diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-08-03 12:08:37 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-01-21 10:47:51 (GMT) |
commit | 97a085f7e2c9b7820000eaace97dc0ab6392cb0d (patch) | |
tree | d3df191a053a69bc52238b76b8e9e42af043302c /src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java | |
parent | fa1633e3b4d75a8217459cdc5fe64e9ee5ace65a (diff) | |
download | stroke-97a085f7e2c9b7820000eaace97dc0ab6392cb0d.zip stroke-97a085f7e2c9b7820000eaace97dc0ab6392cb0d.tar.bz2 |
Completes FileTransfer according to Swiften.
S5BTransport Session still needs generic T.
FileTransfer, OutgoingFileTransfer and IncomingFileTransfer are made an interface due to the need of multiple inheritance in
IncomingJingleFileTransfer and OutgoingJingleFileTransfer. Corresponding documentation has been updated.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
None.
Change-Id: If44cf387767865c37492d871c12d623f94ebaa3a
Diffstat (limited to 'src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java')
-rw-r--r-- | src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java new file mode 100644 index 0000000..d856a2f --- /dev/null +++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.filetransfer; + +import com.isode.stroke.network.HostAddressPort; +import com.isode.stroke.elements.S5BProxyRequest; +import com.isode.stroke.elements.ErrorPayload; +import com.isode.stroke.elements.DiscoInfo; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.disco.DiscoServiceWalker; +import com.isode.stroke.queries.IQRouter; +import com.isode.stroke.queries.GenericRequest; +import com.isode.stroke.signals.Signal1; +import com.isode.stroke.signals.SignalConnection; +import com.isode.stroke.signals.Slot2; +import com.isode.stroke.jid.JID; +import java.util.Vector; +import java.util.logging.Logger; + +/* + * This class is designed to find possible SOCKS5 bytestream proxies which are used for peer-to-peer data transfers in + * restrictive environments. + */ +public class SOCKS5BytestreamProxyFinder { + + private JID service; + private IQRouter iqRouter; + private DiscoServiceWalker serviceWalker; + private Vector<GenericRequest<S5BProxyRequest> > requests = new Vector<GenericRequest<S5BProxyRequest>>(); + private SignalConnection onServiceFoundConnection; + private Logger logger_ = Logger.getLogger(this.getClass().getName()); + + public SOCKS5BytestreamProxyFinder(final JID service, IQRouter iqRouter) { + this.service = service; + this.iqRouter = iqRouter; + } + + public void start() { + serviceWalker = new DiscoServiceWalker(service, iqRouter); + onServiceFoundConnection = serviceWalker.onServiceFound.connect(new Slot2<JID, DiscoInfo>() { + @Override + public void call(JID j, DiscoInfo d) { + handleServiceFound(j, d); + } + }); + serviceWalker.beginWalk(); + } + + public void stop() { + serviceWalker.endWalk(); + onServiceFoundConnection.disconnect(); + serviceWalker = null; + } + + public final Signal1<S5BProxyRequest> onProxyFound = new Signal1<S5BProxyRequest>(); + + private void sendBytestreamQuery(final JID jid) { + S5BProxyRequest proxyRequest = new S5BProxyRequest(); + GenericRequest<S5BProxyRequest> request = new GenericRequest<S5BProxyRequest>(IQ.Type.Get, jid, proxyRequest, iqRouter); + request.onResponse.connect(new Slot2<S5BProxyRequest, ErrorPayload>() { + @Override + public void call(S5BProxyRequest s, ErrorPayload e) { + handleProxyResponse(s, e); + } + }); + request.send(); + } + + private void handleServiceFound(final JID jid, DiscoInfo discoInfo) { + if (discoInfo.hasFeature(DiscoInfo.Bytestream)) { + sendBytestreamQuery(jid); + } + } + private void handleProxyResponse(S5BProxyRequest request, ErrorPayload error) { + if (error != null) { + logger_.fine("ERROR\n"); + } else { + if (request != null) { + onProxyFound.emit(request); + } else { + //assert(false); + } + } + } +}
\ No newline at end of file |