From 43c18d0f4d18a5bc988f1bb4e22ecccf46bc019a Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Sun, 25 Jul 2004 23:43:13 +0000
Subject: [PATCH] (techincally) reduced the minimum bandwidth rate to 1KBps,
 but NO ONE SHOULD SET IT THAT LOW.  do not reduce your limits below 6KBps
 until More Stuff Gets Done. logging

---
 .../BandwidthLimitedOutputStream.java         |  5 ++
 .../transport/FIFOBandwidthLimiter.java       | 53 ++++++++++++++++---
 .../transport/FIFOBandwidthRefiller.java      | 10 ++--
 .../i2p/router/transport/TransportImpl.java   |  8 ++-
 4 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/router/java/src/net/i2p/router/transport/BandwidthLimitedOutputStream.java b/router/java/src/net/i2p/router/transport/BandwidthLimitedOutputStream.java
index 504ef1c121..1f59a62574 100644
--- a/router/java/src/net/i2p/router/transport/BandwidthLimitedOutputStream.java
+++ b/router/java/src/net/i2p/router/transport/BandwidthLimitedOutputStream.java
@@ -38,9 +38,13 @@ public class BandwidthLimitedOutputStream extends FilterOutputStream {
     public void write(int val) throws IOException {
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("Writing a single byte!", new Exception("Single byte from..."));
+        long before = _context.clock().now();
         FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestOutbound(1, _peerTarget);
         // only a single byte, no need to loop
         req.waitForNextAllocation();
+        long waited = _context.clock().now() - before;
+        if ( (waited > 1000) && (_log.shouldLog(Log.WARN)) )
+            _log.warn("Waiting to write a byte took too long [" + waited + "ms");
         out.write(val);
     }
     public void write(byte src[]) throws IOException {
@@ -65,6 +69,7 @@ public class BandwidthLimitedOutputStream extends FilterOutputStream {
                     out.write(src, off + written, toWrite);
                 } catch (IOException ioe) {
                     _currentRequest.abort();
+                    _currentRequest = null;
                     throw ioe;
                 }
                 written += toWrite;
diff --git a/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java b/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java
index 9d3e6a5463..7a4e13cfe3 100644
--- a/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java
+++ b/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java
@@ -138,7 +138,9 @@ public class FIFOBandwidthLimiter {
                     if (_log.shouldLog(Log.WARN))
                         _log.warn("Still denying the " + _pendingInboundRequests.size() 
                                   + " pending inbound requests (available "
-                                  + _availableInboundBytes + "/" + _availableOutboundBytes + " in/out)");
+                                  + _availableInboundBytes + "/" + _availableOutboundBytes 
+                                  + " in/out, longest waited " + locked_getLongestInboundWait()
+                                  + "/" + locked_getLongestOutboundWait() + " in/out)");
                 }
             }
         }
@@ -151,6 +153,31 @@ public class FIFOBandwidthLimiter {
         }
     }
     
+    private long locked_getLongestInboundWait() {
+        long start = -1;
+        for (int i = 0; i < _pendingInboundRequests.size(); i++) {
+            SimpleRequest req = (SimpleRequest)_pendingInboundRequests.get(i);
+            if ( (start < 0) || (start > req.getRequestTime()) )
+                start = req.getRequestTime();
+        }
+        if (start == -1) 
+            return 0;
+        else
+            return _context.clock().now() - start;
+    }
+    private long locked_getLongestOutboundWait() {
+        long start = -1;
+        for (int i = 0; i < _pendingOutboundRequests.size(); i++) {
+            SimpleRequest req = (SimpleRequest)_pendingOutboundRequests.get(i);
+            if ( (start < 0) || (start > req.getRequestTime()) )
+                start = req.getRequestTime();
+        }
+        if (start == -1)
+            return 0;
+        else
+            return _context.clock().now() - start;
+    }
+    
     /**
      * There are no limits, so just give every inbound request whatever they want
      *
@@ -229,14 +256,18 @@ public class FIFOBandwidthLimiter {
                                 + req.getRequestName() + " (wanted " 
                                 + req.getTotalInboundRequested() + " bytes, waited " 
                                 + waited
-                                + "ms) pending " + _pendingInboundRequests.size());
+                                + "ms) pending " + _pendingInboundRequests.size()
+                                + ", longest waited " + locked_getLongestInboundWait() 
+                                + "/" + locked_getLongestOutboundWait() + " in/out");
             } else {
                 if (_log.shouldLog(Log.INFO))
                      _log.info("Allocating " + allocated + " bytes inbound to finish the partial grant to " 
                                 + req.getRequestName() + " (total " 
                                 + req.getTotalInboundRequested() + " bytes, waited " 
                                 + waited
-                                + "ms) pending " + _pendingInboundRequests.size());
+                                + "ms) pending " + _pendingInboundRequests.size()
+                                + ", longest waited " + locked_getLongestInboundWait() 
+                                + "/" + locked_getLongestOutboundWait() + " in/out");
                 _pendingInboundRequests.remove(i);
                 i--;
                 if (waited > 10)
@@ -259,7 +290,9 @@ public class FIFOBandwidthLimiter {
                     if (_log.shouldLog(Log.WARN))
                         _log.warn("Still denying the " + _pendingOutboundRequests.size() 
                                   + " pending outbound requests (available "
-                                  + _availableInboundBytes + "/" + _availableOutboundBytes + " in/out)");
+                                  + _availableInboundBytes + "/" + _availableOutboundBytes + " in/out, "
+                                  + "longest waited " + locked_getLongestInboundWait() 
+                                  + "/" + locked_getLongestOutboundWait() + " in/out)");
                 }
             }
         }
@@ -292,7 +325,9 @@ public class FIFOBandwidthLimiter {
                  _log.info("Granting outbound request " + req.getRequestName() + " fully for " 
                             + req.getTotalOutboundRequested() + " bytes (waited " 
                             + waited
-                            + "ms) pending " + _pendingOutboundRequests.size());
+                            + "ms) pending " + _pendingOutboundRequests.size()
+                            + ", longest waited " + locked_getLongestInboundWait() 
+                             + "/" + locked_getLongestOutboundWait() + " in/out");
             if (waited > 10)
                 _context.statManager().addRateData("bwLimiter.outboundDelayedTime", waited, waited);
         }
@@ -350,14 +385,18 @@ public class FIFOBandwidthLimiter {
                                 + req.getRequestName() + " (wanted " 
                                 + req.getTotalOutboundRequested() + " bytes, waited " 
                                 + waited
-                                + "ms) pending " + _pendingOutboundRequests.size());
+                                + "ms) pending " + _pendingOutboundRequests.size()
+                                + ", longest waited " + locked_getLongestInboundWait() 
+                                + "/" + locked_getLongestOutboundWait() + " in/out");
             } else {
                 if (_log.shouldLog(Log.INFO))
                      _log.info("Allocating " + allocated + " bytes outbound to finish the partial grant to " 
                                 + req.getRequestName() + " (total " 
                                 + req.getTotalOutboundRequested() + " bytes, waited " 
                                 + waited
-                                + "ms) pending " + _pendingOutboundRequests.size());
+                                + "ms) pending " + _pendingOutboundRequests.size()
+                                + ", longest waited " + locked_getLongestInboundWait() 
+                                + "/" + locked_getLongestOutboundWait() + " in/out)");
                 _pendingOutboundRequests.remove(i);
                 i--;
                 if (waited > 10)
diff --git a/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java b/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java
index adcf6a14f6..a04cea0743 100644
--- a/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java
+++ b/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java
@@ -27,13 +27,13 @@ class FIFOBandwidthRefiller implements Runnable {
     public static final String PROP_REPLENISH_FREQUENCY = "i2np.bandwidth.replenishFrequencyMs";
  
     /** For now, until there is some tuning and safe throttling, we set the floor at 6KBps inbound */
