From 8570c9f9126b9807c83c76d8abe8909820b631d1 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 b73aef7cc..5a072e9c6 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -466,14 +466,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()); } } @@ -948,7 +949,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); } } @@ -4590,6 +4592,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 11651397a..93ab1ebf5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -2483,10 +2483,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 9f51bec7e..77737e5ae 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) {