reset stanza count when enabling SM via SASL inline

This commit is contained in:
Daniel Gultsch 2022-12-30 12:09:16 +01:00
parent 01fba162f0
commit a7fe3e8372
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -163,6 +163,7 @@ public class XmppConnection implements Runnable {
private String streamId = null; private String streamId = null;
private int stanzasReceived = 0; private int stanzasReceived = 0;
private int stanzasSent = 0; private int stanzasSent = 0;
private int stanzasSentBeforeAuthentication;
private long lastPacketReceived = 0; private long lastPacketReceived = 0;
private long lastPingSent = 0; private long lastPingSent = 0;
private long lastConnect = 0; private long lastConnect = 0;
@ -786,6 +787,7 @@ public class XmppConnection implements Runnable {
final Element carbonsEnabled = bound.findChild("enabled", Namespace.CARBONS); final Element carbonsEnabled = bound.findChild("enabled", Namespace.CARBONS);
final boolean waitForDisco; final boolean waitForDisco;
if (streamManagementEnabled != null) { if (streamManagementEnabled != null) {
resetOutboundStanzaQueue();
processEnabled(streamManagementEnabled); processEnabled(streamManagementEnabled);
waitForDisco = true; waitForDisco = true;
} else { } else {
@ -845,6 +847,37 @@ public class XmppConnection implements Runnable {
} }
} }
private void resetOutboundStanzaQueue() {
synchronized (this.mStanzaQueue) {
final List<AbstractAcknowledgeableStanza> intermediateStanzas = new ArrayList<>();
if (Config.EXTENDED_SM_LOGGING) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": stanzas sent before auth: "
+ this.stanzasSentBeforeAuthentication);
}
for (int i = this.stanzasSentBeforeAuthentication + 1; i <= this.stanzasSent; ++i) {
final AbstractAcknowledgeableStanza stanza = this.mStanzaQueue.get(i);
if (stanza != null) {
intermediateStanzas.add(stanza);
}
}
this.mStanzaQueue.clear();
for (int i = 0; i < intermediateStanzas.size(); ++i) {
this.mStanzaQueue.put(i, intermediateStanzas.get(i));
}
this.stanzasSent = intermediateStanzas.size();
if (Config.EXTENDED_SM_LOGGING) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": resetting outbound stanza queue to "
+ this.stanzasSent);
}
}
}
private void processNopStreamFeatures() throws IOException { private void processNopStreamFeatures() throws IOException {
final Tag tag = tagReader.readTag(); final Tag tag = tagReader.readTag();
if (tag != null && tag.isStart("features", Namespace.STREAMS)) { if (tag != null && tag.isStart("features", Namespace.STREAMS)) {
@ -1446,8 +1479,11 @@ public class XmppConnection implements Runnable {
+ "/" + "/"
+ this.saslMechanism.getMechanism()); + this.saslMechanism.getMechanism());
authenticate.setAttribute("mechanism", this.saslMechanism.getMechanism()); authenticate.setAttribute("mechanism", this.saslMechanism.getMechanism());
synchronized (this.mStanzaQueue) {
this.stanzasSentBeforeAuthentication = this.stanzasSent;
tagWriter.writeElement(authenticate); tagWriter.writeElement(authenticate);
} }
}
private static boolean isFastTokenAvailable(final Element authentication) { private static boolean isFastTokenAvailable(final Element authentication) {
final Element inline = authentication == null ? null : authentication.findChild("inline"); final Element inline = authentication == null ? null : authentication.findChild("inline");
@ -2173,7 +2209,10 @@ public class XmppConnection implements Runnable {
generateAuthenticationRequest(quickStartMechanism.getClientFirstMessage(sslSocketOrNull(this.socket)), usingFast); generateAuthenticationRequest(quickStartMechanism.getClientFirstMessage(sslSocketOrNull(this.socket)), usingFast);
authenticate.setAttribute("mechanism", quickStartMechanism.getMechanism()); authenticate.setAttribute("mechanism", quickStartMechanism.getMechanism());
sendStartStream(true, false); sendStartStream(true, false);
synchronized (this.mStanzaQueue) {
this.stanzasSentBeforeAuthentication = this.stanzasSent;
tagWriter.writeElement(authenticate); tagWriter.writeElement(authenticate);
}
Log.d( Log.d(
Config.LOGTAG, Config.LOGTAG,
account.getJid().toString() account.getJid().toString()