summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-01-27 16:36:15 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-01-28 12:25:43 (GMT)
commitceb4798aa0739ebd7177632c3f508babacb2f8d7 (patch)
tree7e5a2c1852261c8f0e4d8ed3262a32cced037378 /src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java
parent93eb4ab62a08da883cab4a3743a3a86c198eb0b4 (diff)
downloadstroke-ceb4798aa0739ebd7177632c3f508babacb2f8d7.zip
stroke-ceb4798aa0739ebd7177632c3f508babacb2f8d7.tar.bz2
Changes to FileTransfer to be inline with current Swiften code
There has been some changes to the file transfer clases in Swiften since Tarun's patch was written. This patch updates the java classes to bring them in line with the swiften one. In details IBBSendSession - added code to clean up onResponse connection when not needed. In Swiften this was done by keeping reference to current session using boost bindings to remove binding. In java we have to keep a reference to the current onResponse connection and disconnect it when not neeeded. IncomingFileTransferManager - Remove redundant IQRouter field. LocalJingeTransportCandidateGenerator - Do not advertise link-local IPv6 addresses in FT candidates OutgoingSIFileTransfer - File deleted SOCKS5BytestreamProxiesManager and SOCKS5BytestreamProxyFinder - Search for all proxies instead of just one. Test-information: Ran make and make test to check everything built ok and that the unit tests still passed. Change-Id: I696444e5074fe20625243693a44c836306b3a41e
Diffstat (limited to 'src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java')
-rw-r--r--src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java88
1 files changed, 65 insertions, 23 deletions
diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java
index d856a2f..e880bfb 100644
--- a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java
+++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxyFinder.java
@@ -16,32 +16,45 @@
package com.isode.stroke.filetransfer;
-import com.isode.stroke.network.HostAddressPort;
-import com.isode.stroke.elements.S5BProxyRequest;
-import com.isode.stroke.elements.ErrorPayload;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import com.isode.stroke.disco.DiscoServiceWalker;
import com.isode.stroke.elements.DiscoInfo;
+import com.isode.stroke.elements.ErrorPayload;
import com.isode.stroke.elements.IQ;
-import com.isode.stroke.disco.DiscoServiceWalker;
-import com.isode.stroke.queries.IQRouter;
+import com.isode.stroke.elements.S5BProxyRequest;
+import com.isode.stroke.jid.JID;
import com.isode.stroke.queries.GenericRequest;
+import com.isode.stroke.queries.IQRouter;
import com.isode.stroke.signals.Signal1;
import com.isode.stroke.signals.SignalConnection;
+import com.isode.stroke.signals.Slot;
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 final List<S5BProxyRequest> proxyHosts = new ArrayList<S5BProxyRequest>();
+ private final Set<GenericRequest<S5BProxyRequest>> pendingRequests = new HashSet<GenericRequest<S5BProxyRequest>>();
+
private SignalConnection onServiceFoundConnection;
+ private SignalConnection onWalkCompleteConnection;
+ private final Map<GenericRequest<S5BProxyRequest>,SignalConnection> requestOnResponseConnections
+ = new HashMap<GenericRequest<S5BProxyRequest>,SignalConnection>();
+
+
private Logger logger_ = Logger.getLogger(this.getClass().getName());
public SOCKS5BytestreamProxyFinder(final JID service, IQRouter iqRouter) {
@@ -57,27 +70,42 @@ public class SOCKS5BytestreamProxyFinder {
handleServiceFound(j, d);
}
});
+ onWalkCompleteConnection = serviceWalker.onWalkComplete.connect(new Slot() {
+
+ @Override
+ public void call() {
+ handleWalkEnded();
+ }
+
+ });
serviceWalker.beginWalk();
}
public void stop() {
- serviceWalker.endWalk();
+ for (SignalConnection onResponseConnection : requestOnResponseConnections.values()) {
+ onResponseConnection.disconnect();
+ }
+ requestOnResponseConnections.clear();
+ serviceWalker.endWalk();
onServiceFoundConnection.disconnect();
+ onWalkCompleteConnection.disconnect();
serviceWalker = null;
}
-
- public final Signal1<S5BProxyRequest> onProxyFound = new Signal1<S5BProxyRequest>();
+
+ public final Signal1<List<S5BProxyRequest>> onProxiesFound = new Signal1<List<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>() {
+ final GenericRequest<S5BProxyRequest> requester = new GenericRequest<S5BProxyRequest>(IQ.Type.Get, jid, proxyRequest, iqRouter);
+ SignalConnection requestOnResponseConnection = requester.onResponse.connect(new Slot2<S5BProxyRequest, ErrorPayload>() {
@Override
public void call(S5BProxyRequest s, ErrorPayload e) {
- handleProxyResponse(s, e);
+ handleProxyResponse(requester,s,e);
}
});
- request.send();
+ pendingRequests.add(requester);
+ requestOnResponseConnections.put(requester, requestOnResponseConnection);
+ requester.send();
}
private void handleServiceFound(final JID jid, DiscoInfo discoInfo) {
@@ -85,15 +113,29 @@ public class SOCKS5BytestreamProxyFinder {
sendBytestreamQuery(jid);
}
}
- private void handleProxyResponse(S5BProxyRequest request, ErrorPayload error) {
- if (error != null) {
+
+ private void handleWalkEnded() {
+ if (pendingRequests.isEmpty()) {
+ onProxiesFound.emit(proxyHosts);
+ }
+ }
+
+ private void handleProxyResponse(GenericRequest<S5BProxyRequest> requester,S5BProxyRequest request, ErrorPayload error) {
+ SignalConnection requestOnResponseConnection = requestOnResponseConnections.remove(request);
+ if (requestOnResponseConnection != null) {
+ requestOnResponseConnection.disconnect();
+ }
+ pendingRequests.remove(requester);
+ if (error != null) {
logger_.fine("ERROR\n");
} else {
if (request != null) {
- onProxyFound.emit(request);
- } else {
- //assert(false);
- }
+ logger_.fine("add request\n");
+ proxyHosts.add(request);
+ }
}
+ if (pendingRequests.isEmpty() && !serviceWalker.isActive()) {
+ onProxiesFound.emit(proxyHosts);
+ }
}
} \ No newline at end of file