diff options
Diffstat (limited to 'src')
5 files changed, 65 insertions, 22 deletions
diff --git a/src/com/isode/stroke/filetransfer/DummyFileTransferTransporterFactory.java b/src/com/isode/stroke/filetransfer/DummyFileTransferTransporterFactory.java index 10b630d..1904944 100644 --- a/src/com/isode/stroke/filetransfer/DummyFileTransferTransporterFactory.java +++ b/src/com/isode/stroke/filetransfer/DummyFileTransferTransporterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -51,13 +51,14 @@ class DummyFileTransferTransporter extends FileTransferTransporter { TimerFactory timer, CryptoProvider cryptoProvider, IQRouter iqRouter, - final FileTransferOptions option) { + final FileTransferOptions ftOptions) { initiator_ = initiator; responder_ = responder; role_ = role; s5bRegistry_ = s5bRegistry; crypto_ = cryptoProvider; iqRouter_ = iqRouter; + ftOptions_ = new FileTransferOptions(ftOptions); } public void initialize() { @@ -66,6 +67,12 @@ class DummyFileTransferTransporter extends FileTransferTransporter { public void startGeneratingLocalCandidates() { Vector<JingleS5BTransportPayload.Candidate> candidates = new Vector<JingleS5BTransportPayload.Candidate>(); + if (ftOptions_.isDirectAllowed()) { + JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate(); + candidate.cid = "123"; + candidate.priority = 1235; + candidates.add(candidate); + } onLocalCandidatesGenerated.emit(s5bSessionID_, candidates, getSOCKS5DstAddr()); } @@ -147,6 +154,7 @@ class DummyFileTransferTransporter extends FileTransferTransporter { private CryptoProvider crypto_; private String s5bSessionID_; private IQRouter iqRouter_; + private final FileTransferOptions ftOptions_; }; public class DummyFileTransferTransporterFactory implements FileTransferTransporterFactory { diff --git a/src/com/isode/stroke/filetransfer/IncomingFileTransferManager.java b/src/com/isode/stroke/filetransfer/IncomingFileTransferManager.java index 7166d67..06ed3ab 100644 --- a/src/com/isode/stroke/filetransfer/IncomingFileTransferManager.java +++ b/src/com/isode/stroke/filetransfer/IncomingFileTransferManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -15,6 +15,7 @@ import com.isode.stroke.signals.Signal1; import com.isode.stroke.jingle.IncomingJingleSessionHandler; import com.isode.stroke.jingle.JingleSessionManager; import com.isode.stroke.jingle.JingleSession; +import com.isode.stroke.elements.JingleIBBTransportPayload; import com.isode.stroke.elements.JinglePayload; import com.isode.stroke.elements.JingleContentPayload; import com.isode.stroke.elements.JingleFileTransferDescription; @@ -24,6 +25,7 @@ import com.isode.stroke.network.TimerFactory; import com.isode.stroke.crypto.CryptoProvider; import com.isode.stroke.queries.IQRouter; import com.isode.stroke.jid.JID; + import java.util.logging.Logger; import java.util.Vector; @@ -55,7 +57,8 @@ public class IncomingFileTransferManager implements IncomingJingleSessionHandler final JID recipient) { if (Jingle.getContentWithDescription(contents, new JingleFileTransferDescription()) != null) { JingleContentPayload content = Jingle.getContentWithDescription(contents, new JingleFileTransferDescription()); - if (content.getTransport(new JingleS5BTransportPayload()) != null) { + if ( (content.getTransport(new JingleS5BTransportPayload()) != null) + || (content.getTransport(new JingleIBBTransportPayload()) != null) ) { JingleFileTransferDescription description = content.getDescription(new JingleFileTransferDescription()); if (description != null) { IncomingJingleFileTransfer transfer = new IncomingJingleFileTransfer( diff --git a/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java index 1c67014..f6aa01f 100644 --- a/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java +++ b/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java @@ -171,16 +171,16 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In } }); - if (initialContent.getTransport(new JingleS5BTransportPayload()) != null) { - JingleS5BTransportPayload s5bTransport = initialContent.getTransport(new JingleS5BTransportPayload()); + JingleS5BTransportPayload s5bTransport = initialContent.getTransport(new JingleS5BTransportPayload()); + JingleIBBTransportPayload ibbTransport = initialContent.getTransport(new JingleIBBTransportPayload()); + if (s5bTransport != null) { logger_.fine("Got S5B transport as initial payload.\n"); setTransporter(transporterFactory.createResponderTransporter(getInitiator(), getResponder(), s5bTransport.getSessionID(), options)); transporter.addRemoteCandidates(s5bTransport.getCandidates(), s5bTransport.getDstAddr()); setInternalState(State.GeneratingInitialLocalCandidates); transporter.startGeneratingLocalCandidates(); } - else if(initialContent.getTransport(new JingleIBBTransportPayload()) != null) { - JingleIBBTransportPayload ibbTransport = initialContent.getTransport(new JingleIBBTransportPayload()); + else if(ibbTransport != null && options.isInBandAllowed()) { logger_.fine("Got IBB transport as initial payload.\n"); setTransporter(transporterFactory.createResponderTransporter(getInitiator(), getResponder(), ibbTransport.getSessionID(), options)); @@ -189,8 +189,9 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In session.sendAccept(getContentID(), initialContent.getDescriptions().get(0), ibbTransport); } else { - // Can't happen, because the transfer would have been rejected automatically - assert(false); + // This might happen on incoming transfer which only list transport methods we are not allowed to use due to file-transfer options. + session.sendTerminate(JinglePayload.Reason.Type.UnsupportedTransports); + setFinishedState(FileTransfer.State.Type.Failed, new FileTransferError(FileTransferError.Type.PeerError)); } } diff --git a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java index aa38022..e2117b6 100644 --- a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java +++ b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java @@ -179,10 +179,19 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou logger_.warning("Incorrect state\n"); return; } - - setTransporter(transporterFactory.createInitiatorTransporter(getInitiator(), getResponder(), options)); - setInternalState(State.GeneratingInitialLocalCandidates); - transporter.startGeneratingLocalCandidates(); + + if (!options.isInBandAllowed() && !options.isDirectAllowed() + && !options.isAssistedAllowed() && !options.isProxiedAllowed()) { + // Started outgoing file transfer while not supporting transport methods. + setFinishedState(FileTransfer.State.Type.Failed, + new FileTransferError(FileTransferError.Type.UnknownError)); + } + else { + setTransporter(transporterFactory.createInitiatorTransporter(getInitiator(), getResponder(), options)); + setInternalState(State.GeneratingInitialLocalCandidates); + transporter.startGeneratingLocalCandidates(); + } + } /** @@ -217,6 +226,13 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou setInternalState(State.TryingCandidates); transporter.startTryingRemoteCandidates(); } + else if (transportPayload instanceof JingleIBBTransportPayload) { + JingleIBBTransportPayload ibbPayload = (JingleIBBTransportPayload) transportPayload; + int blockSize = ibbPayload.getBlockSize() != null ? + ibbPayload.getBlockSize().intValue() : DEFAULT_BLOCK_SIZE; + startTransferring(transporter.createIBBSendSession(ibbPayload.getSessionID(), + blockSize, stream)); + } else { logger_.fine("Unknown transport payload. Falling back.\n"); fallback(); @@ -310,14 +326,25 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou fileInfo.addHash(new HashElement("md5", new ByteArray())); description.setFileInfo(fileInfo); - JingleS5BTransportPayload transport = new JingleS5BTransportPayload(); - transport.setSessionID(s5bSessionID); - transport.setMode(JingleS5BTransportPayload.Mode.TCPMode); - transport.setDstAddr(dstAddr); - for(JingleS5BTransportPayload.Candidate candidate : candidates) { - transport.addCandidate(candidate); - logger_.fine("\t" + "S5B candidate: " + candidate.hostPort.toString() + "\n"); - } + JingleTransportPayload transport = null; + if (candidates.isEmpty()) { + logger_.fine("no S5B candidate generated. Send IBB transport candidate.\n"); + JingleIBBTransportPayload ibbTransport = new JingleIBBTransportPayload(); + ibbTransport.setBlockSize(DEFAULT_BLOCK_SIZE); + ibbTransport.setSessionID(idGenerator.generateID()); + transport = ibbTransport; + } + else { + JingleS5BTransportPayload s5bTransport = new JingleS5BTransportPayload(); + s5bTransport.setSessionID(s5bSessionID); + s5bTransport.setMode(JingleS5BTransportPayload.Mode.TCPMode); + s5bTransport.setDstAddr(dstAddr); + for (JingleS5BTransportPayload.Candidate candidate : candidates) { + s5bTransport.addCandidate(candidate); + logger_.fine("\tS5B candidate: "+candidate.hostPort +"\n"); + } + transport = s5bTransport; + } setInternalState(State.WaitingForAccept); session.sendInitiate(contentID, description, transport); } diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java index 590ee60..0d1f0a9 100644 --- a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java +++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java @@ -126,6 +126,10 @@ public class SOCKS5BytestreamServerManager { forwardPortRequest.stop(); forwardPortRequest = null; } + if (unforwardPortRequest != null) { + unforwardPortRequest.stop(); + unforwardPortRequest = null; + } if (server != null) { server.stop(); server = null; |