summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-03-15 12:20:50 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-03-15 14:14:14 (GMT)
commitb1ac3f64bfa7924da8bdeaf01308259018fe5148 (patch)
tree5e8b5d40888b80b4ab12de771a3e0b6f661f178f
parent3205cbf499196b32379c66cb0bea4ccd77334210 (diff)
downloadstroke-b1ac3f64bfa7924da8bdeaf01308259018fe5148.zip
stroke-b1ac3f64bfa7924da8bdeaf01308259018fe5148.tar.bz2
Add getRemoteAddress() method to Connection.
Added a getRemoteAddress() method to connection as per patch 'Listen to IPv6 any address instead of only IPv4' (13801557b6664426cac26384441ab0b19ff9abb5). Also some modifications to SOCKS5BytestreamServerManager to use IPv6 address. Test-information: Unit tests pass ok. Change-Id: Ic0536745db9052ec1c5fc0832ed90eb5ec609429
-rw-r--r--src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java4
-rw-r--r--src/com/isode/stroke/network/Connection.java3
-rw-r--r--src/com/isode/stroke/network/DummyConnection.java14
-rw-r--r--src/com/isode/stroke/network/FakeConnection.java8
-rw-r--r--src/com/isode/stroke/network/JavaConnection.java29
-rw-r--r--src/com/isode/stroke/network/ProxiedConnection.java5
-rw-r--r--src/com/isode/stroke/network/TLSConnection.java5
-rw-r--r--test/com/isode/stroke/component/ComponentConnectorTest.java7
-rw-r--r--test/com/isode/stroke/network/ChainedConnectorTest.java8
-rw-r--r--test/com/isode/stroke/network/ConnectorTest.java7
10 files changed, 78 insertions, 12 deletions
diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java
index 729193a..590ee60 100644
--- a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java
+++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2015 Isode Limited.
+ * Copyright (c) 2012-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -176,7 +176,7 @@ public class SOCKS5BytestreamServerManager {
int port;
for (port = LISTEN_PORTS_BEGIN; port < LISTEN_PORTS_END; ++port) {
logger_.fine("Trying to start server on port " + port + "\n");
- connectionServer = connectionServerFactory.createConnectionServer(new HostAddress("0.0.0.0"), port);
+ connectionServer = connectionServerFactory.createConnectionServer(new HostAddress("::"), port);
ConnectionServer.Error error = connectionServer.tryStart();
if (error == null) {
break;
diff --git a/src/com/isode/stroke/network/Connection.java b/src/com/isode/stroke/network/Connection.java
index b0e4799..ad01553 100644
--- a/src/com/isode/stroke/network/Connection.java
+++ b/src/com/isode/stroke/network/Connection.java
@@ -4,7 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
/*
- * Copyright (c) 2010, Isode Limited, London, England.
+ * Copyright (c) 2010-2016, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.network;
@@ -33,6 +33,7 @@ public abstract class Connection {
public abstract void write(SafeByteArray data);
public abstract HostAddressPort getLocalAddress();
+ public abstract HostAddressPort getRemoteAddress();
public final Signal1<Boolean /*error*/> onConnectFinished = new Signal1<Boolean>();
public final Signal1<Error> onDisconnected = new Signal1<Error>();
public final Signal1<SafeByteArray> onDataRead = new Signal1<SafeByteArray>();
diff --git a/src/com/isode/stroke/network/DummyConnection.java b/src/com/isode/stroke/network/DummyConnection.java
index 51018ef..7cc302b 100644
--- a/src/com/isode/stroke/network/DummyConnection.java
+++ b/src/com/isode/stroke/network/DummyConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -58,8 +58,14 @@ public class DummyConnection extends Connection implements EventOwner {
return localAddress;
}
- public Signal1<SafeByteArray> onDataSent = new Signal1<SafeByteArray>();
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return remoteAddress;
+ }
- public EventLoop eventLoop;
- public HostAddressPort localAddress;
+ public Signal1<SafeByteArray> onDataSent = new Signal1<SafeByteArray>();
+
+ public EventLoop eventLoop;
+ public HostAddressPort localAddress = new HostAddressPort();
+ public HostAddressPort remoteAddress = new HostAddressPort();
} \ No newline at end of file
diff --git a/src/com/isode/stroke/network/FakeConnection.java b/src/com/isode/stroke/network/FakeConnection.java
index ebcf239..1ce5c7b 100644
--- a/src/com/isode/stroke/network/FakeConnection.java
+++ b/src/com/isode/stroke/network/FakeConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2014 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.eventloop.EventOwner;
import com.isode.stroke.eventloop.EventLoop;
import com.isode.stroke.eventloop.Event;
import com.isode.stroke.base.SafeByteArray;
+
import java.util.Vector;
public class FakeConnection extends Connection {
@@ -40,6 +41,11 @@ public class FakeConnection extends Connection {
public HostAddressPort getLocalAddress() {
return new HostAddressPort();
}
+
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return new HostAddressPort();
+ }
public void setError(final Error e) {
error = e;
diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java
index 29e3633..745655f 100644
--- a/src/com/isode/stroke/network/JavaConnection.java
+++ b/src/com/isode/stroke/network/JavaConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015, Isode Limited, London, England.
+ * Copyright (c) 2010-2016, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.network;
@@ -7,8 +7,10 @@ package com.isode.stroke.network;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
+import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
+import java.nio.channels.ClosedChannelException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@@ -515,6 +517,31 @@ public class JavaConnection extends Connection implements EventOwner {
}
@Override
+ public HostAddressPort getRemoteAddress() {
+ if (socketChannel_ == null) {
+ return null;
+ }
+ SocketAddress remoteAddress;
+ try {
+ remoteAddress = socketChannel_.getRemoteAddress();
+ } catch (ClosedChannelException e) {
+ return null;
+ } catch (IOException e) {
+ return null;
+ }
+ if (!(remoteAddress instanceof InetSocketAddress)) {
+ // SocketChannel.getRemoteAddress should return a
+ // InetSocketAddress if it is bound to an IP Socket
+ // Address so return null if it does not
+ return null;
+ }
+ InetSocketAddress remoteInetAddress = (InetSocketAddress) remoteAddress;
+ return new HostAddressPort(
+ new HostAddress(remoteInetAddress.getAddress()),
+ remoteInetAddress.getPort());
+ }
+
+ @Override
public String toString()
{
return "JavaConnection " +
diff --git a/src/com/isode/stroke/network/ProxiedConnection.java b/src/com/isode/stroke/network/ProxiedConnection.java
index 6f4c044..5eac083 100644
--- a/src/com/isode/stroke/network/ProxiedConnection.java
+++ b/src/com/isode/stroke/network/ProxiedConnection.java
@@ -87,6 +87,11 @@ public abstract class ProxiedConnection extends Connection {
public HostAddressPort getLocalAddress() {
return connection_.getLocalAddress();
}
+
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return connection_.getRemoteAddress();
+ }
private void handleConnectFinished(Connection connection) {
cancelConnector();
diff --git a/src/com/isode/stroke/network/TLSConnection.java b/src/com/isode/stroke/network/TLSConnection.java
index d64f88b..4e7f304 100644
--- a/src/com/isode/stroke/network/TLSConnection.java
+++ b/src/com/isode/stroke/network/TLSConnection.java
@@ -124,6 +124,11 @@ public class TLSConnection extends Connection {
return connection.getLocalAddress();
}
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return connection.getRemoteAddress();
+ }
+
public TLSContext getContext() {
return context;
}
diff --git a/test/com/isode/stroke/component/ComponentConnectorTest.java b/test/com/isode/stroke/component/ComponentConnectorTest.java
index 413f325..0a59a7d 100644
--- a/test/com/isode/stroke/component/ComponentConnectorTest.java
+++ b/test/com/isode/stroke/component/ComponentConnectorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -68,6 +68,11 @@ public class ComponentConnectorTest {
}
public HostAddressPort getLocalAddress() { return new HostAddressPort(); }
+
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return new HostAddressPort();
+ }
public void disconnect() { assert(false); }
diff --git a/test/com/isode/stroke/network/ChainedConnectorTest.java b/test/com/isode/stroke/network/ChainedConnectorTest.java
index a2bb98c..e3661d3 100644
--- a/test/com/isode/stroke/network/ChainedConnectorTest.java
+++ b/test/com/isode/stroke/network/ChainedConnectorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -63,6 +63,12 @@ public class ChainedConnectorTest {
}
public HostAddressPort getLocalAddress() { return new HostAddressPort(); }
+
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return new HostAddressPort();
+ }
+
public void disconnect() { assert(false); }
public void write(final SafeByteArray data) { assert(false); }
diff --git a/test/com/isode/stroke/network/ConnectorTest.java b/test/com/isode/stroke/network/ConnectorTest.java
index 43e2300..95080af 100644
--- a/test/com/isode/stroke/network/ConnectorTest.java
+++ b/test/com/isode/stroke/network/ConnectorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2014 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -69,6 +69,11 @@ public class ConnectorTest {
}
public HostAddressPort getLocalAddress() { return new HostAddressPort(); }
+
+ @Override
+ public HostAddressPort getRemoteAddress() {
+ return new HostAddressPort();
+ }
public void disconnect() { assert(false); }