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/SOCKS5BytestreamProxiesManager.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/SOCKS5BytestreamProxiesManager.java')
-rw-r--r--src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxiesManager.java101
1 files changed, 52 insertions, 49 deletions
diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxiesManager.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxiesManager.java
index eab3031..f541222 100644
--- a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxiesManager.java
+++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamProxiesManager.java
@@ -16,29 +16,29 @@
package com.isode.stroke.filetransfer;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import java.util.logging.Logger;
+
+import com.isode.stroke.elements.S5BProxyRequest;
+import com.isode.stroke.jid.JID;
import com.isode.stroke.network.Connection;
import com.isode.stroke.network.ConnectionFactory;
-import com.isode.stroke.network.DomainNameResolver;
-import com.isode.stroke.network.TimerFactory;
-import com.isode.stroke.network.HostAddressPort;
-import com.isode.stroke.network.DomainNameResolveError;
import com.isode.stroke.network.DomainNameAddressQuery;
+import com.isode.stroke.network.DomainNameResolveError;
+import com.isode.stroke.network.DomainNameResolver;
import com.isode.stroke.network.HostAddress;
+import com.isode.stroke.network.HostAddressPort;
+import com.isode.stroke.network.TimerFactory;
import com.isode.stroke.queries.IQRouter;
-import com.isode.stroke.session.Session;
-import com.isode.stroke.signals.Slot1;
-import com.isode.stroke.signals.Slot2;
import com.isode.stroke.signals.Signal;
import com.isode.stroke.signals.SignalConnection;
-import com.isode.stroke.elements.S5BProxyRequest;
-import com.isode.stroke.jid.JID;
-
-import java.util.Iterator;
-import java.util.Vector;
-import java.util.Collection;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.logging.Logger;
+import com.isode.stroke.signals.Slot1;
+import com.isode.stroke.signals.Slot2;
/**
* - manages list of working S5B proxies
@@ -53,8 +53,6 @@ public class SOCKS5BytestreamProxiesManager {
private JID serviceRoot_;
private Logger logger_ = Logger.getLogger(this.getClass().getName());
- // TODO plonk this into the pair or not
- // TODO think what this is trying to do?
private static class Pair {
public JID jid;
public SOCKS5BytestreamClientSession sock5;
@@ -64,7 +62,8 @@ public class SOCKS5BytestreamProxiesManager {
private Map<String, Collection<Pair> > proxySessions_ = new HashMap<String, Collection<Pair> >();
- /**
+ private SignalConnection onProxiesFoundConnection;
+ /**
* Map between {@link SOCKS5BytestreamClientSession} and a {@link SignalConnection} to their
* {@link SOCKS5BytestreamClientSession#onSessionReady}
*/
@@ -183,31 +182,37 @@ public class SOCKS5BytestreamProxiesManager {
}
public final Signal onDiscoveredProxiesChanged = new Signal();
-
- private void handleProxyFound(final S5BProxyRequest proxy) {
- if (proxy != null) {
- if (new HostAddress(proxy.getStreamHost().host).isValid()) {
- addS5BProxy(proxy);
- onDiscoveredProxiesChanged.emit();
- }
- else {
- DomainNameAddressQuery resolveRequest = resolver_.createAddressQuery(proxy.getStreamHost().host);
- resolveRequest.onResult.connect(new Slot2<Collection<HostAddress>, DomainNameResolveError>() {
- @Override
- public void call(Collection<HostAddress> c, DomainNameResolveError d) {
- handleNameLookupResult(c, d, proxy);
- }
- });
- resolveRequest.run();
- }
- }
- else {
- onDiscoveredProxiesChanged.emit();
- }
- proxyFinder_.stop();
- proxyFinder_ = null;
+
+ private void handleProxiesFound(Collection<? extends S5BProxyRequest> proxyHosts) {
+ if (onProxiesFoundConnection != null) {
+ onProxiesFoundConnection.disconnect();
+ onProxiesFoundConnection = null;
+ }
+ for (final S5BProxyRequest proxy : proxyHosts) {
+ if (proxy != null) {
+ if (new HostAddress(proxy.getStreamHost().host).isValid()) {
+ addS5BProxy(proxy);
+ onDiscoveredProxiesChanged.emit();
+ }
+ else {
+ DomainNameAddressQuery resolveRequest = resolver_.createAddressQuery(proxy.getStreamHost().host);
+ resolveRequest.onResult.connect(new Slot2<Collection<HostAddress>, DomainNameResolveError>() {
+ @Override
+ public void call(Collection<HostAddress> c, DomainNameResolveError d) {
+ handleNameLookupResult(c, d, proxy);
+ }
+ });
+ resolveRequest.run();
+ }
+ }
+ }
+ proxyFinder_.stop();
+ proxyFinder_ = null;
+ if (proxyHosts.isEmpty()) {
+ onDiscoveredProxiesChanged.emit();
+ }
}
-
+
private void handleNameLookupResult(final Collection<HostAddress> addresses, DomainNameResolveError error, S5BProxyRequest proxy) {
if (error != null) {
onDiscoveredProxiesChanged.emit();
@@ -215,7 +220,6 @@ public class SOCKS5BytestreamProxiesManager {
else {
if (addresses.isEmpty()) {
logger_.warning("S5B proxy hostname does not resolve.\n");
- onDiscoveredProxiesChanged.emit();
}
else {
// generate proxy per returned address
@@ -226,18 +230,17 @@ public class SOCKS5BytestreamProxiesManager {
proxyForAddress.setStreamHost(streamHost);
addS5BProxy(proxyForAddress);
}
- onDiscoveredProxiesChanged.emit();
}
+ onDiscoveredProxiesChanged.emit();
}
}
private void queryForProxies() {
proxyFinder_ = new SOCKS5BytestreamProxyFinder(serviceRoot_, iqRouter_);
-
- proxyFinder_.onProxyFound.connect(new Slot1<S5BProxyRequest>() {
+ onProxiesFoundConnection = proxyFinder_.onProxiesFound.connect(new Slot1<List<S5BProxyRequest>>() {
@Override
- public void call(S5BProxyRequest s) {
- handleProxyFound(s);
+ public void call(List<S5BProxyRequest> s) {
+ handleProxiesFound(s);
}
});
proxyFinder_.start();