mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
#3595 Allow promotion of the "from" value in peer_atom (and still show where it was first discovered)
This commit is contained in:
parent
f8ea720ba9
commit
8c4f3549c7
2 changed files with 20 additions and 13 deletions
|
@ -121,7 +121,8 @@ enum
|
||||||
*/
|
*/
|
||||||
struct peer_atom
|
struct peer_atom
|
||||||
{
|
{
|
||||||
uint8_t from;
|
uint8_t fromFirst; /* where the peer was first found */
|
||||||
|
uint8_t fromBest; /* the "best" value of where the peer has been found */
|
||||||
uint8_t flags; /* these match the added_f flags */
|
uint8_t flags; /* these match the added_f flags */
|
||||||
uint8_t flags2; /* flags that aren't defined in added_f */
|
uint8_t flags2; /* flags that aren't defined in added_f */
|
||||||
uint8_t uploadOnly; /* UPLOAD_ONLY_ */
|
uint8_t uploadOnly; /* UPLOAD_ONLY_ */
|
||||||
|
@ -150,7 +151,8 @@ static tr_bool
|
||||||
tr_isAtom( const struct peer_atom * atom )
|
tr_isAtom( const struct peer_atom * atom )
|
||||||
{
|
{
|
||||||
return ( atom != NULL )
|
return ( atom != NULL )
|
||||||
&& ( atom->from < TR_PEER_FROM__MAX )
|
&& ( atom->fromFirst < TR_PEER_FROM__MAX )
|
||||||
|
&& ( atom->fromBest < TR_PEER_FROM__MAX )
|
||||||
&& ( tr_isAddress( &atom->addr ) );
|
&& ( tr_isAddress( &atom->addr ) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1571,7 +1573,8 @@ ensureAtomExists( Torrent * t,
|
||||||
a->addr = *addr;
|
a->addr = *addr;
|
||||||
a->port = port;
|
a->port = port;
|
||||||
a->flags = flags;
|
a->flags = flags;
|
||||||
a->from = from;
|
a->fromFirst = from;
|
||||||
|
a->fromBest = from;
|
||||||
a->shelf_date = tr_time( ) + getDefaultShelfLife( from ) + jitter;
|
a->shelf_date = tr_time( ) + getDefaultShelfLife( from ) + jitter;
|
||||||
a->blocklisted = -1;
|
a->blocklisted = -1;
|
||||||
atomSetSeedProbability( a, seedProbability );
|
atomSetSeedProbability( a, seedProbability );
|
||||||
|
@ -1579,8 +1582,12 @@ ensureAtomExists( Torrent * t,
|
||||||
|
|
||||||
tordbg( t, "got a new atom: %s", tr_atomAddrStr( a ) );
|
tordbg( t, "got a new atom: %s", tr_atomAddrStr( a ) );
|
||||||
}
|
}
|
||||||
else if( a->seedProbability == -1 )
|
else
|
||||||
{
|
{
|
||||||
|
if (from < a->fromBest)
|
||||||
|
a->fromBest = from;
|
||||||
|
|
||||||
|
if( a->seedProbability == -1 )
|
||||||
atomSetSeedProbability( a, seedProbability );
|
atomSetSeedProbability( a, seedProbability );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1944,8 +1951,8 @@ compareAtomsByUsefulness( const void * va, const void *vb )
|
||||||
|
|
||||||
if( a->piece_data_time != b->piece_data_time )
|
if( a->piece_data_time != b->piece_data_time )
|
||||||
return a->piece_data_time > b->piece_data_time ? -1 : 1;
|
return a->piece_data_time > b->piece_data_time ? -1 : 1;
|
||||||
if( a->from != b->from )
|
if( a->fromBest != b->fromBest )
|
||||||
return a->from < b->from ? -1 : 1;
|
return a->fromBest < b->fromBest ? -1 : 1;
|
||||||
if( a->numFails != b->numFails )
|
if( a->numFails != b->numFails )
|
||||||
return a->numFails < b->numFails ? -1 : 1;
|
return a->numFails < b->numFails ? -1 : 1;
|
||||||
|
|
||||||
|
@ -2232,7 +2239,7 @@ tr_peerMgrTorrentStats( tr_torrent * tor,
|
||||||
|
|
||||||
++*setmePeersConnected;
|
++*setmePeersConnected;
|
||||||
|
|
||||||
++setmePeersFrom[atom->from];
|
++setmePeersFrom[atom->fromFirst];
|
||||||
|
|
||||||
if( clientIsDownloadingFrom( tor, peer ) )
|
if( clientIsDownloadingFrom( tor, peer ) )
|
||||||
++*setmePeersSendingToUs;
|
++*setmePeersSendingToUs;
|
||||||
|
@ -2341,7 +2348,7 @@ tr_peerMgrPeerStats( const tr_torrent * tor,
|
||||||
tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
|
tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
|
||||||
sizeof( stat->client ) );
|
sizeof( stat->client ) );
|
||||||
stat->port = ntohs( peer->atom->port );
|
stat->port = ntohs( peer->atom->port );
|
||||||
stat->from = atom->from;
|
stat->from = atom->fromFirst;
|
||||||
stat->progress = peer->progress;
|
stat->progress = peer->progress;
|
||||||
stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
|
stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
|
||||||
stat->rateToPeer_KBps = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now_msec, TR_CLIENT_TO_PEER ) );
|
stat->rateToPeer_KBps = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now_msec, TR_CLIENT_TO_PEER ) );
|
||||||
|
@ -2373,7 +2380,7 @@ tr_peerMgrPeerStats( const tr_torrent * tor,
|
||||||
if( !stat->peerIsChoked && !stat->peerIsInterested ) *pch++ = '?';
|
if( !stat->peerIsChoked && !stat->peerIsInterested ) *pch++ = '?';
|
||||||
if( stat->isEncrypted ) *pch++ = 'E';
|
if( stat->isEncrypted ) *pch++ = 'E';
|
||||||
if( stat->from == TR_PEER_FROM_DHT ) *pch++ = 'H';
|
if( stat->from == TR_PEER_FROM_DHT ) *pch++ = 'H';
|
||||||
if( stat->from == TR_PEER_FROM_PEX ) *pch++ = 'X';
|
else if( stat->from == TR_PEER_FROM_PEX ) *pch++ = 'X';
|
||||||
if( stat->isIncoming ) *pch++ = 'I';
|
if( stat->isIncoming ) *pch++ = 'I';
|
||||||
*pch = '\0';
|
*pch = '\0';
|
||||||
}
|
}
|
||||||
|
@ -3453,8 +3460,8 @@ getPeerCandidateScore( const tr_torrent * tor, const struct peer_atom * atom, ui
|
||||||
score = addValToKey( score, 8, i );
|
score = addValToKey( score, 8, i );
|
||||||
|
|
||||||
/* Prefer peers that we got from more trusted sources.
|
/* Prefer peers that we got from more trusted sources.
|
||||||
* lower `from' values indicate more trusted sources */
|
* lower `fromBest' values indicate more trusted sources */
|
||||||
score = addValToKey( score, 4, atom->from );
|
score = addValToKey( score, 4, atom->fromBest );
|
||||||
|
|
||||||
/* salt */
|
/* salt */
|
||||||
score = addValToKey( score, 8, salt );
|
score = addValToKey( score, 8, salt );
|
||||||
|
|
|
@ -185,7 +185,7 @@
|
||||||
|
|
||||||
if (connected > 0)
|
if (connected > 0)
|
||||||
{
|
{
|
||||||
NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 6];
|
NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 7];
|
||||||
if (tracker > 0)
|
if (tracker > 0)
|
||||||
[fromComponents addObject: [NSString stringWithFormat:
|
[fromComponents addObject: [NSString stringWithFormat:
|
||||||
NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]];
|
NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]];
|
||||||
|
|
Loading…
Reference in a new issue