From 129c20b1108db8d288b5f48d9c99c091081bc30a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 3 Oct 2023 12:56:10 +0200 Subject: [PATCH] use more aggressive reconnect intervals during rtp session --- .../services/XmppConnectionService.java | 12 +++++++++--- .../siacs/conversations/xmpp/XmppConnection.java | 13 +++++++++---- .../xmpp/jingle/JingleConnectionManager.java | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 72a56fbec..2de831be6 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -504,14 +504,15 @@ public class XmppConnectionService extends Service { } else if (account.getStatus() != Account.State.CONNECTING && account.getStatus() != Account.State.NO_INTERNET) { resetSendingToWaiting(account); if (connection != null && account.getStatus().isAttemptReconnect()) { - final int next = connection.getTimeToNextAttempt(); + final boolean aggressive = hasJingleRtpConnection(account); + final int next = connection.getTimeToNextAttempt(aggressive); final boolean lowPingTimeoutMode = isInLowPingTimeoutMode(account); if (next <= 0) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. reconnecting now. lowPingTimeout=" + lowPingTimeoutMode); reconnectAccount(account, true, false); } else { final int attempt = connection.getAttempt() + 1; - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt + " time. lowPingTimeout=" + lowPingTimeoutMode); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt + " time. lowPingTimeout=" + lowPingTimeoutMode+", aggressive="+aggressive); scheduleWakeUpCall(next, account.getUuid().hashCode()); } } @@ -1106,7 +1107,8 @@ public class XmppConnectionService extends Service { scheduleWakeUpCall((int) Math.min(timeout, discoTimeout), account.getUuid().hashCode()); } } else { - if (account.getXmppConnection().getTimeToNextAttempt() <= 0) { + final boolean aggressive = hasJingleRtpConnection(account); + if (account.getXmppConnection().getTimeToNextAttempt(aggressive) <= 0) { reconnectAccount(account, true, interactive); } } @@ -5058,6 +5060,10 @@ public class XmppConnectionService extends Service { return this.mJingleConnectionManager; } + private boolean hasJingleRtpConnection(final Account account) { + return this.mJingleConnectionManager.hasJingleRtpConnection(account); + } + public MessageArchiveService getMessageArchiveService() { return this.mMessageArchiveService; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 37034fa31..7e1c36675 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -2512,10 +2512,15 @@ public class XmppConnection implements Runnable { return servers.size() > 0 ? servers.get(0) : null; } - public int getTimeToNextAttempt() { - final int additionalTime = - account.getLastErrorStatus() == Account.State.POLICY_VIOLATION ? 3 : 0; - final int interval = Math.min((int) (25 * Math.pow(1.3, (additionalTime + attempt))), 300); + public int getTimeToNextAttempt(final boolean aggressive) { + final int interval; + if (aggressive) { + interval = Math.min((int) (3 * Math.pow(1.3,attempt)), 60); + } else { + final int additionalTime = + account.getLastErrorStatus() == Account.State.POLICY_VIOLATION ? 3 : 0; + interval = Math.min((int) (25 * Math.pow(1.3, (additionalTime + attempt))), 300); + } final int secondsSinceLast = (int) ((SystemClock.elapsedRealtime() - this.lastConnect) / 1000); return interval - secondsSinceLast; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 6145ef659..b795ba567 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -158,6 +158,21 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } + public boolean hasJingleRtpConnection(final Account account) { + for (AbstractJingleConnection connection : this.connections.values()) { + if (connection instanceof JingleRtpConnection) { + final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection; + if (rtpConnection.isTerminated()) { + continue; + } + if (rtpConnection.id.account == account) { + return true; + } + } + } + return false; + } + public void notifyPhoneCallStarted() { for (AbstractJingleConnection connection : connections.values()) { if (connection instanceof JingleRtpConnection) { @@ -170,6 +185,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } + private Optional findMatchingSessionProposal( final Account account, final Jid with, final Set media) { synchronized (this.rtpSessionProposals) { -- 2.45.2