Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Adapt to jicoco changes. #1201

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions jicofo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
<scope>compile</scope>
</dependency>
<!-- org.jitsi -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco-config</artifactId>
Expand Down
60 changes: 39 additions & 21 deletions jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ import org.jitsi.jicofo.metrics.GlobalMetrics
import org.jitsi.jicofo.xmpp.XmppProvider.RoomExistsException
import org.jitsi.jicofo.xmpp.muc.ChatRoom
import org.jitsi.jicofo.xmpp.muc.ChatRoomImpl
import org.jitsi.retry.RetryStrategy
import org.jitsi.retry.SimpleRetryTask
import org.jitsi.utils.logging2.Logger
import org.jitsi.utils.logging2.createChildLogger
import org.jitsi.xmpp.TrustAllHostnameVerifier
import org.jitsi.xmpp.TrustAllX509TrustManager
import org.jivesoftware.smack.AbstractXMPPConnection
import org.jivesoftware.smack.ConnectionConfiguration
import org.jivesoftware.smack.ConnectionListener
Expand All @@ -43,18 +39,24 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager
import org.jxmpp.jid.DomainBareJid
import org.jxmpp.jid.EntityBareJid
import org.jxmpp.jid.EntityFullJid
import java.security.cert.X509Certificate
import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.logging.Level
import javax.net.ssl.X509TrustManager

/** Wraps a Smack [XMPPConnection]. */
class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
private val logger: Logger = createChildLogger(parentLogger).apply {
addContext("xmpp_connection", config.name)
}

/** We need a retry strategy for the first connect attempt. Later those are handled by Smack internally. */
private val connectRetry = RetryStrategy(TaskPools.scheduledPool)
/** A task which will keep trying to connect to the XMPP server at a fixed 1-second delay. Smack's
* ReconnectionManager only kicks in once a connection suceeds. */
private var connectTask: ScheduledFuture<*>? = null
private val connectSyncRoot = Any()

/** A list of all listeners registered with this instance. */
private val listeners = CopyOnWriteArraySet<Listener>()
Expand Down Expand Up @@ -94,17 +96,34 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
if (xmppConnection.isConnected) {
xmppConnection.disconnect()

// If there was an error reconnecting, do not give up, let's retry
// if we retry too quickly and prosody is not fully up ('invalid-namespace' error)
connectRetry.runRetryingTask(
SimpleRetryTask(0, 1000L, true) {
doConnect()
}
)
// In some after cases with Stream Management Smack's ReconnectionManager gives up. Make sure we keep
// trying.
scheduleConnectTask()
}
}
}

/** Start/restart the connect task. */
private fun scheduleConnectTask() = synchronized(connectSyncRoot) {
val delay = 1L
connectTask?.cancel(true)
connectTask = TaskPools.scheduledPool.scheduleAtFixedRate({
try {
if (doConnect()) {
logger.warn("Failed to connect, will re-try after $delay second")
} else {
logger.info("Connected.")
synchronized(connectSyncRoot) {
connectTask?.cancel(false)
connectTask = null
}
}
} catch (e: Exception) {
logger.error("Failed to connect: ${e.message}, will re-try after $delay second", e)
}
}, 0, delay, TimeUnit.SECONDS)
}

private val connectionListener = object : ConnectionListener {
override fun authenticated(connection: XMPPConnection?, resumed: Boolean) {
registered = true
Expand Down Expand Up @@ -145,11 +164,7 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
if (!started.compareAndSet(false, true)) {
logger.info("Already started.")
} else {
connectRetry.runRetryingTask(
SimpleRetryTask(0, 5000L, true) {
this.doConnect()
}
)
scheduleConnectTask()
}
}

Expand All @@ -158,7 +173,6 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
logger.info("Already stopped or not started.")
} else {
synchronized(this) {
connectRetry.cancel()
xmppConnection.disconnect()
logger.info("Disconnected.")
xmppConnection.removeConnectionListener(connectionListener)
Expand Down Expand Up @@ -327,8 +341,12 @@ private fun createXmppConnection(config: XmppConnectionConfig, logger: Logger):
}
if (config.disableCertificateVerification) {
logger.warn("Disabling TLS certificate verification!")
setCustomX509TrustManager(TrustAllX509TrustManager())
setHostnameVerifier(TrustAllHostnameVerifier())
setCustomX509TrustManager(object : X509TrustManager {
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {}
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {}
override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray()
})
setHostnameVerifier { _, _ -> true }
}
}

