1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

lessons learned from 0.82:

* if we can't bind a socket to a peer, take that peer out of the retry pool.
* also, try to connect with more peers up-front.
This commit is contained in:
Charles Kerr 2007-12-15 04:26:31 +00:00
parent 4da5fc85bb
commit 10b6e8ff8f
2 changed files with 40 additions and 37 deletions

View file

@ -174,14 +174,18 @@ tr_peerIoNewOutgoing( struct tr_handle * handle,
int port, int port,
const uint8_t * torrentHash ) const uint8_t * torrentHash )
{ {
int socket;
assert( handle != NULL ); assert( handle != NULL );
assert( in_addr != NULL ); assert( in_addr != NULL );
assert( port >= 0 ); assert( port >= 0 );
assert( torrentHash != NULL ); assert( torrentHash != NULL );
return tr_peerIoNew( handle, in_addr, port, socket = tr_netOpenTCP( in_addr, port, 0 );
torrentHash, 0,
tr_netOpenTCP( in_addr, port, 0 ) ); return socket < 0
? NULL
: tr_peerIoNew( handle, in_addr, port, torrentHash, 0, socket );
} }
static void static void

View file

@ -110,8 +110,12 @@ enum
/* number of bad pieces a peer is allowed to send before we ban them */ /* number of bad pieces a peer is allowed to send before we ban them */
MAX_BAD_PIECES_PER_PEER = 3, MAX_BAD_PIECES_PER_PEER = 3,
/* use for bitwise operations w/peer_atom.myflags */ /* use for bitwise operations w/peer_atom.myflags */
MYFLAG_BANNED = 1 MYFLAG_BANNED = 1,
/* unreachable for now... but not banned. if they try to connect to us it's okay */
MYFLAG_UNREACHABLE = 2
}; };
@ -1735,40 +1739,26 @@ getPeerCandidates( Torrent * t, int * setmeSize )
/* peer fed us too much bad data ... we only keep it around /* peer fed us too much bad data ... we only keep it around
* now to weed it out in case someone sends it to us via pex */ * now to weed it out in case someone sends it to us via pex */
if( atom->myflags & MYFLAG_BANNED ) { if( atom->myflags & MYFLAG_BANNED )
#if 0 continue;
tordbg( t, "RECONNECT peer %d (%s) is banned...",
i, tr_peerIoAddrStr(&atom->addr,atom->port) ); /* peer was unconnectable before, so we're not going to keep trying.
#endif * this is needs a separate flag from `banned', since if they try
* to connect to us later, we'll let them in */
if( atom->myflags & MYFLAG_UNREACHABLE )
continue; continue;
}
/* we don't need two connections to the same peer... */ /* we don't need two connections to the same peer... */
if( peerIsInUse( t, &atom->addr ) ) { if( peerIsInUse( t, &atom->addr ) )
#if 0
tordbg( t, "RECONNECT peer %d (%s) is in use..",
i, tr_peerIoAddrStr(&atom->addr,atom->port) );
#endif
continue; continue;
}
/* no need to connect if we're both seeds... */ /* no need to connect if we're both seeds... */
if( seed && (atom->flags & ADDED_F_SEED_FLAG) ) { if( seed && (atom->flags & ADDED_F_SEED_FLAG) )
#if 0
tordbg( t, "RECONNECT peer %d (%s) is a seed and so are we..",
i, tr_peerIoAddrStr(&atom->addr,atom->port) );
#endif
continue; continue;
}
/* we're wasting our time trying to connect to this bozo. */ /* we're wasting our time trying to connect to this bozo. */
if( atom->numFails > 10 ) { if( atom->numFails > 10 )
#if 0
tordbg( t, "RECONNECT peer %d (%s) gives us nothing but failure.",
i, tr_peerIoAddrStr(&atom->addr,atom->port) );
#endif
continue; continue;
}
/* if we used this peer recently, give someone else a turn */ /* if we used this peer recently, give someone else a turn */
minWait = 60; minWait = 60;
@ -1803,7 +1793,7 @@ reconnectPulse( void * vtorrent )
} }
else else
{ {
int i, nCandidates, nBad; int i, nCandidates, nBad, addMax;
struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates ); struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates );
struct tr_peer ** connections = getPeersToClose( t, &nBad ); struct tr_peer ** connections = getPeersToClose( t, &nBad );
@ -1829,19 +1819,27 @@ reconnectPulse( void * vtorrent )
} }
/* add some new ones */ /* add some new ones */
addMax = tr_ptrArraySize(t->pool)
? MAX_RECONNECTIONS_PER_PULSE
: MAX_CONNECTED_PEERS_PER_TORRENT;
for( i=0; i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i ) for( i=0; i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
{ {
tr_peerMgr * mgr = t->manager; tr_peerMgr * mgr = t->manager;
struct peer_atom * atom = candidates[i]; struct peer_atom * atom = candidates[i];
tr_peerIo * io; tr_peerIo * io;
tr_handshake * handshake;
tordbg( t, "Starting an OUTGOING connection with %s", tordbg( t, "Starting an OUTGOING connection with %s",
tr_peerIoAddrStr( &atom->addr, atom->port ) ); tr_peerIoAddrStr( &atom->addr, atom->port ) );
io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash ); io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash );
if( io == NULL )
handshake = tr_handshakeNew( io, {
atom->myflags |= MYFLAG_UNREACHABLE;
}
else
{
tr_handshake * handshake = tr_handshakeNew( io,
mgr->handle->encryptionMode, mgr->handle->encryptionMode,
myHandshakeDoneCB, myHandshakeDoneCB,
mgr ); mgr );
@ -1849,6 +1847,7 @@ reconnectPulse( void * vtorrent )
assert( tr_peerIoGetTorrentHash( io ) != NULL ); assert( tr_peerIoGetTorrentHash( io ) != NULL );
tr_ptrArrayInsertSorted( t->outgoingHandshakes, handshake, handshakeCompare ); tr_ptrArrayInsertSorted( t->outgoingHandshakes, handshake, handshakeCompare );
}
atom->time = time( NULL ); atom->time = time( NULL );
} }