*/
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 flags2; /* flags that aren't defined in added_f */
uint8_t uploadOnly; /* UPLOAD_ONLY_ */
tr_isAtom( const struct peer_atom * atom )
{
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 ) );
}
#endif
a->addr = *addr;
a->port = port;
a->flags = flags;
- a->from = from;
+ a->fromFirst = from;
+ a->fromBest = from;
a->shelf_date = tr_time( ) + getDefaultShelfLife( from ) + jitter;
a->blocklisted = -1;
atomSetSeedProbability( a, seedProbability );
tordbg( t, "got a new atom: %s", tr_atomAddrStr( a ) );
}
- else if( a->seedProbability == -1 )
+ else
{
- atomSetSeedProbability( a, seedProbability );
+ if (from < a->fromBest)
+ a->fromBest = from;
+
+ if( a->seedProbability == -1 )
+ atomSetSeedProbability( a, seedProbability );
}
}
if( a->piece_data_time != b->piece_data_time )
return a->piece_data_time > b->piece_data_time ? -1 : 1;
- if( a->from != b->from )
- return a->from < b->from ? -1 : 1;
+ if( a->fromBest != b->fromBest )
+ return a->fromBest < b->fromBest ? -1 : 1;
if( a->numFails != b->numFails )
return a->numFails < b->numFails ? -1 : 1;
++*setmePeersConnected;
- ++setmePeersFrom[atom->from];
+ ++setmePeersFrom[atom->fromFirst];
if( clientIsDownloadingFrom( tor, peer ) )
++*setmePeersSendingToUs;
tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
sizeof( stat->client ) );
stat->port = ntohs( peer->atom->port );
- stat->from = atom->from;
+ stat->from = atom->fromFirst;
stat->progress = peer->progress;
stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
stat->rateToPeer_KBps = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now_msec, TR_CLIENT_TO_PEER ) );
if( !stat->peerIsChoked && !stat->peerIsInterested ) *pch++ = '?';
if( stat->isEncrypted ) *pch++ = 'E';
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';
*pch = '\0';
}
score = addValToKey( score, 8, i );
/* Prefer peers that we got from more trusted sources.
- * lower `from' values indicate more trusted sources */
- score = addValToKey( score, 4, atom->from );
+ * lower `fromBest' values indicate more trusted sources */
+ score = addValToKey( score, 4, atom->fromBest );
/* salt */
score = addValToKey( score, 8, salt );