mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
when deciding which peers to try to connect to, add some weights to punish peers that don't transfer piece data with us. We'll still give them another, but at longer intervals than better peers get.
This commit is contained in:
parent
92bb5c33de
commit
8feeb9ee6b
2 changed files with 36 additions and 19 deletions
|
@ -97,6 +97,7 @@ struct peer_atom
|
||||||
uint8_t flags; /* these match the added_f flags */
|
uint8_t flags; /* these match the added_f flags */
|
||||||
uint8_t myflags; /* flags that aren't defined in added_f */
|
uint8_t myflags; /* flags that aren't defined in added_f */
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
uint16_t numFails;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
time_t time;
|
time_t time;
|
||||||
};
|
};
|
||||||
|
@ -290,12 +291,6 @@ getExistingAtom( const Torrent * t, const struct in_addr * addr )
|
||||||
return tr_ptrArrayFindSorted( t->pool, addr, comparePeerAtomToAddress );
|
return tr_ptrArrayFindSorted( t->pool, addr, comparePeerAtomToAddress );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
peerIsKnown( const Torrent * t, const struct in_addr * addr )
|
|
||||||
{
|
|
||||||
return getExistingAtom( t, addr ) != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
peerIsInUse( const Torrent * ct, const struct in_addr * addr )
|
peerIsInUse( const Torrent * ct, const struct in_addr * addr )
|
||||||
{
|
{
|
||||||
|
@ -852,16 +847,19 @@ msgsCallbackFunc( void * vpeer, void * vevent, void * vt )
|
||||||
static void
|
static void
|
||||||
ensureAtomExists( Torrent * t, const struct in_addr * addr, uint16_t port, uint8_t flags, uint8_t from )
|
ensureAtomExists( Torrent * t, const struct in_addr * addr, uint16_t port, uint8_t flags, uint8_t from )
|
||||||
{
|
{
|
||||||
if( !peerIsKnown( t, addr ) )
|
struct peer_atom * a = getExistingAtom( t, addr );
|
||||||
|
|
||||||
|
if( a != NULL )
|
||||||
{
|
{
|
||||||
struct peer_atom * a = tr_new0( struct peer_atom, 1 );
|
struct peer_atom * a = tr_new0( struct peer_atom, 1 );
|
||||||
a->addr = *addr;
|
a->addr = *addr;
|
||||||
a->port = port;
|
a->port = port;
|
||||||
a->flags = flags;
|
a->flags = flags;
|
||||||
a->from = from;
|
|
||||||
tordbg( t, "got a new atom: %s", tr_peerIoAddrStr(&a->addr,a->port) );
|
tordbg( t, "got a new atom: %s", tr_peerIoAddrStr(&a->addr,a->port) );
|
||||||
tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms );
|
tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a->from = from;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: this is kind of a mess. */
|
/* FIXME: this is kind of a mess. */
|
||||||
|
@ -906,6 +904,9 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
||||||
if( !ok || !t || !t->isRunning )
|
if( !ok || !t || !t->isRunning )
|
||||||
{
|
{
|
||||||
tr_peerIoFree( io );
|
tr_peerIoFree( io );
|
||||||
|
|
||||||
|
if( t )
|
||||||
|
++getExistingAtom( t, in_addr )->numFails;
|
||||||
}
|
}
|
||||||
else /* looking good */
|
else /* looking good */
|
||||||
{
|
{
|
||||||
|
@ -976,7 +977,7 @@ tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||||
void
|
void
|
||||||
tr_peerMgrAddPex( tr_peerMgr * manager,
|
tr_peerMgrAddPex( tr_peerMgr * manager,
|
||||||
const uint8_t * torrentHash,
|
const uint8_t * torrentHash,
|
||||||
int from,
|
uint8_t from,
|
||||||
const tr_pex * pex,
|
const tr_pex * pex,
|
||||||
int pexCount )
|
int pexCount )
|
||||||
{
|
{
|
||||||
|
@ -995,7 +996,7 @@ tr_peerMgrAddPex( tr_peerMgr * manager,
|
||||||
void
|
void
|
||||||
tr_peerMgrAddPeers( tr_peerMgr * manager,
|
tr_peerMgrAddPeers( tr_peerMgr * manager,
|
||||||
const uint8_t * torrentHash,
|
const uint8_t * torrentHash,
|
||||||
int from,
|
uint8_t from,
|
||||||
const uint8_t * peerCompact,
|
const uint8_t * peerCompact,
|
||||||
int peerCount )
|
int peerCount )
|
||||||
{
|
{
|
||||||
|
@ -1582,6 +1583,7 @@ getPeerCandidates( Torrent * t, int * setmeSize )
|
||||||
ret = tr_new( struct peer_atom*, atomCount );
|
ret = tr_new( struct peer_atom*, atomCount );
|
||||||
for( i=retCount=0; i<atomCount; ++i )
|
for( i=retCount=0; i<atomCount; ++i )
|
||||||
{
|
{
|
||||||
|
int wait, minWait, maxWait;
|
||||||
struct peer_atom * atom = atoms[i];
|
struct peer_atom * atom = atoms[i];
|
||||||
|
|
||||||
/* peer fed us too much bad data ... we only keep it around
|
/* peer fed us too much bad data ... we only keep it around
|
||||||
|
@ -1607,9 +1609,14 @@ getPeerCandidates( Torrent * t, int * setmeSize )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we used this peer recently, give someone else a turn */
|
/* if we used this peer recently, give someone else a turn */
|
||||||
if( ( now - atom->time ) < 180 ) {
|
minWait = 60;
|
||||||
tordbg( t, "RECONNECT peer %d (%s) is in its grace period..",
|
maxWait = minWait * 5;
|
||||||
i, tr_peerIoAddrStr(&atom->addr,atom->port) );
|
wait = atom->numFails * 10;
|
||||||
|
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 );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1646,9 +1653,19 @@ reconnectPulse( void * vtorrent )
|
||||||
tr_ptrArraySize(t->pool),
|
tr_ptrArraySize(t->pool),
|
||||||
(int)MAX_RECONNECTIONS_PER_PULSE );
|
(int)MAX_RECONNECTIONS_PER_PULSE );
|
||||||
|
|
||||||
/* disconnect some peers */
|
/* disconnect some peers.
|
||||||
for( i=0; i<nBad; ++i )
|
if we got transferred piece data, then they might be good peers,
|
||||||
removePeer( t, connections[i] );
|
so reset their `numFails' weight to zero. otherwise we connected
|
||||||
|
to them fruitlessly, so mark it as another fail */
|
||||||
|
for( i=0; i<nBad; ++i ) {
|
||||||
|
tr_peer * peer = connections[i];
|
||||||
|
struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
|
||||||
|
if( peer->pieceDataActivityDate )
|
||||||
|
atom->numFails = 0;
|
||||||
|
else
|
||||||
|
++atom->numFails;
|
||||||
|
removePeer( t, peer );
|
||||||
|
}
|
||||||
|
|
||||||
/* add some new ones */
|
/* add some new ones */
|
||||||
nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
|
nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
|
||||||
|
|
|
@ -43,13 +43,13 @@ void tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||||
|
|
||||||
void tr_peerMgrAddPeers( tr_peerMgr * manager,
|
void tr_peerMgrAddPeers( tr_peerMgr * manager,
|
||||||
const uint8_t * torrentHash,
|
const uint8_t * torrentHash,
|
||||||
int from,
|
uint8_t from,
|
||||||
const uint8_t * peerCompact,
|
const uint8_t * peerCompact,
|
||||||
int peerCount );
|
int peerCount );
|
||||||
|
|
||||||
void tr_peerMgrAddPex( tr_peerMgr * manager,
|
void tr_peerMgrAddPex( tr_peerMgr * manager,
|
||||||
const uint8_t * torrentHash,
|
const uint8_t * torrentHash,
|
||||||
int from,
|
uint8_t from,
|
||||||
const tr_pex * pex,
|
const tr_pex * pex,
|
||||||
int pexCount );
|
int pexCount );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue