From 2eb154c24cc61ca3ef2b1fc97220cf8237139ea2 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 10 Oct 2008 17:26:44 +0000
Subject: [PATCH]     * Tunnel Tests: Add time for outbound delay, to avoid    
   congestion collapse

---
 router/java/src/net/i2p/router/tunnel/pool/TestJob.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/router/java/src/net/i2p/router/tunnel/pool/TestJob.java b/router/java/src/net/i2p/router/tunnel/pool/TestJob.java
index 8b2332f37a..b81178bdf7 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/TestJob.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/TestJob.java
@@ -212,7 +212,11 @@ class TestJob extends JobImpl {
         // Minimum is 7.5s (since a 0-hop could be the expl. tunnel, but only >= 1-hop client tunnels are tested)
         // Network average for success is about 1.5s.
         // Another possibility - make configurable via pool options
-        return 2500 * (_outTunnel.getLength() + _replyTunnel.getLength());
+        //
+        // Try to prevent congestion collapse (failing all our tunnels and then clogging our outbound
+        // with new tunnel build requests) by adding in three times the average outbound delay.
+        int delay = 3 * (int) getContext().statManager().getRate("transport.sendProcessingTime").getRate(60*1000).getAverageValue();
+        return delay + (2500 * (_outTunnel.getLength() + _replyTunnel.getLength()));
     }
 
     private void scheduleRetest() { scheduleRetest(false); }
-- 
GitLab