Opened 2 years ago

Closed 2 years ago

#1875 closed defect (fixed)

Fix Long-Standing Regression for Running Local Test Networks

Reported by: Obscuratus Owned by: zzz
Priority: minor Milestone: 0.9.28
Component: router/transport Version: 0.9.27
Keywords: Cc:
Parent Tickets:

Description

I2P has infrastructure to allow running in a sand-boxed local network for testing purposes, but this functionality has regressed for several years.

I am including two patches I have used to build my own sand-boxed local testing network.

The patches are broken into two parts to facilitate review.

The first patch is primarily refactoring the allowLocal configuration parameter. I2P currently has two (currently broken) configuration settings for allowLocal, one for the UDP transport, and one for the NTCP transport.

I can't figure out the use-case for having UDP running local, and NTCP being public (or visa-versa), but combining the two to a single allowLocal configuration setting simplifies things, supports a more simple solution to fixing the issue.

i2p/transport: Make allowLocal a transport-level parameter

I2P currently provides UDP and NTCP configuration parameters for
allowing local connections (for testing purposes).

There's not really a use-case for only setting allowLocal in
only UDP or NTCP, and not the other transport.

Add a transport level configuration parameter: i2np.allowLocal

NOTE: This change is mostly re-factoring and cleaning up of allowLocal.

A further change is still necessary to make allowLocal fully functional.

Signed-off-by: obscuratus <obscuratus@mail.i2p>
---

diff --git a/router/java/src/net/i2p/router/MultiRouter.java b/router/java/src/net/i2p/router/MultiRouter.java
index abcd32e..8e663f8 100644
--- a/router/java/src/net/i2p/router/MultiRouter.java
+++ b/router/java/src/net/i2p/router/MultiRouter.java
@@ -193,8 +193,7 @@ public class MultiRouter {
         props.setProperty("i2np.udp.host", "127.0.0.1");
         props.setProperty("i2np.ntcp.port", BASE_PORT + id + "");
         props.setProperty("i2np.udp.port", BASE_PORT + id + "");
-        props.setProperty("i2np.ntcp.allowLocal", "true");
-        props.setProperty("i2np.udp.allowLocal", "true");
+        props.setProperty("i2np.allowLocal", "true");
         props.setProperty("i2np.udp.internalPort", BASE_PORT + id + "");
         props.setProperty("i2cp.port", Integer.toString((BASE_PORT + nbrRouters + id)));   
 
diff --git a/router/java/src/net/i2p/router/transport/TransportImpl.java b/router/java/src/net/i2p/router/transport/TransportImpl.java
index d3f3a8d..cb3609a 100644
--- a/router/java/src/net/i2p/router/transport/TransportImpl.java
+++ b/router/java/src/net/i2p/router/transport/TransportImpl.java
@@ -944,6 +944,18 @@ public abstract class TransportImpl implements Transport {
     }
 
     /**
+     * Are we allowed to connect to local addresses?
+     *
+     * @since 0.9.28
+     *  adapted from previous implementation in UDPTransport.java @since IPv6
+     */
+    public boolean allowLocal() {
+        boolean rv;
+        rv = (_context.getBooleanProperty("i2np.allowLocal"));
+        return rv;
+    }
+
+    /**
      * IP of the peer from the last connection (in or out, any transport).
      *
      * @param ip IPv4 or IPv6, non-null
diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
index d371a93..13cba50 100644
--- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
+++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
@@ -436,7 +436,7 @@ public class NTCPTransport extends TransportImpl {
                 continue;
             }
             if (!isValid(ip)) {
-                if (! _context.getBooleanProperty("i2np.ntcp.allowLocal")) {
+                if (! allowLocal()) {
                     //_context.statManager().addRateData("ntcp.bidRejectedLocalAddress", 1);
                     //if (_log.shouldLog(Log.DEBUG))
                     //    _log.debug("no bid when trying to send to " + peer + " as they have a private ntcp address");
diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
index 162e64a..1595f2d 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
@@ -1093,16 +1093,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
             return true;
         return allowLocal();
     }
-    
-    /**
-     * Are we allowed to connect to local addresses?
-     *
-     * @since IPv6
-     */
-    boolean allowLocal() {
-        return _context.getBooleanProperty("i2np.udp.allowLocal");
-    }
-    
+
     /**
      *  Was true before 0.9.2
      *  Now false if we need introducers (as perhaps that's why we need them,
diff --git a/router/java/test/junit/net/i2p/router/SSUDemo.java b/router/java/test/junit/net/i2p/router/SSUDemo.java
index 5ae9ba1..2c94f9b 100644
--- a/router/java/test/junit/net/i2p/router/SSUDemo.java
+++ b/router/java/test/junit/net/i2p/router/SSUDemo.java
@@ -64,8 +64,7 @@ public class SSUDemo {
         envProps.setProperty("time.disabled", "false");
         // allow 127.0.0.1/10.0.0.1/etc (useful for testing).  If this is false,
         // peers who say they're on an invalid IP are banlisted
-        envProps.setProperty("i2np.udp.allowLocal", "true");
-        envProps.setProperty("i2np.ntcp.allowLocal", "true");
+        envProps.setProperty("i2np.allowLocal", "true");
         // IPv6
         envProps.setProperty("i2np.udp.ipv6", "enable");
         envProps.setProperty("i2np.ntcp.ipv6", "enable");

As noted in the patch, I haven't actually fixed anything yet. But with the above refactoring, UDP and NTCP (and any other aspect of I2P that is checking for public routability, such as uPNP) are all working with the same configuration parameter, which allows us to by-pass the test for being publicly routable in a more simple manner.

i2p/router: Return true from isPubliclyRoutable if allowLocal is true.

This change will facilitate the setup of test networks running on
local addresses that are not necessarily publically routable.

Signed-off-by: obscuratus <obscuratus@mail.i2p>
---

diff --git a/router/java/src/net/i2p/router/transport/TransportUtil.java b/router/java/src/net/i2p/router/transport/TransportUtil.java
index de8dc0f..16ede3b 100644
--- a/router/java/src/net/i2p/router/transport/TransportUtil.java
+++ b/router/java/src/net/i2p/router/transport/TransportUtil.java
@@ -13,6 +13,7 @@ import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Map;
 
+import net.i2p.I2PAppContext;
 import net.i2p.data.router.RouterAddress;
 import net.i2p.router.RouterContext;
 
@@ -131,6 +132,8 @@ public abstract class TransportUtil {
      *  @since IPv6
      */
     public static boolean isPubliclyRoutable(byte addr[], boolean allowIPv4, boolean allowIPv6) {
+        if (I2PAppContext.getGlobalContext().getBooleanProperty("i2np.allowLocal"))
+            return true;
         if (addr.length == 4) {
             if (!allowIPv4)
                 return false;

Subtickets

Change History (1)

comment:1 Changed 2 years ago by zzz

  • Milestone changed from undecided to 0.9.28
  • Resolution set to fixed
  • Status changed from new to closed
  • Version changed from 0.9.28 to 0.9.27

In 5459f44c248b7d1c497b9de4fbc882b934edcd08 0.9.27-7
thank you

Note: See TracTickets for help on using tickets.