diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-07-13 00:20:57 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-07-13 18:38:08 +0200 |
commit | cbbd178e07d600fda7903ab0dfae61daeade4343 (patch) | |
tree | 13b60853f3a69a8a806b0f0b083b8912f458b8b2 /src/main/java/eu/siacs | |
parent | 4250355cebd93fc17663d5e591148bc3a48851b2 (diff) |
don't time out disco request but just send bind request
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 49 |
1 files 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<String> mPendingServiceDiscoveriesIds = new ArrayList<>(); + private AtomicBoolean mWaitForDisco = new AtomicBoolean(true); private boolean mInteractive = false; private int attempt = 0; private final Hashtable<String, Pair<IqPacket, OnIqPacketReceived>> 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<OnIqPacketReceived> callbacks = new ArrayList<>(); - synchronized (this.mPendingServiceDiscoveriesIds) { - for(String id : mPendingServiceDiscoveriesIds) { - synchronized (this.packetCallbacks) { - Pair<IqPacket, OnIqPacketReceived> 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() { |