From 686c4da2b0952973c736073826a580c276b10f87 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Mon, 1 Jul 2019 08:46:00 +0200 Subject: rate limit muc pings / joins. never run two pings at same time --- .../messenger/services/XmppConnectionService.java | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/main/java/de/pixart/messenger/services') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index ff96f255d..b75dd0225 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -326,6 +326,12 @@ public class XmppConnectionService extends Service { } account.getRoster().clearPresences(); + synchronized (account.inProgressConferenceJoins) { + account.inProgressConferenceJoins.clear(); + } + synchronized (account.inProgressConferencePings) { + account.inProgressConferencePings.clear(); + } mJingleConnectionManager.cancelInTransmission(); mQuickConversationsService.considerSyncBackground(false); fetchRosterFromServer(account); @@ -2738,21 +2744,37 @@ public class XmppConnectionService extends Service { } public void mucSelfPingAndRejoin(final Conversation conversation) { + final Account account = conversation.getAccount(); + synchronized (account.inProgressConferenceJoins) { + if (account.inProgressConferenceJoins.contains(conversation)) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": canceling muc self ping because join is already under way"); + return; + } + } + synchronized (account.inProgressConferencePings) { + if (!account.inProgressConferencePings.add(conversation)) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": canceling muc self ping because ping is already under way"); + return; + } + } final Jid self = conversation.getMucOptions().getSelf().getFullJid(); final IqPacket ping = new IqPacket(IqPacket.TYPE.GET); ping.setTo(self); ping.addChild("ping", Namespace.PING); - sendIqPacket(conversation.getAccount(), ping, (account, response) -> { + sendIqPacket(conversation.getAccount(), ping, (a, response) -> { if (response.getType() == IqPacket.TYPE.ERROR) { Element error = response.findChild("error"); if (error == null || error.hasChild("service-unavailable") || error.hasChild("feature-not-implemented") || error.hasChild("item-not-found")) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ping to " + self + " came back as ignorable error"); + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": ping to " + self + " came back as ignorable error"); } else { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ping to " + self + " failed. attempting rejoin"); + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": ping to " + self + " failed. attempting rejoin"); joinMuc(conversation); } } else if (response.getType() == IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ping to " + self + " came back fine"); + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": ping to " + self + " came back fine"); + } + synchronized (account.inProgressConferencePings) { + account.inProgressConferencePings.remove(conversation); } }); } -- cgit v1.2.3