forked from I2P_Developers/i2p.i2p
Get call to system timer out of tight loop when counting connections
This commit is contained in:
@@ -415,9 +415,13 @@ public class NTCPConnection implements Closeable {
|
||||
|
||||
/** @return milliseconds */
|
||||
public long getTimeSinceSend() { return _context.clock().now()-_lastSendTime; }
|
||||
|
||||
public long getTimeSinceSend(long now) { return now - _lastSendTime; }
|
||||
|
||||
/** @return milliseconds */
|
||||
public long getTimeSinceReceive() { return _context.clock().now()-_lastReceiveTime; }
|
||||
|
||||
public long getTimeSinceReceive(long now) { return now - _lastReceiveTime; }
|
||||
|
||||
/** @return milliseconds */
|
||||
public long getTimeSinceCreated() { return _context.clock().now()-_created; }
|
||||
|
@@ -707,12 +707,13 @@ public class NTCPTransport extends TransportImpl {
|
||||
* As of 0.9.20, actually returns active peer count, not total.
|
||||
*/
|
||||
public int countActivePeers() {
|
||||
final long now = _context.clock().now();
|
||||
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)) {
|
||||
if ((con.getMessagesSent() > 0 && con.getTimeSinceSend(now) <= 5*60*1000) ||
|
||||
(con.getMessagesReceived() > 0 && con.getTimeSinceReceive(now) <= 5*60*1000)) {
|
||||
active++;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user