Expand Down
4 changes: 0 additions & 4 deletions jicofo-selector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<scope>compile</scope>
</dependency>
<!-- org.jitsi -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco-config</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jicofo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<!-- org.jitsi -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco</artifactId>
<artifactId>jicoco-health-checker</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
12 changes: 5 additions & 7 deletions jicofo/src/main/java/org/jitsi/jicofo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import kotlin.jvm.functions.*;
import org.jetbrains.annotations.*;
import org.jitsi.cmd.*;
import org.jitsi.config.*;
import org.jitsi.metaconfig.*;
import org.jitsi.shutdown.*;
import org.jitsi.utils.*;
import org.jitsi.utils.logging2.*;

import java.util.concurrent.*;


/**
* Provides the <tt>main</tt> entry point of Jitsi Meet conference focus.
Expand All @@ -42,7 +42,6 @@ public class Main
* @param args command-line arguments.
*/
public static void main(String[] args)
throws ParseException
{
logger.info("Starting Jicofo.");

Expand All @@ -63,9 +62,8 @@ public static void main(String[] args)
ConfigUtils.PASSWORD_CMD_LINE_ARGS = "user_password";


ShutdownServiceImpl shutdownService = new ShutdownServiceImpl();
// Register shutdown hook to perform cleanup before exit
Runtime.getRuntime().addShutdownHook(new Thread(shutdownService::beginShutdown));
CountDownLatch shutdownLatch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown));

JicofoServices jicofoServices;
try
Expand All @@ -88,7 +86,7 @@ public static void main(String[] args)

try
{
shutdownService.waitForShutdown();
shutdownLatch.await();
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.jitsi.xmpp.extensions.colibri2.Sources
import org.jitsi.xmpp.extensions.colibri2.Transport
import org.jitsi.xmpp.extensions.jingle.DtlsFingerprintPacketExtension
import org.jitsi.xmpp.extensions.jingle.IceUdpTransportPacketExtension
import org.jitsi.xmpp.util.createError
import org.jivesoftware.smack.packet.ExtensionElement
import org.jivesoftware.smack.packet.IQ
import org.jivesoftware.smack.packet.StanzaError
import org.jivesoftware.smack.packet.StanzaError.Condition.bad_request
Expand Down Expand Up @@ -211,3 +211,18 @@ private fun buildFeedbackSources(localAudioSsrc: Long, localVideoSsrc: Long): So
.build()
)
}.build()

fun createError(
request: IQ,
errorCondition: StanzaError.Condition,
errorMessage: String? = null,
extension: ExtensionElement? = null
): IQ {
val error = StanzaError.getBuilder(errorCondition)
errorMessage?.let { error.setDescriptiveEnText(it) }
extension?.let {
error.setExtensions(listOf(it))
}

return IQ.createErrorResponse(request, error.build())
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<kotest.version>5.7.2</kotest.version>
<slf4j.version>1.7.32</slf4j.version>
<jitsi.utils.version>1.0-127-g6c65524</jitsi.utils.version>
<jicoco.version>1.1-143-g175c44b</jicoco.version>
<jicoco.version>1.1-SNAPSHOT</jicoco.version>
<ktlint-maven-plugin.version>3.0.0</ktlint-maven-plugin.version>
<spotbugs.version>4.8.6</spotbugs.version>
<spotbugs-maven-plugin.version>4.8.6.6</spotbugs-maven-plugin.version>
Expand Down Expand Up @@ -144,12 +144,12 @@
<!-- org.jitsi -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco</artifactId>
<artifactId>jicoco-config</artifactId>
<version>${jicoco.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jicoco-config</artifactId>
<artifactId>jicoco-health-checker</artifactId>
<version>${jicoco.version}</version>
</dependency>
<dependency>
Expand Down
Loading