From 64bcfd09ec9d195b211f735fbca8ae59d34e7405 Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Tue, 5 Oct 2004 15:38:37 +0000
Subject: [PATCH] 2004-10-05  jrandom     * Don't go into a fast busy if an
 I2PTunnel 'server' is explicitly killed       (thanks mule!)     * Handle
 some more error conditions regarding abruptly closing sockets       (thanks
 Jonva!)

---
 .../src/net/i2p/i2ptunnel/I2PTunnelServer.java    |  1 +
 history.txt                                       |  8 +++++++-
 .../src/net/i2p/data/i2np/I2NPMessageHandler.java | 15 ++++++++++++++-
 router/java/src/net/i2p/router/RouterVersion.java |  4 ++--
 router/java/src/net/i2p/router/Shitlist.java      | 15 ++++++++++-----
 .../router/transport/tcp/ConnectionBuilder.java   |  2 +-
 .../router/transport/tcp/ConnectionRunner.java    |  3 +++
 7 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java
index b669d1353c..e313199de4 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java
@@ -148,6 +148,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
             I2PServerSocket i2pss = sockMgr.getServerSocket();
             while (true) {
                 I2PSocket i2ps = i2pss.accept();
+                if (i2ps == null) throw new I2PException("I2PServerSocket closed");
                 I2PThread t = new I2PThread(new Handler(i2ps));
                 t.start();
             }
diff --git a/history.txt b/history.txt
index 3bc86964db..fad22afb02 100644
--- a/history.txt
+++ b/history.txt
@@ -1,4 +1,10 @@
-$Id: history.txt,v 1.31 2004/10/03 15:48:43 jrandom Exp $
+$Id: history.txt,v 1.32 2004/10/04 12:30:23 jrandom Exp $
+
+2004-10-05  jrandom
+    * Don't go into a fast busy if an I2PTunnel 'server' is explicitly killed
+      (thanks mule!)
+    * Handle some more error conditions regarding abruptly closing sockets 
+      (thanks Jonva!)
 
 2004-10-04  jrandom
     * Update the shitlist to reject a peer for an exponentially increasing 
diff --git a/router/java/src/net/i2p/data/i2np/I2NPMessageHandler.java b/router/java/src/net/i2p/data/i2np/I2NPMessageHandler.java
index c9ea316f87..9ad59e680d 100644
--- a/router/java/src/net/i2p/data/i2np/I2NPMessageHandler.java
+++ b/router/java/src/net/i2p/data/i2np/I2NPMessageHandler.java
@@ -43,7 +43,20 @@ public class I2NPMessageHandler {
             int type = (int)DataHelper.readLong(in, 1);
             _lastReadBegin = System.currentTimeMillis();
             I2NPMessage msg = createMessage(in, type);
-            msg.readBytes(in, type);
+            try {
+                msg.readBytes(in, type);
+            } catch (IOException ioe) {
+                throw ioe;
+            } catch (I2NPMessageException ime) {
+                throw ime;
+            } catch (DataFormatException dfe) {
+                throw dfe;
+            } catch (Exception e) {
+                if (_log.shouldLog(Log.WARN))
+                    _log.warn("Error reading the stream", e);
+                throw new IOException("Unknown error reading the " + msg.getClass().getName() 
+                                      + ": " + e.getMessage());
+            }
             _lastReadEnd = System.currentTimeMillis();
             return msg;
         } catch (DataFormatException dfe) {
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index 4babaae5af..6f7dad04ea 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
  *
  */
 public class RouterVersion {
-    public final static String ID = "$Revision: 1.41 $ $Date: 2004/10/03 15:48:43 $";
+    public final static String ID = "$Revision: 1.42 $ $Date: 2004/10/04 12:30:23 $";
     public final static String VERSION = "0.4.1.1";
-    public final static long BUILD = 7;
+    public final static long BUILD = 8;
     public static void main(String args[]) {
         System.out.println("I2P Router version: " + VERSION);
         System.out.println("Router ID: " + RouterVersion.ID);
diff --git a/router/java/src/net/i2p/router/Shitlist.java b/router/java/src/net/i2p/router/Shitlist.java
index a33bb51e73..6e695b87c4 100644
--- a/router/java/src/net/i2p/router/Shitlist.java
+++ b/router/java/src/net/i2p/router/Shitlist.java
@@ -88,15 +88,20 @@ public class Shitlist {
     }
     
     public void unshitlistRouter(Hash peer) {
+        unshitlistRouter(peer, true);
+    }
+    private void unshitlistRouter(Hash peer, boolean realUnshitlist) {
         if (peer == null) return;
         _log.info("Unshitlisting router " + peer.toBase64());
         synchronized (_shitlist) {
             _shitlist.remove(peer);
             _shitlistCause.remove(peer);
         }
-        PeerProfile prof = _context.profileOrganizer().getProfile(peer);
-        if (prof != null)
-            prof.unshitlist();
+        if (realUnshitlist) {
+            PeerProfile prof = _context.profileOrganizer().getProfile(peer);
+            if (prof != null)
+                prof.unshitlist();
+        }
     }
     
     public boolean isShitlisted(Hash peer) {
@@ -110,7 +115,7 @@ public class Shitlist {
         if (shitlistDate.getTime() > _context.clock().now()) {
             return true;
         } else {
-            unshitlistRouter(peer);
+            unshitlistRouter(peer, false);
             return false;
         }
     }
@@ -133,7 +138,7 @@ public class Shitlist {
             Hash key = (Hash)iter.next();
             Date shitDate = (Date)shitlist.get(key);
             if (shitDate.getTime() < limit) {
-                unshitlistRouter(key);
+                unshitlistRouter(key, false);
             }
         }
     }
diff --git a/router/java/src/net/i2p/router/transport/tcp/ConnectionBuilder.java b/router/java/src/net/i2p/router/transport/tcp/ConnectionBuilder.java
index e483fa825d..a5addc8119 100644
--- a/router/java/src/net/i2p/router/transport/tcp/ConnectionBuilder.java
+++ b/router/java/src/net/i2p/router/transport/tcp/ConnectionBuilder.java
@@ -104,7 +104,7 @@ public class ConnectionBuilder {
         try {
             return doEstablishConnection();
         } catch (Exception e) { // catchall in case the timeout gets us flat footed
-            _log.error("Error connecting", e);
+            fail("Error connecting", e);
             return null;
         }
     }
diff --git a/router/java/src/net/i2p/router/transport/tcp/ConnectionRunner.java b/router/java/src/net/i2p/router/transport/tcp/ConnectionRunner.java
index 500e335312..606dfac97b 100644
--- a/router/java/src/net/i2p/router/transport/tcp/ConnectionRunner.java
+++ b/router/java/src/net/i2p/router/transport/tcp/ConnectionRunner.java
@@ -47,6 +47,8 @@ class ConnectionRunner implements Runnable {
             if (msg == null) {
                 if (_keepRunning)
                     _log.error("next message is null but we should keep running?");
+                _con.closeConnection();
+                return;
             } else {
                 sendMessage(msg);
             }
@@ -88,6 +90,7 @@ class ConnectionRunner implements Runnable {
         } catch (IOException ioe) {
             if (_log.shouldLog(Log.WARN))
                 _log.warn("Error writing out the message", ioe);
+            _con.closeConnection();
         }
         _con.sent(msg, ok, after - before);
     }
-- 
GitLab