From e383477b01b16ae0dbc504bc182c74cf4e161218 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Tue, 19 Jun 2012 21:48:31 +0000
Subject: [PATCH]  * Socks: Pass remote port through  * I2PTunnel: More javadoc
 warnings on default options

---
 .../java/src/net/i2p/i2ptunnel/I2PTunnel.java     |  5 +++--
 .../net/i2p/i2ptunnel/I2PTunnelClientBase.java    | 11 +++++++----
 .../net/i2p/i2ptunnel/I2PTunnelConnectClient.java |  5 +++--
 .../net/i2p/i2ptunnel/I2PTunnelHTTPClient.java    | 15 ++++++++++-----
 .../net/i2p/i2ptunnel/socks/SOCKS4aServer.java    |  7 ++++++-
 .../src/net/i2p/i2ptunnel/socks/SOCKS5Server.java |  5 ++++-
 6 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
index ddf3fd155e..052a211f45 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
@@ -209,8 +209,9 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
     }
     
     /**
-     *  Generic options used for clients and servers
-     *  @return not a copy
+     *  Generic options used for clients and servers.
+     *  NOT a copy, Do NOT modify for per-connection options, make a copy.
+     *  @return NOT a copy, do NOT modify for per-connection options
      */
     public Properties getClientOptions() { return _clientOptions; }
     
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java
index 916550dcf7..1e69e0e182 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java
@@ -471,8 +471,9 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
     }
 
     /** 
-     * create the default options (using the default timeout, etc)
-     *
+     * Create the default options (using the default timeout, etc).
+     * Warning, this does not make a copy of I2PTunnel's client options,
+     * it modifies them directly.
      */
     protected I2PSocketOptions getDefaultOptions() {
         Properties defaultOpts = getTunnel().getClientOptions();
@@ -483,8 +484,10 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
     }
     
     /** 
-     * create the default options (using the default timeout, etc)
-     *
+     * Create the default options (using the default timeout, etc).
+     * Warning, this does not make a copy of I2PTunnel's client options,
+     * it modifies them directly.
+     * Do not use overrides for per-socket options.
      */
     protected I2PSocketOptions getDefaultOptions(Properties overrides) {
         Properties defaultOpts = getTunnel().getClientOptions();
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java
index 49261da242..f8113382d1 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java
@@ -132,8 +132,9 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R
     }
 
     /** 
-     * create the default options (using the default timeout, etc)
-     *
+     * Create the default options (using the default timeout, etc).
+     * Warning, this does not make a copy of I2PTunnel's client options,
+     * it modifies them directly.
      */
     @Override
     protected I2PSocketOptions getDefaultOptions() {
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
index 267bc312cc..195d4fbada 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
@@ -225,7 +225,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
     }
 
     /**
-     * create the default options (using the default timeout, etc)
+     * Create the default options (using the default timeout, etc).
+     * Warning, this does not make a copy of I2PTunnel's client options,
+     * it modifies them directly.
      * unused?
      */
     @Override
@@ -244,8 +246,10 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
     }
 
     /**
-     * create the default options (using the default timeout, etc)
-     *
+     * Create the default options (using the default timeout, etc).
+     * Warning, this does not make a copy of I2PTunnel's client options,
+     * it modifies them directly.
+     * Do not use overrides for per-socket options.
      */
     @Override
     protected I2PSocketOptions getDefaultOptions(Properties overrides) {
@@ -965,12 +969,13 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
                 return;
             }
 
-            Properties opts = new Properties();
+            //Properties opts = new Properties();
             //opts.setProperty("i2p.streaming.inactivityTimeout", ""+120*1000);
             // 1 == disconnect.  see ConnectionOptions in the new streaming lib, which i
             // dont want to hard link to here
             //opts.setProperty("i2p.streaming.inactivityTimeoutAction", ""+1);
-            I2PSocketOptions sktOpts = getDefaultOptions(opts);
+            //I2PSocketOptions sktOpts = getDefaultOptions(opts);
+            I2PSocketOptions sktOpts = getDefaultOptions();
             if (remotePort > 0)
                 sktOpts.setPort(remotePort);
             I2PSocket i2ps = createI2PSocket(clientDest, sktOpts);
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java
index 63c38dc75c..36c377857f 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java
@@ -15,10 +15,12 @@ import java.net.Socket;
 import java.net.SocketException;
 import java.util.List;
 import java.util.Locale;
+import java.util.Properties;
 
 import net.i2p.I2PAppContext;
 import net.i2p.I2PException;
 import net.i2p.client.streaming.I2PSocket;
+import net.i2p.client.streaming.I2PSocketOptions;
 import net.i2p.data.DataFormatException;
 import net.i2p.util.HexDump;
 import net.i2p.util.Log;
@@ -203,7 +205,10 @@ public class SOCKS4aServer extends SOCKSServer {
                 // Let's not due a new Dest for every request, huh?
                 //I2PSocketManager sm = I2PSocketManagerFactory.createManager();
                 //destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
-                destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName));
+                Properties overrides = new Properties();
+                I2PSocketOptions sktOpts = t.buildOptions(overrides);
+                sktOpts.setPort(connPort);
+                destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName), sktOpts);
             } else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
                 String err = "No localhost accesses allowed through the Socks Proxy";
                 _log.error(err);
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java
index 45915f6b31..0854c79935 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java
@@ -366,7 +366,10 @@ public class SOCKS5Server extends SOCKSServer {
                     } catch (IOException ioe) {}
                     throw new SOCKSException("Host not found");
                 }
-                destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName));
+                Properties overrides = new Properties();
+                I2PSocketOptions sktOpts = t.buildOptions(overrides);
+                sktOpts.setPort(connPort);
+                destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName), sktOpts);
             } else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
                 String err = "No localhost accesses allowed through the Socks Proxy";
                 _log.error(err);
-- 
GitLab