From 6afa5653cb7936f5d5021b64fae80aa0b4952132 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 18 Aug 2017 14:33:56 +0200 Subject: [PATCH] fixed jingle state machine being thrown off by iq-result coming after session-accept fixes #2587 --- .../xmpp/jingle/JingleConnection.java | 25 ++++++++++--------- .../xmpp/jingle/stanzas/Content.java | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 9a90dcc79..73638ffbe 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -45,6 +45,7 @@ public class JingleConnection implements Transferable { private JingleConnectionManager mJingleConnectionManager; private XmppConnectionService mXmppConnectionService; + private static final int JINGLE_STATUS_OFFERED = -1; protected static final int JINGLE_STATUS_INITIATED = 0; protected static final int JINGLE_STATUS_ACCEPTED = 1; protected static final int JINGLE_STATUS_FINISHED = 4; @@ -55,7 +56,7 @@ public class JingleConnection implements Transferable { private int ibbBlockSize = 8192; - private int mJingleStatus = -1; + private int mJingleStatus = JINGLE_STATUS_OFFERED; private int mStatus = Transferable.STATUS_UNKNOWN; private Message message; private String sessionId; @@ -516,8 +517,12 @@ public class JingleConnection implements Transferable { public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { Log.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer"); - mJingleStatus = JINGLE_STATUS_INITIATED; - mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); + if (mJingleStatus == JINGLE_STATUS_OFFERED) { + mJingleStatus = JINGLE_STATUS_INITIATED; + mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); + } else { + Log.d(Config.LOGTAG,"received ack for offer when status was "+mJingleStatus); + } } else { fail(IqParser.extractErrorMessage(packet)); } @@ -645,8 +650,7 @@ public class JingleConnection implements Transferable { } else if (content.socks5transport().hasChild("candidate-error")) { Log.d(Config.LOGTAG, "received candidate error"); this.receivedCandidate = true; - if ((mJingleStatus == JINGLE_STATUS_ACCEPTED) - && (this.sentCandidate)) { + if (mJingleStatus == JINGLE_STATUS_ACCEPTED && this.sentCandidate) { this.connect(); } return true; @@ -662,12 +666,10 @@ public class JingleConnection implements Transferable { } candidate.flagAsUsedByCounterpart(); this.receivedCandidate = true; - if ((mJingleStatus == JINGLE_STATUS_ACCEPTED) - && (this.sentCandidate)) { + if (mJingleStatus == JINGLE_STATUS_ACCEPTED && this.sentCandidate) { this.connect(); } else { - Log.d(Config.LOGTAG, - "ignoring because file is already in transmission or we haven't sent our candidate yet"); + Log.d(Config.LOGTAG, "ignoring because file is already in transmission or we haven't sent our candidate yet status="+mJingleStatus+" sentCandidate="+Boolean.toString(sentCandidate)); } return true; } else { @@ -1007,8 +1009,7 @@ public class JingleConnection implements Transferable { JinglePacket packet = bootstrapPacket("transport-info"); Content content = new Content(this.contentCreator, this.contentName); content.setTransportId(this.transportId); - content.socks5transport().addChild("candidate-used") - .setAttribute("cid", cid); + content.socks5transport().addChild("candidate-used").setAttribute("cid", cid); packet.setContent(content); this.sentCandidate = true; if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) { @@ -1024,7 +1025,7 @@ public class JingleConnection implements Transferable { content.socks5transport().addChild("candidate-error"); packet.setContent(content); this.sentCandidate = true; - if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) { + if (receivedCandidate && mJingleStatus == JINGLE_STATUS_ACCEPTED) { connect(); } this.sendJinglePacket(packet); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java index 12ea69991..1b01cf0b3 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java @@ -30,6 +30,7 @@ public class Content extends Element { public Content(String creator, String name) { super("content"); this.setAttribute("creator", creator); + this.setAttribute("senders", creator); this.setAttribute("name", name); }