From ffda7f63269cf372c9a14f373cbdb9e88b74b28e Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 25 Jul 2013 18:49:22 +0000
Subject: [PATCH]  * Tunnels:    - Make expl. default 3 hops  (ticket #966)   
 - Allow expl. fallback up to -2 hops

---
 .../src/net/i2p/router/TunnelPoolSettings.java     |  2 +-
 .../src/net/i2p/router/tunnel/pool/TunnelPool.java | 14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/router/java/src/net/i2p/router/TunnelPoolSettings.java b/router/java/src/net/i2p/router/TunnelPoolSettings.java
index 841a22e039..d5669e4a61 100644
--- a/router/java/src/net/i2p/router/TunnelPoolSettings.java
+++ b/router/java/src/net/i2p/router/TunnelPoolSettings.java
@@ -53,7 +53,7 @@ public class TunnelPoolSettings {
     public static final int     DEFAULT_BACKUP_QUANTITY = 0;
     // public static final int     DEFAULT_REBUILD_PERIOD = 60*1000;
     public static final int     DEFAULT_DURATION = 10*60*1000;
-    public static final int     DEFAULT_LENGTH = 2;
+    public static final int     DEFAULT_LENGTH = 3;
     public static final int     DEFAULT_LENGTH_VARIANCE = 0;
     public static final boolean DEFAULT_ALLOW_ZERO_HOP = true;
     public static final int     DEFAULT_IP_RESTRICTION = 2;    // class B (/16)
diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
index 87c177d88e..aa96135fa8 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
@@ -50,7 +50,8 @@ public class TunnelPool {
     /** if less than one success in this many, reduce quantity (exploratory only) */
     private static final int BUILD_TRIES_QUANTITY_OVERRIDE = 12;
     /** if less than one success in this many, reduce length (exploratory only) */
-    private static final int BUILD_TRIES_LENGTH_OVERRIDE = 18;
+    private static final int BUILD_TRIES_LENGTH_OVERRIDE_1 = 10;
+    private static final int BUILD_TRIES_LENGTH_OVERRIDE_2 = 18;
     
     TunnelPool(RouterContext ctx, TunnelPoolManager mgr, TunnelPoolSettings settings, TunnelPeerSelector sel) {
         _context = ctx;
@@ -374,10 +375,15 @@ public class TunnelPool {
                     long rc = rr.computeAverages(ra, false).getTotalEventCount();
                     long sc = sr.computeAverages(ra, false).getTotalEventCount();
                     long tot = ec + rc + sc;
-                    if (tot >= BUILD_TRIES_LENGTH_OVERRIDE) {
-                        if (1000 * sc / tot <=  1000 / BUILD_TRIES_LENGTH_OVERRIDE)
-                            _settings.setLengthOverride(len - 1);
+                    if (tot >= BUILD_TRIES_LENGTH_OVERRIDE_1) {
+                        long succ = 1000 * sc / tot;
+                        if (succ <=  1000 / BUILD_TRIES_LENGTH_OVERRIDE_1) {
+                            if (len > 2 && succ <= 1000 / BUILD_TRIES_LENGTH_OVERRIDE_2)
+                                _settings.setLengthOverride(len - 2);
+                            else
+                                _settings.setLengthOverride(len - 1);
                             return;
+                        }
                     }
                 }
             }
-- 
GitLab