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 843079aea..75573acb4 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -2,7 +2,6 @@ package eu.siacs.conversations.xmpp.jingle; import android.util.Base64; import android.util.Log; -import android.util.Pair; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -74,6 +73,7 @@ public class JingleConnection implements Transferable { private String contentName; private String contentCreator; + private Transport initialTransport; private int mProgress = 0; @@ -167,6 +167,18 @@ public class JingleConnection implements Transferable { return this.mFileOutputStream; } + private OnTransportConnected onIbbTransportConnected = new OnTransportConnected() { + @Override + public void failed() { + Log.d(Config.LOGTAG, "ibb open failed"); + } + + @Override + public void established() { + JingleConnection.this.transport.send(file, onFileTransmissionStatusChanged); + } + }; + private OnProxyActivated onProxyActivated = new OnProxyActivated() { @Override @@ -368,9 +380,27 @@ public class JingleConnection implements Transferable { this.sessionId = packet.getSessionId(); Content content = packet.getJingleContent(); this.contentCreator = content.getAttribute("creator"); + this.initialTransport = content.hasSocks5Transport() ? Transport.SOCKS : Transport.IBB; this.contentName = content.getAttribute("name"); this.transportId = content.getTransportId(); - this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren())); + if (this.initialTransport == Transport.SOCKS) { + this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren())); + } else if (this.initialTransport == Transport.IBB) { + final String receivedBlockSize = content.ibbTransport().getAttribute("block-size"); + if (receivedBlockSize != null) { + try { + this.ibbBlockSize = Math.min(Integer.parseInt(receivedBlockSize), this.ibbBlockSize); + } catch (NumberFormatException e) { + this.sendCancel(); + this.fail(); + return; + } + } else { + this.sendCancel(); + this.fail(); + return; + } + } this.ftVersion = content.getVersion(); if (ftVersion == null) { this.sendCancel(); @@ -532,6 +562,14 @@ public class JingleConnection implements Transferable { mJingleStatus = JINGLE_STATUS_ACCEPTED; this.mStatus = Transferable.STATUS_DOWNLOADING; this.mJingleConnectionManager.updateConversationUi(true); + if (initialTransport == Transport.SOCKS) { + sendAcceptSocks(); + } else { + sendAcceptIbb(); + } + } + + private void sendAcceptSocks() { this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() { @Override public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) { @@ -576,6 +614,17 @@ public class JingleConnection implements Transferable { }); } + private void sendAcceptIbb() { + this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); + final JinglePacket packet = bootstrapPacket("session-accept"); + final Content content = new Content(contentCreator,contentName); + content.setFileOffer(fileOffer, ftVersion); + content.setTransportId(transportId); + content.ibbTransport().setAttribute("block-size",this.ibbBlockSize); + packet.setContent(content); + this.sendJinglePacket(packet); + } + private JinglePacket bootstrapPacket(String action) { JinglePacket packet = new JinglePacket(); packet.setAction(action); @@ -785,17 +834,6 @@ public class JingleConnection implements Transferable { this.sendJinglePacket(packet); } - OnTransportConnected onIbbTransportConnected = new OnTransportConnected() { - @Override - public void failed() { - Log.d(Config.LOGTAG, "ibb open failed"); - } - - @Override - public void established() { - JingleConnection.this.transport.send(file, onFileTransmissionStatusChanged); - } - }; private boolean receiveFallbackToIbb(JinglePacket packet) { Log.d(Config.LOGTAG, "receiving fallack to ibb"); @@ -811,8 +849,9 @@ public class JingleConnection implements Transferable { this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); JinglePacket answer = bootstrapPacket("transport-accept"); - Content content = new Content("initiator", "a-file-offer"); - content.setTransportId(this.transportId); + + final Content content = new Content(contentCreator,contentName); + content.setFileOffer(fileOffer, ftVersion); content.ibbTransport().setAttribute("block-size",this.ibbBlockSize); answer.setContent(content); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/Transport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/Transport.java new file mode 100644 index 000000000..4d0fb4b65 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/Transport.java @@ -0,0 +1,5 @@ +package eu.siacs.conversations.xmpp.jingle; + +public enum Transport { + SOCKS, IBB +}