Transport: Fix active peer count for NTCP,

which will make the network-down message in the console consistent.
Javadocs for getActivePeers() and getActiveSendPeers()
Make getActivePeers() and getActiveSendPeers() abstract in TransportImpl
Make getActivePeers() and getActiveSendPeers() more efficient
Preliminary conn limits for P/X
Log tweaks
This commit is contained in:
zzz
2015-04-16 14:13:23 +00:00
parent 997fbb3392
commit 12fd585625
8 changed files with 77 additions and 24 deletions

View File

@ -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; }

View File

@ -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

View File

@ -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;
}
}

View File

@ -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()) {

View File

@ -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 */

View File

@ -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;
}

View File

@ -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();

View File

@ -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;