-    public static final int MIN_INBOUND_BANDWIDTH = 6;
+    public static final int MIN_INBOUND_BANDWIDTH = 1;
     /** For now, until there is some tuning and safe throttling, we set the floor at 6KBps outbound */
-    public static final int MIN_OUTBOUND_BANDWIDTH = 6;
+    public static final int MIN_OUTBOUND_BANDWIDTH = 1;
     /** For now, until there is some tuning and safe throttling, we set the floor at a 10 second burst */
-    public static final int MIN_INBOUND_BANDWIDTH_PEAK = 6;
+    public static final int MIN_INBOUND_BANDWIDTH_PEAK = 1;
     /** For now, until there is some tuning and safe throttling, we set the floor at a 10 second burst */
-    public static final int MIN_OUTBOUND_BANDWIDTH_PEAK = 6;
+    public static final int MIN_OUTBOUND_BANDWIDTH_PEAK = 1;
     /** Updating the bandwidth more than once a second is silly.  once every 2 or 5 seconds is less so. */
     public static final long MIN_REPLENISH_FREQUENCY = 1000;
     
@@ -107,6 +107,8 @@ class FIFOBandwidthRefiller implements Runnable {
             }
             return true;
         } else {
+            if (_log.shouldLog(Log.WARN))
+                _log.warn("Refresh delay too fast (" + numMs + ")");
             return false;
         }
     }
diff --git a/router/java/src/net/i2p/router/transport/TransportImpl.java b/router/java/src/net/i2p/router/transport/TransportImpl.java
index 2a282861b5..c493bfab31 100644
--- a/router/java/src/net/i2p/router/transport/TransportImpl.java
+++ b/router/java/src/net/i2p/router/transport/TransportImpl.java
@@ -75,10 +75,14 @@ public abstract class TransportImpl implements Transport {
         long lifetime = msg.getLifetime();
         if (lifetime > 5000) {
             if (_log.shouldLog(Log.WARN))
-                _log.warn("afterSend: [success=" + sendSuccessful + "]\n" + msg.toString());
+                _log.warn("afterSend: [success=" + sendSuccessful + "]" + msg.getMessageSize() + "byte " 
+                          + msg.getMessageType() + " from " + _context.routerHash().toBase64().substring(0,6) 
+                          + " to " + msg.getTarget().getIdentity().calculateHash().toBase64().substring(0,6) + "\n" + msg.toString());
         } else {
             if (_log.shouldLog(Log.INFO))
-                _log.info("afterSend: [success=" + sendSuccessful + "]\n" + msg.toString());
+                _log.info("afterSend: [success=" + sendSuccessful + "]" + msg.getMessageSize() + "byte " 
+                          + msg.getMessageType() + " from " + _context.routerHash().toBase64().substring(0,6) 
+                          + " to " + msg.getTarget().getIdentity().calculateHash().toBase64().substring(0,6) + "\n" + msg.toString());
         }
 
         if (sendSuccessful) {
-- 
GitLab