fixed jingle state machine being thrown off by iq-result coming after session-accept

fixes #2587
This commit is contained in:
Daniel Gultsch 2017-08-18 14:33:56 +02:00
parent 1383d3d2e4
commit 6afa5653cb
2 changed files with 14 additions and 12 deletions

View File

@ -45,6 +45,7 @@ public class JingleConnection implements Transferable {
private JingleConnectionManager mJingleConnectionManager; private JingleConnectionManager mJingleConnectionManager;
private XmppConnectionService mXmppConnectionService; 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_INITIATED = 0;
protected static final int JINGLE_STATUS_ACCEPTED = 1; protected static final int JINGLE_STATUS_ACCEPTED = 1;
protected static final int JINGLE_STATUS_FINISHED = 4; protected static final int JINGLE_STATUS_FINISHED = 4;
@ -55,7 +56,7 @@ public class JingleConnection implements Transferable {
private int ibbBlockSize = 8192; private int ibbBlockSize = 8192;
private int mJingleStatus = -1; private int mJingleStatus = JINGLE_STATUS_OFFERED;
private int mStatus = Transferable.STATUS_UNKNOWN; private int mStatus = Transferable.STATUS_UNKNOWN;
private Message message; private Message message;
private String sessionId; private String sessionId;
@ -516,8 +517,12 @@ public class JingleConnection implements Transferable {
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) { if (packet.getType() == IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer"); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer");
if (mJingleStatus == JINGLE_STATUS_OFFERED) {
mJingleStatus = JINGLE_STATUS_INITIATED; mJingleStatus = JINGLE_STATUS_INITIATED;
mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
} else {
Log.d(Config.LOGTAG,"received ack for offer when status was "+mJingleStatus);
}
} else { } else {
fail(IqParser.extractErrorMessage(packet)); fail(IqParser.extractErrorMessage(packet));
} }
@ -645,8 +650,7 @@ public class JingleConnection implements Transferable {
} else if (content.socks5transport().hasChild("candidate-error")) { } else if (content.socks5transport().hasChild("candidate-error")) {
Log.d(Config.LOGTAG, "received candidate error"); Log.d(Config.LOGTAG, "received candidate error");
this.receivedCandidate = true; this.receivedCandidate = true;
if ((mJingleStatus == JINGLE_STATUS_ACCEPTED) if (mJingleStatus == JINGLE_STATUS_ACCEPTED && this.sentCandidate) {
&& (this.sentCandidate)) {
this.connect(); this.connect();
} }
return true; return true;
@ -662,12 +666,10 @@ public class JingleConnection implements Transferable {
} }
candidate.flagAsUsedByCounterpart(); candidate.flagAsUsedByCounterpart();
this.receivedCandidate = true; this.receivedCandidate = true;
if ((mJingleStatus == JINGLE_STATUS_ACCEPTED) if (mJingleStatus == JINGLE_STATUS_ACCEPTED && this.sentCandidate) {
&& (this.sentCandidate)) {
this.connect(); this.connect();
} else { } else {
Log.d(Config.LOGTAG, 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));
"ignoring because file is already in transmission or we haven't sent our candidate yet");
} }
return true; return true;
} else { } else {
@ -1007,8 +1009,7 @@ public class JingleConnection implements Transferable {
JinglePacket packet = bootstrapPacket("transport-info"); JinglePacket packet = bootstrapPacket("transport-info");
Content content = new Content(this.contentCreator, this.contentName); Content content = new Content(this.contentCreator, this.contentName);
content.setTransportId(this.transportId); content.setTransportId(this.transportId);
content.socks5transport().addChild("candidate-used") content.socks5transport().addChild("candidate-used").setAttribute("cid", cid);
.setAttribute("cid", cid);
packet.setContent(content); packet.setContent(content);
this.sentCandidate = true; this.sentCandidate = true;
if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) { if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
@ -1024,7 +1025,7 @@ public class JingleConnection implements Transferable {
content.socks5transport().addChild("candidate-error"); content.socks5transport().addChild("candidate-error");
packet.setContent(content); packet.setContent(content);
this.sentCandidate = true; this.sentCandidate = true;
if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) { if (receivedCandidate && mJingleStatus == JINGLE_STATUS_ACCEPTED) {
connect(); connect();
} }
this.sendJinglePacket(packet); this.sendJinglePacket(packet);

View File

@ -30,6 +30,7 @@ public class Content extends Element {
public Content(String creator, String name) { public Content(String creator, String name) {
super("content"); super("content");
this.setAttribute("creator", creator); this.setAttribute("creator", creator);
this.setAttribute("senders", creator);
this.setAttribute("name", name); this.setAttribute("name", name);
} }