summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-07-27 15:01:45 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-01-12 11:31:04 (GMT)
commitb4cf2bb8d7b69d95b4a10d610ad259998d2aee5b (patch)
treeb942953236a7c712eed6ce4a5f261019691c0dca /src/com/isode/stroke/network/Connector.java
parentc168fcd0c2468ec939b8d164175e9c5776a63147 (diff)
downloadstroke-b4cf2bb8d7b69d95b4a10d610ad259998d2aee5b.zip
stroke-b4cf2bb8d7b69d95b4a10d610ad259998d2aee5b.tar.bz2
Make Networks equivalent with Swiften.
Adds ProxyProviders, DomainNameResolvers and DummyConnection. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for ChainedConnector, Connector and HostAddress. Test also added for ComponentConnector, which needed bits of Network. Five assertions are commented in ConnectorTest, which fails and will be updated after review. Change-Id: I8a62841eb2f9c109bc3a94865b7a003b33493e11
Diffstat (limited to 'src/com/isode/stroke/network/Connector.java')
-rw-r--r--src/com/isode/stroke/network/Connector.java27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/com/isode/stroke/network/Connector.java b/src/com/isode/stroke/network/Connector.java
index 13a2bc3..6033a89 100644
--- a/src/com/isode/stroke/network/Connector.java
+++ b/src/com/isode/stroke/network/Connector.java
@@ -32,7 +32,6 @@ public class Connector {
assert serviceQuery == null;
assert timer == null;
queriedAllServices = false;
- serviceQueryResults = new ArrayList<Result>();
if (timeoutMilliseconds > 0) {
timer = timerFactory.createTimer(timeoutMilliseconds);
@@ -41,10 +40,9 @@ public class Connector {
handleTimeout();
}
});
- timer.start();
}
if (serviceLookupPrefix != null) {
- serviceQuery = resolver.createServiceQuery(serviceLookupPrefix + hostname);
+ serviceQuery = resolver.createServiceQuery(serviceLookupPrefix, hostname);
serviceQuery.onResult.connect(new Slot1<Collection<DomainNameServiceQuery.Result>>() {
public void call(Collection<Result> p1) {
handleServiceQueryResult(p1);
@@ -52,6 +50,12 @@ public class Connector {
});
serviceQuery.run();
}
+ else if (new HostAddress(hostname).isValid()) {
+ // hostname is already a valid address; skip name lookup.
+ foundSomeDNS = true;
+ addressQueryResults.add(new HostAddress(hostname));
+ tryNextAddress();
+ }
else {
queryAddress(hostname);
}
@@ -70,6 +74,9 @@ public class Connector {
this.timerFactory = timerFactory;
this.port = port;
this.serviceLookupPrefix = serviceLookupPrefix;
+ this.timeoutMilliseconds = 0;
+ this.queriedAllServices = true;
+ this.foundSomeDNS = false;
}
private void handleServiceQueryResult(Collection<Result> result) {
@@ -161,10 +168,17 @@ public class Connector {
});
currentConnection.connect(target);
+ if (timer != null) {
+ timer.start();
+ }
}
private void handleConnectionConnectFinished(boolean error) {
//std::cout << "Connector::handleConnectionConnectFinished() " << error << std::endl;
+ if (timer != null) {
+ timer.stop();
+ timer = null;
+ }
currentConnectionConnectFinishedConnection.disconnect();
if (error) {
currentConnection = null;
@@ -206,7 +220,8 @@ public class Connector {
}
private void handleTimeout() {
- finish(null);
+ //SWIFT_LOG(debug) << "Timeout" << std::endl;
+ handleConnectionConnectFinished(true);
}
@Override
@@ -223,9 +238,9 @@ public class Connector {
private int timeoutMilliseconds = 0;
private Timer timer;
private DomainNameServiceQuery serviceQuery;
- private ArrayList<DomainNameServiceQuery.Result> serviceQueryResults;
+ private ArrayList<DomainNameServiceQuery.Result> serviceQueryResults = new ArrayList<DomainNameServiceQuery.Result>();
private DomainNameAddressQuery addressQuery;
- private ArrayList<HostAddress> addressQueryResults;
+ private ArrayList<HostAddress> addressQueryResults = new ArrayList<HostAddress>();
private boolean queriedAllServices = true;
private Connection currentConnection;
private SignalConnection currentConnectionConnectFinishedConnection;