don't bother remembering peers that hang up on us.

don't bother remembering peers that are seeds when we're seeding.
This commit is contained in:
Charles Kerr 2007-09-26 04:44:54 +00:00
parent 9dec223018
commit 682be6b12e
2 changed files with 17 additions and 8 deletions

View File

@ -28,7 +28,7 @@ typedef struct tr_peer
unsigned int clientIsChoked : 1; unsigned int clientIsChoked : 1;
unsigned int clientIsInterested : 1; unsigned int clientIsInterested : 1;
unsigned int peerSupportsEncryption : 1; unsigned int peerSupportsEncryption : 1;
unsigned int doDisconnect : 1; unsigned int doPurge : 1;
uint8_t from; uint8_t from;
uint16_t port; uint16_t port;

View File

@ -653,7 +653,7 @@ msgsCallbackFunc( void * vpeer, void * vevent, void * vt )
const int clientIsSeed = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE; const int clientIsSeed = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE;
const int peerIsSeed = e->progress >= 1.0; const int peerIsSeed = e->progress >= 1.0;
if( clientIsSeed && peerIsSeed ) if( clientIsSeed && peerIsSeed )
peer->doDisconnect = 1; peer->doPurge = 1;
break; break;
} }
@ -662,7 +662,7 @@ msgsCallbackFunc( void * vpeer, void * vevent, void * vt )
break; break;
case TR_PEERMSG_GOT_ERROR: case TR_PEERMSG_GOT_ERROR:
peer->doDisconnect = 1; peer->doPurge = 1;
reconnectSoon( t ); reconnectSoon( t );
break; break;
@ -1178,9 +1178,6 @@ shouldPeerBeDisconnected( Torrent * t, tr_peer * peer, int peerCount, int isSeed
if( !t->isRunning ) /* the torrent is stopped... nobody should be connected */ if( !t->isRunning ) /* the torrent is stopped... nobody should be connected */
return TRUE; return TRUE;
if( peer->doDisconnect ) /* someone set a `doDisconnect' flag somewhere */
return TRUE;
/* when deciding whether or not to keep a peer, judge its responsiveness /* when deciding whether or not to keep a peer, judge its responsiveness
on a sliding scale that's based on how many other peers are available */ on a sliding scale that's based on how many other peers are available */
relaxStrictnessIfFewerThanN = relaxStrictnessIfFewerThanN =
@ -1229,13 +1226,25 @@ reconnectPulse( void * vt UNUSED )
if( peers[i]->msgs != NULL ) if( peers[i]->msgs != NULL )
++liveCount; ++liveCount;
/* disconnect from some peers */ /* destroy and/or disconnect from some peers */
for( i=0; i<size; ++i ) { for( i=0; i<size; )
{
tr_peer * peer = peers[i]; tr_peer * peer = peers[i];
if( peer->doPurge ) {
tr_ptrArrayErase( t->peers, i, i+1 );
freePeer( peer );
--size;
--liveCount;
continue;
}
if( shouldPeerBeDisconnected( t, peer, liveCount, isSeeding ) ) { if( shouldPeerBeDisconnected( t, peer, liveCount, isSeeding ) ) {
disconnectPeer( peer ); disconnectPeer( peer );
--liveCount; --liveCount;
} }
++i;
} }
/* maybe connect to some new peers */ /* maybe connect to some new peers */