From cbbd178e07d600fda7903ab0dfae61daeade4343 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 13 Jul 2016 00:20:57 +0200 Subject: don't time out disco request but just send bind request --- .../siacs/conversations/xmpp/XmppConnection.java | 49 ++++++---------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 0bf62e342..88765c147 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -118,9 +118,7 @@ public class XmppConnection implements Runnable { private long lastSessionStarted = 0; private long lastDiscoStarted = 0; private AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0); - private AtomicBoolean mIsServiceItemsDiscoveryPending = new AtomicBoolean(true); - private boolean mWaitForDisco = true; - private final ArrayList mPendingServiceDiscoveriesIds = new ArrayList<>(); + private AtomicBoolean mWaitForDisco = new AtomicBoolean(true); private boolean mInteractive = false; private int attempt = 0; private final Hashtable> packetCallbacks = new Hashtable<>(); @@ -990,25 +988,8 @@ public class XmppConnection implements Runnable { } public void sendDiscoTimeout() { - final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.ERROR); //don't use timeout - final ArrayList callbacks = new ArrayList<>(); - synchronized (this.mPendingServiceDiscoveriesIds) { - for(String id : mPendingServiceDiscoveriesIds) { - synchronized (this.packetCallbacks) { - Pair pair = this.packetCallbacks.remove(id); - if (pair != null) { - callbacks.add(pair.second); - } - } - } - this.mPendingServiceDiscoveriesIds.clear(); - } - if (callbacks.size() > 0) { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": sending disco timeout"); - resetStreamId(); //we don't want to live with this for ever - } - for(OnIqPacketReceived callback : callbacks) { - callback.onIqPacketReceived(account,failurePacket); + if (mWaitForDisco.compareAndSet(true, false)) { + finalizeBind(); } } @@ -1050,8 +1031,7 @@ public class XmppConnection implements Runnable { this.disco.clear(); } mPendingServiceDiscoveries.set(0); - mIsServiceItemsDiscoveryPending.set(true); - mWaitForDisco = mServerIdentity != Identity.NIMBUZZ; + mWaitForDisco.set(mServerIdentity != Identity.NIMBUZZ); lastDiscoStarted = SystemClock.elapsedRealtime(); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery"); mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode()); @@ -1070,7 +1050,8 @@ public class XmppConnection implements Runnable { } sendServiceDiscoveryInfo(account.getJid().toBareJid()); sendServiceDiscoveryItems(account.getServer()); - if (!mWaitForDisco) { + + if (!mWaitForDisco.get()) { finalizeBind(); } this.lastSessionStarted = SystemClock.elapsedRealtime(); @@ -1081,7 +1062,7 @@ public class XmppConnection implements Runnable { final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); iq.setTo(jid); iq.query("http://jabber.org/protocol/disco#info"); - String id = this.sendIqPacket(iq, new OnIqPacketReceived() { + this.sendIqPacket(iq, new OnIqPacketReceived() { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { @@ -1122,16 +1103,12 @@ public class XmppConnection implements Runnable { } if (packet.getType() != IqPacket.TYPE.TIMEOUT) { if (mPendingServiceDiscoveries.decrementAndGet() == 0 - && !mIsServiceItemsDiscoveryPending.get() - && mWaitForDisco) { + && mWaitForDisco.compareAndSet(true, false)) { finalizeBind(); } } } }); - synchronized (this.mPendingServiceDiscoveriesIds) { - this.mPendingServiceDiscoveriesIds.add(id); - } } private void finalizeBind() { @@ -1156,10 +1133,11 @@ public class XmppConnection implements Runnable { } private void sendServiceDiscoveryItems(final Jid server) { + mPendingServiceDiscoveries.incrementAndGet(); final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); iq.setTo(server.toDomainJid()); iq.query("http://jabber.org/protocol/disco#items"); - String id = this.sendIqPacket(iq, new OnIqPacketReceived() { + this.sendIqPacket(iq, new OnIqPacketReceived() { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { @@ -1177,16 +1155,13 @@ public class XmppConnection implements Runnable { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco items of " + server); } if (packet.getType() != IqPacket.TYPE.TIMEOUT) { - mIsServiceItemsDiscoveryPending.set(false); - if (mPendingServiceDiscoveries.get() == 0 && mWaitForDisco) { + if (mPendingServiceDiscoveries.decrementAndGet() == 0 + && mWaitForDisco.compareAndSet(true, false)) { finalizeBind(); } } } }); - synchronized (this.mPendingServiceDiscoveriesIds) { - this.mPendingServiceDiscoveriesIds.add(id); - } } private void sendEnableCarbons() { -- cgit v1.2.3