Opened 2 years ago

Closed 2 years ago

#1876 closed defect (fixed)

i2p/router: Make Minimum Peer Setting Configurable

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

Description

The trac ticket is primarily to support a small-ish number of routers running on a local test-network.

I2P has been hard-coded to try to establish a minimum of 30 IPv6 peers when IPv6 is enabled.

On small-ish I2P test networks, where 30 IPv6 peers may not be available, I2P exhibits strange behavior when it can't find 30 IPv6 peers. The 'Message delay' measurement increases to 2-3 seconds (no idea why this is happening, especially on a single computer with virtually no physical delay). This causes the peer to reject tunnels due to high message delay.

Another problem that arises is when an I2P router saturates the available IPv6 peers by connecting to all of them, you can't test IPv6 peer testing because there is no Charlie available that you aren't already connect with.

In order to make my test network work in a normal manner, I found I needed to decrease the minimum number of IPv6 peers.

i2p/router: Make Minimum Peer Setting Configurable

To support the implementation of small I2P testing networks,
allow the minimum peers settings to be configurable.

The default values are fine for normal peers, but these values
may be too high for small local test networks.

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

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 1595f2d..24dfee1 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
@@ -97,7 +97,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
      */
     private volatile boolean _haveIPv6Address;
     private long _lastInboundIPv6;
-    
+
+    private int _min_peers;
+    private int _min_v6_peers;
+
     /** do we need to rebuild our external router address asap? */
     private boolean _needsRebuild;
     private final Object _rebuildLock = new Object();
@@ -213,6 +216,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
     //private static final String THINSP = "&thinsp;/&thinsp;";
     private static final String THINSP = " / ";
 
+    /** minimum active peers to maintain IP detection, etc. */
+    private static final int MIN_PEERS = 5;
+    private static final int MIN_PEERS_IF_HAVE_V6 = 30;
+
     /**
      *  RI sigtypes supported in 0.9.16, but due to a bug in InboundEstablishState
      *  fixed in 0.9.17, we cannot connect out to routers before that version.
@@ -267,6 +274,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
         _mtu_ipv6 = PeerState.MIN_IPV6_MTU;
         setupPort();
         _needsRebuild = true;
+        _min_peers = getInt("i2np.udp.minpeers", MIN_PEERS);
+        _min_v6_peers = getInt("i2np.udp.minv6peers", MIN_PEERS_IF_HAVE_V6);
         
         _context.statManager().createRateStat("udp.alreadyConnected", "What is the lifetime of a reestablished session", "udp", RATES);
         _context.statManager().createRateStat("udp.droppedPeer", "How long ago did we receive from a dropped peer (duration == session lifetime", "udp", RATES);
@@ -1695,9 +1706,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
         }
     }
 
-    /** minimum active peers to maintain IP detection, etc. */
-    private static final int MIN_PEERS = 5;
-    private static final int MIN_PEERS_IF_HAVE_V6 = 30;
     /** minimum peers volunteering to be introducers if we need that */
     private static final int MIN_INTRODUCER_POOL = 5;
 
@@ -1762,8 +1770,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
             // (Otherwise we only talk UDP to those that are firewalled, and we will
             // never get any introducers)
             int count = _peersByIdent.size();
-            if (alwaysPreferUDP() || count < MIN_PEERS ||
-                (_haveIPv6Address && count < MIN_PEERS_IF_HAVE_V6) ||
+            if (alwaysPreferUDP() || count < _min_peers ||
+                (_haveIPv6Address && count < _min_v6_peers) ||
                 (introducersRequired() && _introManager.introducerCount() < MIN_INTRODUCER_POOL))
                 return _cachedBid[SLOW_PREFERRED_BID];
             else if (preferUDP())
@@ -3396,6 +3404,17 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
         }
     }
 
+    private int getInt(String prop, int defaultVal) {
+        String p = _context.getProperty(prop);
+        try {
+            if ( (p != null) && (p.trim().length() > 0) )
+                return  Integer.parseInt(p.trim());
+        } catch (NumberFormatException nfe) {
+            // ignore
+        }
+        return defaultVal;
+    }
+
 /*******
     private static final String BADIPS[] = new String[] { "192.168.0.1", "127.0.0.1", "10.3.4.5", "172.16.3.4", "224.5.6.7" };
     private static final String GOODIPS[] = new String[] { "192.167.0.1", "126.0.0.1", "11.3.4.5", "172.15.3.4", "223.5.6.7" };

Subtickets

Change History (2)

comment:1 Changed 2 years ago by Obscuratus

  • Component changed from unspecified to router/transport
  • Owner set to zzz

comment:2 Changed 2 years ago by zzz

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

In dcfc1c9bbcc91ba84722c111d7069815bc7ef2f8 0.9.27-7
I cleaned it up a little
thank you

Note: See TracTickets for help on using tickets.