Skip to content

Commit

Permalink
* feat(connection): Enables stream management for xmpp connections.
Browse files Browse the repository at this point in the history
* feat(connection): Enables stream management for xmpp connections.

* squash: Enable quicker reconnect.

* squash: Uses the reply timeout for reconnect timeout.

This is the maximum time we will wait for stanzas to be sent, beyond that we can consider disconnected and let it connect again.

* squash: Remove duplicate log.

* squash: Handle when reconnected without resuming.
  • Loading branch information
damencho authored Dec 2, 2024
1 parent 6111ddd commit 9119130
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.jitsi.jicofo.xmpp;

import org.jetbrains.annotations.*;
import org.jitsi.jicofo.*;
import org.jitsi.jicofo.xmpp.muc.*;
import org.jitsi.utils.logging2.*;
import org.jitsi.xmpp.util.*;
Expand Down Expand Up @@ -76,6 +77,11 @@ public abstract class BaseBrewery<T extends ExtensionElement>
*/
private final String extensionNamespace;

/**
* Reconnect timer. Used to stop the conference if XMPP connection is not restored in a given time.
*/
private Future<?> reconnectTimeout;

/**
* Creates new instance of <tt>BaseBrewery</tt>
* @param breweryJid the MUC JID of the room which this detector will join,
Expand Down Expand Up @@ -150,11 +156,20 @@ synchronized public void registrationChanged(boolean registered)
{
if (registered)
{
if (this.reconnectTimeout != null)
{
this.reconnectTimeout.cancel(true);
this.reconnectTimeout = null;
}

maybeStart();
}
else
{
stop();
reconnectTimeout = TaskPools.getScheduledPool().schedule(
this::stop,
XmppConfig.service.getReplyTimeout().toMillis(),
TimeUnit.MILLISECONDS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
private val connectionListener = object : ConnectionListener {
override fun authenticated(connection: XMPPConnection?, resumed: Boolean) {
registered = true
logger.info("Registered.")
logger.info(
"Registered." + if (connection is XMPPTCPConnection) {
" isSmEnabled:" + connection.isSmEnabled +
" isSmAvailable:" + connection.isSmAvailable +
" isSmResumptionPossible:" + connection.isSmResumptionPossible
} else {
""
}
)

config.xmppDomain?.let {
logger.info("Will discover components for $it")
TaskPools.ioPool.submit { discoverComponents(it) }
Expand Down Expand Up @@ -279,11 +288,14 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
init {
EntityCapsManager.setDefaultEntityNode("http://jitsi.org/jicofo")
ReconnectionManager.setEnabledPerDefault(true)
// Jicofo handles at most two connections and most of the time that is localhost and the number
// of jicofo instances is small so we can afford to retry quickly.
ReconnectionManager.setDefaultFixedDelay(2)
// Smack uses SASL Mechanisms ANONYMOUS and PLAIN, but tries to authenticate with GSSAPI when it's offered
// by the server. Disable GSSAPI.
SASLAuthentication.unregisterSASLMechanism("org.jivesoftware.smack.sasl.javax.SASLGSSAPIMechanism")
XMPPTCPConnection.setUseStreamManagementResumptionDefault(false)
XMPPTCPConnection.setUseStreamManagementDefault(false)
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true)
XMPPTCPConnection.setUseStreamManagementDefault(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import org.jitsi.jicofo.jibri.*;

import org.jitsi.xmpp.extensions.visitors.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.tcp.*;
import org.jivesoftware.smackx.caps.*;
import org.jivesoftware.smackx.caps.packet.*;
import org.jxmpp.jid.*;
Expand Down Expand Up @@ -175,6 +177,11 @@ public class JitsiMeetConferenceImpl
*/
private Future<?> conferenceStartTimeout;

/**
* Reconnect timer. Used to stop the conference if XMPP connection is not restored in a given time.
*/
private Future<?> reconnectTimeout;

/**
* Whether participants being invited to the conference as a result of joining (as opposed to having already
* joined) should be invited with the "start audio muted" option.
Expand Down Expand Up @@ -1076,24 +1083,45 @@ public void registrationChanged(boolean registered)
if (registered)
{
logger.info("XMPP reconnected");
if (chatRoom == null)

if (this.reconnectTimeout != null)
{
try
{
joinTheRoom();
}
catch (Exception e)
{
logger.error("Failed to join the room: " + roomName, e);
this.reconnectTimeout.cancel(true);
this.reconnectTimeout = null;
}
else
{
logger.error("Reconnected but not supposed to be here:" + roomName);
}

stop();
}
XMPPConnection connection = chatRoom.getXmppProvider().getXmppConnection();
if (connection instanceof XMPPTCPConnection && !((XMPPTCPConnection) connection).streamWasResumed())
{
logger.error("Reconnected without resuming, give up and stop.");

// This is a connect without resumption, so make sure we fix the state, by stopping
// all clients will reload the state will be fine when they invite us again.
stop();
}
}
else
{
logger.info("XMPP disconnected.");
stop();
XMPPConnection connection = chatRoom.getXmppProvider().getXmppConnection();

if (connection instanceof XMPPTCPConnection
&& ((XMPPTCPConnection) connection).isSmEnabled())
{
logger.info("XMPP will wait for a reconnect.");
reconnectTimeout = TaskPools.getScheduledPool().schedule(
this::stop,
XmppConfig.client.getReplyTimeout().toMillis(),
TimeUnit.MILLISECONDS);
}
else
{
stop();
}
}
}

Expand Down

0 comments on commit 9119130

Please sign in to comment.