From c546b283fd6ca1b54bfcb14fe039f0f221b56e6d Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 13 Jan 2016 16:01:13 +0000
Subject: [PATCH] BuildHandler: More early-disconnect cases

---
 .../net/i2p/router/tunnel/pool/BuildHandler.java    | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java
index 2f4ebffb9c..f36f449b74 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java
@@ -451,6 +451,10 @@ class BuildHandler implements Runnable {
         if (_log.shouldLog(Log.DEBUG))
             _log.debug(state.msg.getUniqueId() + ": handling request after " + timeSinceReceived);
         
+        Hash from = state.fromHash;
+        if (from == null && state.from != null)
+            from = state.from.calculateHash();
+
         if (timeSinceReceived > (BuildRequestor.REQUEST_TIMEOUT*3)) {
             // don't even bother, since we are so overloaded locally
             _context.throttle().setTunnelStatus(_x("Dropping tunnel requests: Overloaded"));
@@ -458,6 +462,8 @@ class BuildHandler implements Runnable {
                 _log.warn("Not even trying to handle/decrypt the request " + state.msg.getUniqueId() 
                            + ", since we received it a long time ago: " + timeSinceReceived);
             _context.statManager().addRateData("tunnel.dropLoadDelay", timeSinceReceived);
+            if (from != null)
+                _context.commSystem().mayDisconnect(from);
             return -1;
         }
         // ok, this is not our own tunnel, so we need to do some heavy lifting
@@ -472,12 +478,11 @@ class BuildHandler implements Runnable {
         if (req == null) {
             // no records matched, or the decryption failed.  bah
             if (_log.shouldLog(Log.WARN)) {
-                Hash from = state.fromHash;
-                if (from == null && state.from != null)
-                    from = state.from.calculateHash();
                 _log.warn("The request " + state.msg.getUniqueId() + " could not be decrypted from: " + from);
             }
             _context.statManager().addRateData("tunnel.dropDecryptFail", 1);
+            if (from != null)
+                _context.commSystem().mayDisconnect(from);
             return -1;
         }
 
@@ -506,6 +511,8 @@ class BuildHandler implements Runnable {
                     _log.warn("Drop next hop lookup, limit " + limit);
                 _context.statManager().addRateData("tunnel.dropLookupThrottle", 1);
             }
+            if (from != null)
+                _context.commSystem().mayDisconnect(from);
             return -1;
         } else {
             long beforeHandle = System.currentTimeMillis();
-- 
GitLab