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() {
PeerState s = state;
if (s != null) {
PeerConnectionIn in = s.in;
PeerConnectionOut out = s.out;
if (out != null)
return System.currentTimeMillis() - out.lastSent;
else
if (in != null && out != null) {
long now = System.currentTimeMillis();
return Math.max(now - out.lastSent, now - in.lastRcvd);
} else
return -1; //"state, no out";
} else {
return -1; //"no state";

View File

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

View File

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

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
* 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 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 long BUILD = 3;
public final static long BUILD = 4;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);