Changeset 7456 for trunk/libtransmission/peer-mgr.c
- Timestamp:
- Dec 22, 2008, 12:52:44 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r7448 r7456 199 199 200 200 static int 201 handshakeCompareToAddr( const void * va, 202 const void * vb ) 201 handshakeCompareToAddr( const void * va, const void * vb ) 203 202 { 204 203 const tr_handshake * a = va; … … 208 207 209 208 static int 210 handshakeCompare( const void * a, 211 const void * b ) 209 handshakeCompare( const void * a, const void * b ) 212 210 { 213 211 return handshakeCompareToAddr( a, tr_handshakeGetAddr( b, NULL ) ); … … 535 533 536 534 tr_bool 537 tr_peerMgrPeerIsSeed( const tr_peerMgr 538 const uint8_t 539 const tr_address 535 tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 536 const uint8_t * torrentHash, 537 const tr_address * addr ) 540 538 { 541 539 tr_bool isSeed = FALSE; … … 633 631 634 632 static tr_piece_index_t * 635 getPreferredPieces( Torrent * t, tr_piece_index_t 633 getPreferredPieces( Torrent * t, tr_piece_index_t * pieceCount ) 636 634 { 637 635 const tr_torrent * tor = t->tor; … … 831 829 for( j=0; !handled && j<peerCount; ) 832 830 { 833 const tr_addreq_t val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length , FALSE);831 const tr_addreq_t val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length ); 834 832 switch( val ) 835 833 { … … 858 856 for( j=0; !handled && j<webseedCount; ) 859 857 { 860 const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], 861 index, offset, length ); 858 const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], index, offset, length ); 862 859 switch( val ) 863 860 { … … 942 939 943 940 static void 944 peerSuggestedPiece( Torrent * t, 945 tr_peer * peer, 946 tr_piece_index_t pieceIndex, 947 int isFastAllowed ) 948 { 941 peerSuggestedPiece( Torrent * t UNUSED, 942 tr_peer * peer UNUSED, 943 tr_piece_index_t pieceIndex UNUSED, 944 int isFastAllowed UNUSED ) 945 { 946 #if 0 949 947 assert( t ); 950 948 assert( peer ); … … 980 978 const uint32_t offset = getBlockOffsetInPiece( tor, block ); 981 979 const uint32_t length = tr_torBlockCountBytes( tor, block ); 982 tr_peerMsgsAddRequest( peer->msgs, pieceIndex, offset, length , TRUE);980 tr_peerMsgsAddRequest( peer->msgs, pieceIndex, offset, length ); 983 981 incrementPieceRequests( t, pieceIndex ); 984 982 } 985 983 } 986 984 } 985 #endif 987 986 } 988 987 989 988 static void 990 peerCallbackFunc( void * vpeer, 991 void * vevent, 992 void * vt ) 993 { 994 tr_peer * peer = vpeer; /* may be NULL if peer is a webseed */ 995 Torrent * t = vt; 989 peerCallbackFunc( void * vpeer, void * vevent, void * vt ) 990 { 991 tr_peer * peer = vpeer; /* may be NULL if peer is a webseed */ 992 Torrent * t = vt; 996 993 const tr_peer_event * e = vevent; 997 994 … … 1204 1201 /* FIXME: this is kind of a mess. */ 1205 1202 static tr_bool 1206 myHandshakeDoneCB( tr_handshake * 1203 myHandshakeDoneCB( tr_handshake * handshake, 1207 1204 tr_peerIo * io, 1208 1205 int isConnected, … … 1344 1341 } 1345 1342 1346 static int1343 static tr_bool 1347 1344 tr_isPex( const tr_pex * pex ) 1348 1345 { … … 1361 1358 managerLock( manager ); 1362 1359 1363 1364 1360 t = getExistingTorrent( manager, torrentHash ); 1365 1361 if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) ) 1366 1362 ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from ); 1367 1363 1368 1364 managerUnlock( manager ); 1369 1365 } … … 1539 1535 { 1540 1536 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1537 1541 1538 assert( tr_isAddress( &peer->addr ) ); 1542 1539 walk->addr = peer->addr; … … 1545 1542 if( peerPrefersCrypto( peer ) ) 1546 1543 walk->flags |= ADDED_F_ENCRYPTION_FLAG; 1547 if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) || 1548 ( peer->progress >= 1.0 ) ) 1544 if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ) ) 1549 1545 walk->flags |= ADDED_F_SEED_FLAG; 1550 1546 ++peersReturning; … … 1555 1551 assert( ( walk - pex ) == peersReturning ); 1556 1552 qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare ); 1557 1558 1553 *setme_pex = pex; 1559 1554 } … … 1678 1673 const tr_torrent * tor; 1679 1674 float interval; 1680 intisSeed;1675 tr_bool isSeed; 1681 1676 int peerCount; 1682 1677 const tr_peer ** peers; … … 1698 1693 if( isSeed || tr_cpPieceIsComplete( tor->completion, piece ) ) 1699 1694 tab[i] = -1; 1700 else if( peerCount ) 1701 { 1695 else if( peerCount ) { 1702 1696 int j; 1703 1697 for( j = 0; j < peerCount; ++j ) … … 1802 1796 webseeds = (const tr_webseed **) tr_ptrArrayPeek( t->webseeds, &size ); 1803 1797 for( i=0; i<size; ++i ) 1804 {1805 1798 if( tr_webseedIsActive( webseeds[i] ) ) 1806 1799 ++*setmeWebseedsSendingToUs; 1807 }1808 1800 1809 1801 managerUnlock( manager ); … … 1872 1864 tr_address norm_addr; 1873 1865 1874 memcpy( &norm_addr, &peer->addr, sizeof( tr_address ) );1866 norm_addr = peer->addr; 1875 1867 tr_normalizeV4Mapped( &norm_addr ); 1876 1868 tr_ntop( &norm_addr, stat->addr, sizeof( stat->addr ) ); … … 2048 2040 } 2049 2041 2050 for( i = 0; i <size; ++i )2042 for( i=0; i<size; ++i ) 2051 2043 tr_peerMsgsSetChoke( choke[i].peer->msgs, !choke[i].doUnchoke ); 2052 2044 … … 2105 2097 tr_bitfieldFree( tmp ); 2106 2098 } 2107 if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 ))) { 2099 2100 if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 ))) 2101 { 2108 2102 tordbg( t, "purging peer %s because we're both seeds", 2109 tr_peerIoAddrStr( &atom->addr, atom->port ) );2103 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2110 2104 return TRUE; 2111 2105 } … … 2303 2297 if( nBad || nCandidates ) 2304 2298 tordbg( t, "reconnect pulse for [%s]: %d bad connections, " 2305 "%d connection candidates, %d atoms, max per pulse is %d",2306 t->tor->info.name, nBad, nCandidates,2307 tr_ptrArraySize( t->pool ),2308 (int)MAX_RECONNECTIONS_PER_PULSE );2299 "%d connection candidates, %d atoms, max per pulse is %d", 2300 t->tor->info.name, nBad, nCandidates, 2301 tr_ptrArraySize( t->pool ), 2302 (int)MAX_RECONNECTIONS_PER_PULSE ); 2309 2303 2310 2304 /* disconnect some peers. … … 2319 2313 else 2320 2314 ++atom->numFails; 2321 2322 2315 tordbg( t, "removing bad peer %s", tr_peerIoGetAddrStr( peer->io ) ); 2323 2316 removePeer( t, peer );
Note: See TracChangeset
for help on using the changeset viewer.