use more aggressive reconnect intervals during rtp session

This commit is contained in:
Daniel Gultsch 2023-10-03 12:56:10 +02:00
parent fd4b8ba188
commit 8570c9f912
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 34 additions and 7 deletions

View file

@ -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;
}

View file

@ -2483,10 +2483,15 @@ public class XmppConnection implements Runnable {
return servers.size() > 0 ? servers.get(0) : null;
}
public int getTimeToNextAttempt() {
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;
final int interval = Math.min((int) (25 * Math.pow(1.3, (additionalTime + attempt))), 300);
interval = Math.min((int) (25 * Math.pow(1.3, (additionalTime + attempt))), 300);
}
final int secondsSinceLast =
(int) ((SystemClock.elapsedRealtime() - this.lastConnect) / 1000);
return interval - secondsSinceLast;

View file

@ -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<RtpSessionProposal> findMatchingSessionProposal(
final Account account, final Jid with, final Set<Media> media) {
synchronized (this.rtpSessionProposals) {