From 28db5be8027e48d37ee3d25a0155c89e8c14ba90 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 29 Jul 2008 00:52:02 +0000 Subject: [PATCH] #1123: unreachable peers need to be handled better --- libtransmission/peer-io.c | 13 +++++++++++-- libtransmission/peer-io.h | 1 + libtransmission/peer-mgr.c | 21 ++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 67b17094c..05c2aa392 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -68,6 +68,8 @@ struct tr_peerIo void * userData; tr_crypto * crypto; + + uint64_t fromPeer; }; /** @@ -537,11 +539,11 @@ tr_peerIoReadBytes( tr_peerIo * io, switch( io->encryptionMode ) { case PEER_ENCRYPTION_NONE: - evbuffer_remove( inbuf, bytes, byteCount ); + io->fromPeer += evbuffer_remove( inbuf, bytes, byteCount ); break; case PEER_ENCRYPTION_RC4: - evbuffer_remove( inbuf, bytes, byteCount ); + io->fromPeer += evbuffer_remove( inbuf, bytes, byteCount ); tr_cryptoDecrypt( io->crypto, byteCount, bytes, bytes ); break; @@ -593,3 +595,10 @@ tr_peerIoGetAge( const tr_peerIo * io ) { return time( NULL ) - io->timeCreated; } + +int64_t +tr_peerIoCountBytesFromPeer( const tr_peerIo * io ) +{ + return io->fromPeer; +} + diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index fede9c4b9..953a8271c 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -178,5 +178,6 @@ void tr_peerIoDrain ( tr_peerIo * io, struct evbuffer * inbuf, size_t byteCount ); +int64_t tr_peerIoCountBytesFromPeer( const tr_peerIo * io ); #endif diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index c6f43c5d4..55350fef7 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -44,7 +44,7 @@ enum RECHOKE_PERIOD_MSEC = (10 * 1000), /* minimum interval for refilling peers' request lists */ - REFILL_PERIOD_MSEC = 333, + REFILL_PERIOD_MSEC = 500, /* when many peers are available, keep idle ones this long */ MIN_UPLOAD_IDLE_SECS = (60 * 3), @@ -965,7 +965,18 @@ myHandshakeDoneCB( tr_handshake * handshake, if( t ) { struct peer_atom * atom = getExistingAtom( t, addr ); if( atom ) - ++atom->numFails; + { + /* if we talked but the connection failed, mark a failure + * in the peer's permanent record. if they didn't send + * us anything at all, mark the peer as unreachable. */ + if( tr_peerIoCountBytesFromPeer( io ) ) { + ++atom->numFails; + tordbg( t, "handshake failed; incremented fail count to %d", (int)atom->numFails ); + } else { + tordbg( t, "no data received at all during handshake; marking as unreachable" ); + atom->myflags |= MYFLAG_UNREACHABLE; + } + } } tr_peerIoFree( io ); @@ -1814,8 +1825,8 @@ getPeerCandidates( Torrent * t, int * setmeSize ) if( wait < minWait ) wait = minWait; if( wait > maxWait ) wait = maxWait; if( ( now - atom->time ) < wait ) { - tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..", - i, tr_peerIoAddrStr(&atom->addr,atom->port), wait ); + /*tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..", + i, tr_peerIoAddrStr(&atom->addr,atom->port), wait );*/ continue; } } @@ -1895,7 +1906,7 @@ reconnectPulse( void * vtorrent ) io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash ); if( io == NULL ) { - atom->myflags |= MYFLAG_UNREACHABLE; + /* we've temporarily exceeded our max connection limit... */ } else {