XmppConnection: do not count stanzas before smacks session has started

This commit is contained in:
Daniel Gultsch 2017-10-27 11:35:55 +02:00
parent dc5d504edd
commit 6f802b88d2
1 changed files with 9 additions and 1 deletions

View File

@ -108,6 +108,7 @@ public class XmppConnection implements Runnable {
private final Features features = new Features(this); private final Features features = new Features(this);
private boolean needsBinding = true; private boolean needsBinding = true;
private boolean shouldAuthenticate = true; private boolean shouldAuthenticate = true;
private boolean inSmacksSession = false;
private Element streamFeatures; private Element streamFeatures;
private final HashMap<Jid, ServiceDiscoveryResult> disco = new HashMap<>(); private final HashMap<Jid, ServiceDiscoveryResult> disco = new HashMap<>();
@ -271,6 +272,7 @@ public class XmppConnection implements Runnable {
} }
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting"); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting");
features.encryptionEnabled = false; features.encryptionEnabled = false;
inSmacksSession = false;
this.attempt++; this.attempt++;
this.verifiedHostname = null; //will be set if user entered hostname is being used or hostname was verified with dnssec this.verifiedHostname = null; //will be set if user entered hostname is being used or hostname was verified with dnssec
try { try {
@ -578,9 +580,11 @@ public class XmppConnection implements Runnable {
+ ": stream management(" + smVersion + ") enabled"); + ": stream management(" + smVersion + ") enabled");
} }
this.stanzasReceived = 0; this.stanzasReceived = 0;
this.inSmacksSession = true;
final RequestPacket r = new RequestPacket(smVersion); final RequestPacket r = new RequestPacket(smVersion);
tagWriter.writeStanzaAsync(r); tagWriter.writeStanzaAsync(r);
} else if (nextTag.isStart("resumed")) { } else if (nextTag.isStart("resumed")) {
this.inSmacksSession = true;
this.tagWriter.writeStanzaAsync(new RequestPacket(smVersion)); this.tagWriter.writeStanzaAsync(new RequestPacket(smVersion));
lastPacketReceived = SystemClock.elapsedRealtime(); lastPacketReceived = SystemClock.elapsedRealtime();
final Element resumed = tagReader.readElement(nextTag); final Element resumed = tagReader.readElement(nextTag);
@ -733,7 +737,11 @@ public class XmppConnection implements Runnable {
resetStreamId(); resetStreamId();
throw new IOException("time to restart the session. cant handle >2 billion pcks"); throw new IOException("time to restart the session. cant handle >2 billion pcks");
} }
if (inSmacksSession) {
++stanzasReceived; ++stanzasReceived;
} else if (features.sm()) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": not counting stanza("+element.getClass().getSimpleName()+"). Not in smacks session.");
}
lastPacketReceived = SystemClock.elapsedRealtime(); lastPacketReceived = SystemClock.elapsedRealtime();
if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) { if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) {
Log.d(Config.LOGTAG, "[background stanza] " + element); Log.d(Config.LOGTAG, "[background stanza] " + element);