From 053ce887432c69caba9a9cbca2e4f06a321c728e Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 31 Aug 2014 13:17:44 +0000 Subject: [PATCH] * I2PTunnel: Allow changing of spoof host and target host/port without restarting server tunnel --- .../i2p/i2ptunnel/I2PTunnelHTTPServer.java | 4 +++ .../net/i2p/i2ptunnel/I2PTunnelServer.java | 27 +++++++++++++++++-- .../net/i2p/i2ptunnel/TunnelController.java | 11 ++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index 128b1565d3..ac1d2d39a7 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -182,6 +182,10 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { if (getTunnel() != tunnel) return; setupPostThrottle(); + Properties props = tunnel.getClientOptions(); + // see TunnelController.setSessionOptions() + String spoofHost = props.getProperty(TunnelController.PROP_SPOOFED_HOST); + _spoofHost = (spoofHost != null && spoofHost.trim().length() > 0) ? spoofHost.trim() : null; super.optionsUpdated(tunnel); } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index c79e274e08..dfec31bc37 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -16,6 +16,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.security.GeneralSecurityException; import java.util.Map; import java.util.Properties; @@ -50,8 +51,8 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { protected final Object slock = new Object(); protected final Object sslLock = new Object(); - protected final InetAddress remoteHost; - protected final int remotePort; + protected InetAddress remoteHost; + protected int remotePort; private final boolean _usePool; protected final Logging l; private I2PSSLSocketFactory _sslFactory; @@ -350,6 +351,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { /** * Update the I2PSocketManager. + * And since 0.9.15, the target host and port. * * @since 0.9.1 */ @@ -359,6 +361,27 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { return; Properties props = tunnel.getClientOptions(); sockMgr.setDefaultOptions(sockMgr.buildOptions(props)); + // see TunnelController.setSessionOptions() + String h = props.getProperty(TunnelController.PROP_TARGET_HOST); + if (h != null) { + try { + remoteHost = InetAddress.getByName(h); + } catch (UnknownHostException uhe) { + l.log("Unknown host: " + h); + } + } + String p = props.getProperty(TunnelController.PROP_TARGET_PORT); + if (p != null) { + try { + int port = Integer.parseInt(p); + if (port > 0 && port <= 65535) + remotePort = port; + else + l.log("Bad port: " + port); + } catch (NumberFormatException nfe) { + l.log("Bad port: " + p); + } + } buildSocketMap(props); } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index 96fab6213b..32b8b85af3 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -487,6 +487,17 @@ public class TunnelController implements Logging { String proxies = getProxyList(); if (proxies != null) opts.setProperty(PROP_PROXIES, proxies); + // Ditto spoof host. Since 0.9.15. + String spoofhost = getSpoofedHost(); + if (spoofhost != null) + opts.setProperty(PROP_SPOOFED_HOST, spoofhost); + // Ditto target host/port. Since 0.9.15. + String targethost = getTargetHost(); + if (targethost != null) + opts.setProperty(PROP_TARGET_HOST, targethost); + String targetport = getTargetPort(); + if (targetport != null) + opts.setProperty(PROP_TARGET_PORT, targetport); _tunnel.setClientOptions(opts); } -- GitLab