Changeset 9611
- Timestamp:
- Nov 28, 2009, 7:15:31 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r9600 r9611 115 115 struct peer_atom 116 116 { 117 tr_peer * peer; /* will be NULL if not connected */ 117 118 uint8_t from; 118 119 uint8_t flags; /* these match the added_f flags */ … … 310 311 } 311 312 312 static int313 peerCompareToAddr( const void * a, const void * vb )314 {315 return tr_compareAddresses( tr_peerAddress( a ), vb );316 }317 318 static tr_peer*319 getExistingPeer( Torrent * torrent,320 const tr_address * addr )321 {322 assert( torrentIsLocked( torrent ) );323 assert( addr );324 325 return tr_ptrArrayFindSorted( &torrent->peers, addr, peerCompareToAddr );326 }327 328 313 static struct peer_atom* 329 314 getExistingAtom( const Torrent * t, … … 336 321 337 322 static tr_bool 338 peerIsInUse( const Torrent * ct, 339 const tr_address * addr ) 323 peerIsInUse( const Torrent * ct, const struct peer_atom * atom ) 340 324 { 341 325 Torrent * t = (Torrent*) ct; … … 343 327 assert( torrentIsLocked ( t ) ); 344 328 345 return getExistingPeer( t, addr)346 || getExistingHandshake( &t->outgoingHandshakes, addr )347 || getExistingHandshake( &t->manager->incomingHandshakes, addr );329 return ( atom->peer != NULL ) 330 || getExistingHandshake( &t->outgoingHandshakes, &atom->addr ) 331 || getExistingHandshake( &t->manager->incomingHandshakes, &atom->addr ); 348 332 } 349 333 … … 354 338 tr_bitsetConstructor( &peer->have, 0 ); 355 339 peer->atom = atom; 340 atom->peer = peer; 341 peer->atom = atom; 356 342 return peer; 357 343 } … … 364 350 assert( torrentIsLocked( torrent ) ); 365 351 366 peer = getExistingPeer( torrent, &atom->addr );352 peer = atom->peer; 367 353 368 354 if( peer == NULL ) … … 396 382 tr_bitfieldFree( peer->blame ); 397 383 tr_free( peer->client ); 384 peer->atom->peer = NULL; 398 385 399 386 tr_free( peer ); … … 1518 1505 else 1519 1506 { 1520 tr_peer * peer = getExistingPeer( t, addr );1507 tr_peer * peer = atom->peer; 1521 1508 1522 1509 if( peer ) /* we already have this peer */ … … 2539 2526 2540 2527 /* we don't need two connections to the same peer... */ 2541 if( peerIsInUse( t, &atom->addr) )2528 if( peerIsInUse( t, atom ) ) 2542 2529 continue; 2543 2530 … … 3026 3013 for( i=0; i<atomCount; ++i ) { 3027 3014 struct peer_atom * atom = atoms[i]; 3028 if( peerIsInUse( t, &atom->addr) )3015 if( peerIsInUse( t, atom ) ) 3029 3016 keep[keepCount++] = atom; 3030 3017 else
Note: See TracChangeset
for help on using the changeset viewer.