#1123: unreachable peers need to be handled better
This commit is contained in:
parent
703f96aeb3
commit
28db5be802
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue