diff --git a/router/java/src/net/i2p/router/CommSystemFacade.java b/router/java/src/net/i2p/router/CommSystemFacade.java index fa970fc27b8f9e914b16a127d78dcb2a213d343e..f34bbb803ddf06700448af1d8fbdf50cf3e8dd1d 100644 --- a/router/java/src/net/i2p/router/CommSystemFacade.java +++ b/router/java/src/net/i2p/router/CommSystemFacade.java @@ -32,8 +32,19 @@ public abstract class CommSystemFacade implements Service { /** Create the list of RouterAddress structures based on the router's config */ public List<RouterAddress> createAddresses() { return Collections.emptyList(); } + /** + * How many peers are we currently connected to, that we have + * sent a message to or received a message from in the last five minutes. + */ public int countActivePeers() { return 0; } + + /** + * How many peers are we currently connected to, that we have + * sent a message to in the last minute. + * Unused for anything, to be removed. + */ public int countActiveSendPeers() { return 0; } + public boolean haveInboundCapacity(int pct) { return true; } public boolean haveOutboundCapacity(int pct) { return true; } public boolean haveHighOutboundCapacity() { return true; } diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index 3ac79186658d6868463882cf0a45312124ed5a78..59091a6d8aecef50ed1f5402bb5235f671663145 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -79,10 +79,21 @@ public class CommSystemFacadeImpl extends CommSystemFacade { _manager.restart(); } + /** + * How many peers are we currently connected to, that we have + * sent a message to or received a message from in the last five minutes. + */ @Override public int countActivePeers() { return _manager.countActivePeers(); } + + /** + * How many peers are we currently connected to, that we have + * sent a message to in the last minute. + * Unused for anything, to be removed. + */ @Override public int countActiveSendPeers() { return _manager.countActiveSendPeers(); } + @Override public boolean haveInboundCapacity(int pct) { return _manager.haveInboundCapacity(pct); } @Override diff --git a/router/java/src/net/i2p/router/transport/TransportImpl.java b/router/java/src/net/i2p/router/transport/TransportImpl.java index 92b9a61d995c86ea0e517ad1e2658577d876e6b6..9454027d61fcba3cff7573375878a1a4444356c8 100644 --- a/router/java/src/net/i2p/router/transport/TransportImpl.java +++ b/router/java/src/net/i2p/router/transport/TransportImpl.java @@ -113,14 +113,17 @@ public abstract class TransportImpl implements Transport { public int countPeers() { return countActivePeers(); } /** - * How many peers active in the last few minutes? + * How many peers are we currently connected to, that we have + * sent a message to or received a message from in the last five minutes. */ - public int countActivePeers() { return 0; } + public abstract int countActivePeers(); /** - * How many peers are we actively sending messages to (this minute) + * How many peers are we currently connected to, that we have + * sent a message to in the last minute. + * Unused for anything, to be removed. */ - public int countActiveSendPeers() { return 0; } + public abstract int countActiveSendPeers(); /** ...and 50/100/150/200/250 for BW Tiers K/L/M/N/O */ private static final int MAX_CONNECTION_FACTOR = 50; @@ -158,10 +161,13 @@ public abstract class TransportImpl implements Transport { def *= 4; break; case Router.CAPABILITY_BW256: - // TODO + def *= 6; + break; case Router.CAPABILITY_BW512: + def *= 8; + break; case Router.CAPABILITY_BW_UNLIMITED: - def *= 7; + def *= 12; break; } } diff --git a/router/java/src/net/i2p/router/transport/TransportManager.java b/router/java/src/net/i2p/router/transport/TransportManager.java index 188d5fb4d2832b5beb589d33a738bafe31cdf9c0..609bd7dc80728f6a3abca41df732d40b405b1185 100644 --- a/router/java/src/net/i2p/router/transport/TransportManager.java +++ b/router/java/src/net/i2p/router/transport/TransportManager.java @@ -286,6 +286,10 @@ public class TransportManager implements TransportEventListener { int getTransportCount() { return _transports.size(); } + /** + * How many peers are we currently connected to, that we have + * sent a message to or received a message from in the last five minutes. + */ public int countActivePeers() { int peers = 0; for (Transport t : _transports.values()) { @@ -294,6 +298,11 @@ public class TransportManager implements TransportEventListener { return peers; } + /** + * How many peers are we currently connected to, that we have + * sent a message to in the last minute. + * Unused for anything, to be removed. + */ public int countActiveSendPeers() { int peers = 0; for (Transport t : _transports.values()) { diff --git a/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java b/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java index e53d9666699a45c261592a6c9d027c529224a12a..c3660f50c5bc1c6242f0bd32406f802ba22ee4db 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java +++ b/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java @@ -1090,7 +1090,7 @@ class EstablishState { log.warn("prepareOutbound() on verified state, doing nothing!"); } - @Override public String toString() { return "VerifiedEstablishState";} + @Override public String toString() { return "VerifiedEstablishState: ";} } /** @@ -1108,7 +1108,7 @@ class EstablishState { log.warn("prepareOutbound() on verified state, doing nothing!"); } - @Override public String toString() { return "FailedEstablishState";} + @Override public String toString() { return "FailedEstablishState: ";} } /** @deprecated unused */ diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java index 01ef417a060728c30b93820d73de5a1b4f8df81d..be60f09e192740e1c1e198ce7a025d511a167cf8 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java @@ -493,21 +493,33 @@ public class NTCPTransport extends TransportImpl { } /** - * How many peers can we talk to right now? - * + * How many peers have we talked to in the last 5 minutes? + * As of 0.9.20, actually returns active peer count, not total. */ - @Override - public int countActivePeers() { return _conByIdent.size(); } + public int countActivePeers() { + int active = 0; + for (NTCPConnection con : _conByIdent.values()) { + // con initializes times at construction, + // so check message count also + if ((con.getMessagesSent() > 0 && con.getTimeSinceSend() <= 5*60*1000) || + (con.getMessagesReceived() > 0 && con.getTimeSinceReceive() <= 5*60*1000)) { + active++; + } + } + return active; + } /** * How many peers are we actively sending messages to (this minute) */ - @Override public int countActiveSendPeers() { int active = 0; for (NTCPConnection con : _conByIdent.values()) { - if ( (con.getTimeSinceSend() <= 60*1000) || (con.getTimeSinceReceive() <= 60*1000) ) - active++; + // con initializes times at construction, + // so check message count also + if (con.getMessagesSent() > 0 && con.getTimeSinceSend() <= 60*1000) { + active++; + } } return active; } diff --git a/router/java/src/net/i2p/router/transport/udp/UDPPacket.java b/router/java/src/net/i2p/router/transport/udp/UDPPacket.java index 7b9c2bdd00159c7d5a87aa1bc3b161a434eb2760..2f8cf4ea31f7fe94a1c04a0fd902e43670221ec3 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPPacket.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPPacket.java @@ -240,8 +240,10 @@ class UDPPacket implements CDQEntry { } } } else { - //if (_log.shouldLog(Log.WARN)) - // _log.warn("Payload length is " + payloadLength); + Log log = _context.logManager().getLog(UDPPacket.class); + if (log.shouldLog(Log.WARN)) + log.warn("Payload length is " + payloadLength + ", too short!\n" + + net.i2p.util.HexDump.dump(_data, _packet.getOffset(), _packet.getLength())); } //_afterValidate = _context.clock().now(); diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index 6a53d8551c623f8d213e8725f32d0f6b4c890d70..ff151a6e131dc6cffc6514e9395fec239cf8175e 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -2244,23 +2244,25 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority return _peersByIdent.size(); } - @Override public int countActivePeers() { - long now = _context.clock().now(); + long old = _context.clock().now() - 5*60*1000; int active = 0; for (PeerState peer : _peersByIdent.values()) { - if (now-peer.getLastReceiveTime() <= 5*60*1000) - active++; + // PeerState initializes times at construction, + // so check message count also + if ((peer.getMessagesReceived() > 0 && peer.getLastReceiveTime() >= old) || + (peer.getMessagesSent() > 0 && peer.getLastSendTime() >= old)) { + active++; } + } return active; } - @Override public int countActiveSendPeers() { - long now = _context.clock().now(); + long old = _context.clock().now() - 60*1000; int active = 0; for (PeerState peer : _peersByIdent.values()) { - if (now-peer.getLastSendFullyTime() <= 1*60*1000) + if (peer.getLastSendFullyTime() >= old) active++; } return active;