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 */
|
/** @return milliseconds */
|
||||||
public long getTimeSinceSend() { return _context.clock().now()-_lastSendTime; }
|
public long getTimeSinceSend() { return _context.clock().now()-_lastSendTime; }
|
||||||
|
|
||||||
|
public long getTimeSinceSend(long now) { return now - _lastSendTime; }
|
||||||
|
|
||||||
/** @return milliseconds */
|
/** @return milliseconds */
|
||||||
public long getTimeSinceReceive() { return _context.clock().now()-_lastReceiveTime; }
|
public long getTimeSinceReceive() { return _context.clock().now()-_lastReceiveTime; }
|
||||||
|
|
||||||
|
public long getTimeSinceReceive(long now) { return now - _lastReceiveTime; }
|
||||||
|
|
||||||
/** @return milliseconds */
|
/** @return milliseconds */
|
||||||
public long getTimeSinceCreated() { return _context.clock().now()-_created; }
|
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.
|
* As of 0.9.20, actually returns active peer count, not total.
|
||||||
*/
|
*/
|
||||||
public int countActivePeers() {
|
public int countActivePeers() {
|
||||||
|
final long now = _context.clock().now();
|
||||||
int active = 0;
|
int active = 0;
|
||||||
for (NTCPConnection con : _conByIdent.values()) {
|
for (NTCPConnection con : _conByIdent.values()) {
|
||||||
// con initializes times at construction,
|
// con initializes times at construction,
|
||||||
// so check message count also
|
// so check message count also
|
||||||
if ((con.getMessagesSent() > 0 && con.getTimeSinceSend() <= 5*60*1000) ||
|
if ((con.getMessagesSent() > 0 && con.getTimeSinceSend(now) <= 5*60*1000) ||
|
||||||
(con.getMessagesReceived() > 0 && con.getTimeSinceReceive() <= 5*60*1000)) {
|
(con.getMessagesReceived() > 0 && con.getTimeSinceReceive(now) <= 5*60*1000)) {
|
||||||
active++;
|
active++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user