2007-11-26 zzz

* i2psnark: add timeout for receive inactivity
This commit is contained in:
zzz
2007-11-26 21:53:58 +00:00
committed by zzz
parent 4ebcc95d9f
commit c6a1112f0a
5 changed files with 18 additions and 9 deletions

View File

@ -461,10 +461,12 @@ public class Peer implements Comparable
public long getInactiveTime() { public long getInactiveTime() {
PeerState s = state; PeerState s = state;
if (s != null) { if (s != null) {
PeerConnectionIn in = s.in;
PeerConnectionOut out = s.out; PeerConnectionOut out = s.out;
if (out != null) if (in != null && out != null) {
return System.currentTimeMillis() - out.lastSent; long now = System.currentTimeMillis();
else return Math.max(now - out.lastSent, now - in.lastRcvd);
} else
return -1; //"state, no out"; return -1; //"state, no out";
} else { } else {
return -1; //"no state"; return -1; //"no state";

View File

@ -35,10 +35,13 @@ class PeerConnectionIn implements Runnable
private Thread thread; private Thread thread;
private volatile boolean quit; private volatile boolean quit;
long lastRcvd;
public PeerConnectionIn(Peer peer, DataInputStream din) public PeerConnectionIn(Peer peer, DataInputStream din)
{ {
this.peer = peer; this.peer = peer;
this.din = din; this.din = din;
lastRcvd = System.currentTimeMillis();
quit = false; quit = false;
} }
@ -76,6 +79,7 @@ class PeerConnectionIn implements Runnable
// Wait till we hear something... // Wait till we hear something...
// The length of a complete message in bytes. // The length of a complete message in bytes.
int i = din.readInt(); int i = din.readInt();
lastRcvd = System.currentTimeMillis();
if (i < 0) if (i < 0)
throw new IOException("Unexpected length prefix: " + i); throw new IOException("Unexpected length prefix: " + i);

View File

@ -253,8 +253,8 @@ public class PeerCoordinator implements PeerListener
synchronized(peers) synchronized(peers)
{ {
Peer old = peerIDInList(peer.getPeerID(), peers); Peer old = peerIDInList(peer.getPeerID(), peers);
if ( (old != null) && (old.getInactiveTime() > 4*60*1000) ) { if ( (old != null) && (old.getInactiveTime() > 8*60*1000) ) {
// idle for 4 minutes, kill the old con (64KB/4min = 273B/sec minimum for one block) // idle for 8 minutes, kill the old con (32KB/8min = 68B/sec minimum for one block)
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Remomving old peer: " + peer + ": " + old + ", inactive for " + old.getInactiveTime()); _log.warn("Remomving old peer: " + peer + ": " + old + ", inactive for " + old.getInactiveTime());
peers.remove(old); peers.remove(old);
@ -315,7 +315,7 @@ public class PeerCoordinator implements PeerListener
need_more = !peer.isConnected() && peers.size() < MAX_CONNECTIONS; need_more = !peer.isConnected() && peers.size() < MAX_CONNECTIONS;
// Check if we already have this peer before we build the connection // Check if we already have this peer before we build the connection
Peer old = peerIDInList(peer.getPeerID(), peers); Peer old = peerIDInList(peer.getPeerID(), peers);
need_more = need_more && ((old == null) || (old.getInactiveTime() > 4*60*1000)); need_more = need_more && ((old == null) || (old.getInactiveTime() > 8*60*1000));
} }
if (need_more) if (need_more)

View File

@ -1,4 +1,7 @@
$Id: history.txt,v 1.596 2007-11-06 06:26:01 jrandom Exp $ $Id: history.txt,v 1.597 2007-11-24 15:22:46 zzz Exp $
2007-11-26 zzz
* i2psnark: add timeout for receive inactivity
2007-11-24 zzz 2007-11-24 zzz
* i2psnark: increase streaming lib write timeout to 240 sec and change * i2psnark: increase streaming lib write timeout to 240 sec and change

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
* *
*/ */
public class RouterVersion { public class RouterVersion {
public final static String ID = "$Revision: 1.531 $ $Date: 2007-10-11 01:03:21 $"; public final static String ID = "$Revision: 1.532 $ $Date: 2007-11-24 15:22:45 $";
public final static String VERSION = "0.6.1.30"; public final static String VERSION = "0.6.1.30";
public final static long BUILD = 3; public final static long BUILD = 4;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID); System.out.println("Router ID: " + RouterVersion.ID);