From 72be9b5f04d8cefb97ebb75eb9a447cd1dde2778 Mon Sep 17 00:00:00 2001 From: jrandom <jrandom> Date: Sat, 27 Nov 2004 21:02:06 +0000 Subject: [PATCH] 2004-11-27 jrandom * Some cleanup and bugfixes for the IP address detection code where we only consider connections that have actually sent and received messages recently as active, rather than the mere presence of a TCP socket as activity. --- .../net/i2p/client/streaming/Connection.java | 4 +-- history.txt | 8 ++++- .../src/net/i2p/router/RouterVersion.java | 4 +-- .../router/transport/tcp/MessageHandler.java | 1 + .../router/transport/tcp/TCPConnection.java | 19 ++++++++++ .../i2p/router/transport/tcp/TCPListener.java | 2 +- .../router/transport/tcp/TCPTransport.java | 36 ++++++++++++++++--- 7 files changed, 64 insertions(+), 10 deletions(-) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java index f2521d533a..e9f7086ae5 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java @@ -325,8 +325,8 @@ public class Connection { _occurredEventCount++; } else { _occurredTime = now; - if (_occurredEventCount > 5) { - _log.log(Log.CRIT, "More than 5 events (" + _occurredEventCount + ") in a second on " + if (_occurredEventCount > 10) { + _log.log(Log.CRIT, "More than 10 events (" + _occurredEventCount + ") in a second on " + toString() + ": scheduler = " + sched); } _occurredEventCount = 0; diff --git a/history.txt b/history.txt index 5950a122db..db898d0a14 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,10 @@ -$Id: history.txt,v 1.84 2004/11/26 22:54:18 jrandom Exp $ +$Id: history.txt,v 1.85 2004/11/27 00:17:06 jrandom Exp $ + +2004-11-27 jrandom + * Some cleanup and bugfixes for the IP address detection code where we + only consider connections that have actually sent and received messages + recently as active, rather than the mere presence of a TCP socket as + activity. 2004-11-27 jrandom * Removed the I2PTunnel inactivity timeout thread, since the new streaming diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index d8431e8134..1c2b1dc3e0 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.89 $ $Date: 2004/11/26 22:54:17 $"; + public final static String ID = "$Revision: 1.90 $ $Date: 2004/11/27 00:17:06 $"; public final static String VERSION = "0.4.2"; - public final static long BUILD = 2; + public final static long BUILD = 3; 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/transport/tcp/MessageHandler.java b/router/java/src/net/i2p/router/transport/tcp/MessageHandler.java index e03d68707f..33ad2a1c5c 100644 --- a/router/java/src/net/i2p/router/transport/tcp/MessageHandler.java +++ b/router/java/src/net/i2p/router/transport/tcp/MessageHandler.java @@ -30,6 +30,7 @@ public class MessageHandler implements I2NPMessageReader.I2NPMessageEventListene } public void messageReceived(I2NPMessageReader reader, I2NPMessage message, long msToRead, int size) { + _con.messageReceived(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Just received message " + message.getUniqueId() + " from " + _identHash.toBase64().substring(0,6) diff --git a/router/java/src/net/i2p/router/transport/tcp/TCPConnection.java b/router/java/src/net/i2p/router/transport/tcp/TCPConnection.java index c8436cbb4f..bbcfc1fc58 100644 --- a/router/java/src/net/i2p/router/transport/tcp/TCPConnection.java +++ b/router/java/src/net/i2p/router/transport/tcp/TCPConnection.java @@ -40,6 +40,8 @@ public class TCPConnection { private RateStat _sendRate; private long _started; private boolean _closed; + private long _lastRead; + private long _lastWrite; public TCPConnection(RouterContext ctx) { _context = ctx; @@ -53,6 +55,8 @@ public class TCPConnection { _transport = null; _started = -1; _closed = false; + _lastRead = 0; + _lastWrite = 0; _runner = new ConnectionRunner(_context, this); _context.statManager().createRateStat("tcp.probabalisticDropQueueSize", "How many bytes were queued to be sent when a message as dropped probabalistically?", "TCP", new long[] { 60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l } ); _context.statManager().createRateStat("tcp.queueSize", "How many bytes were queued on a connection?", "TCP", new long[] { 60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l } ); @@ -359,6 +363,19 @@ public class TCPConnection { boolean getIsClosed() { return _closed; } RouterContext getRouterContext() { return _context; } + boolean getIsActive() { + if ( (_lastRead <= 0) || (_lastWrite <= 0) ) return false; + long recent = (_lastRead > _lastWrite ? _lastRead : _lastWrite); + long howLongAgo = _context.clock().now() - recent; + if (howLongAgo < 1*60*1000) + return true; + else + return false; + } + void messageReceived() { + _lastRead = _context.clock().now(); + } + /** * The message was sent. * @@ -370,5 +387,7 @@ public class TCPConnection { _transport.afterSend(msg, ok, true, time); if (ok) _sendRate.addData(msg.getMessageSize(), msg.getLifetime()); + if (ok) + _lastWrite = _context.clock().now(); } } diff --git a/router/java/src/net/i2p/router/transport/tcp/TCPListener.java b/router/java/src/net/i2p/router/transport/tcp/TCPListener.java index 40f6cbaf31..e45db40033 100644 --- a/router/java/src/net/i2p/router/transport/tcp/TCPListener.java +++ b/router/java/src/net/i2p/router/transport/tcp/TCPListener.java @@ -137,7 +137,7 @@ class TCPListener { public void run() { if (_log.shouldLog(Log.INFO)) - _log.info("Beginning TCP listener"); + _log.info("Beginning TCP listener on " + _myAddress); int curDelay = 0; while (_isRunning) { diff --git a/router/java/src/net/i2p/router/transport/tcp/TCPTransport.java b/router/java/src/net/i2p/router/transport/tcp/TCPTransport.java index 4a0f79dece..96822b3754 100644 --- a/router/java/src/net/i2p/router/transport/tcp/TCPTransport.java +++ b/router/java/src/net/i2p/router/transport/tcp/TCPTransport.java @@ -349,6 +349,8 @@ public class TCPTransport extends TransportImpl { if (_myAddress != null) { if (addr.getAddress().equals(_myAddress.getAddress())) { // ignore, since there is no change + if (_log.shouldLog(Log.INFO)) + _log.info("Not updating our local address, as it hasnt changed from " + address); return; } } @@ -363,6 +365,8 @@ public class TCPTransport extends TransportImpl { } else { // either we have explicitly specified our IP address, or // we are already connected to some people. + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Not allowing address update"); } } } @@ -505,11 +509,22 @@ public class TCPTransport extends TransportImpl { * */ private boolean allowAddressUpdate() { + int connectedPeers = countActivePeers(); boolean addressSpecified = (null != _context.getProperty(LISTEN_ADDRESS)); - if (addressSpecified) + if (addressSpecified) { + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Not allowing address update, sicne we have one specified (#cons=" + connectedPeers + ")"); return false; - int connectedPeers = countActivePeers(); - return (connectedPeers == 0); + } + if (connectedPeers <= 0) { + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Allowing address update, since the # of connected peers is " + connectedPeers); + return true; + } else { + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Not allowing address update, since the # of connected peers is " + connectedPeers); + return false; + } } /** @@ -544,9 +559,22 @@ public class TCPTransport extends TransportImpl { * */ public int countActivePeers() { + int numActive = 0; + int numInactive = 0; synchronized (_connectionLock) { - return _connectionsByIdent.size(); + if (_connectionsByIdent.size() <= 0) return 0; + for (Iterator iter = _connectionsByIdent.values().iterator(); iter.hasNext(); ) { + TCPConnection con = (TCPConnection)iter.next(); + if (con.getIsActive()) + numActive++; + else + numInactive++; + } } + if ( (numInactive > 0) && (_log.shouldLog(Log.DEBUG)) ) + _log.debug("Inactive peers: " + numInactive + " active: " + numActive); + + return numActive; } /** -- GitLab