Changeset 7456
- Timestamp:
- Dec 22, 2008, 12:52:44 AM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/handshake.h
r7441 r7456 19 19 20 20 #include "transmission.h" 21 #include "net.h" 21 22 22 struct tr_address;23 23 struct tr_peerIo; 24 24 typedef struct tr_handshake tr_handshake; … … 36 36 void * doneUserData ); 37 37 38 const struct tr_address * 39 tr_handshakeGetAddr( const struct tr_handshake * handshake, 38 const tr_address * tr_handshakeGetAddr( const struct tr_handshake * handshake, 40 39 tr_port * port ); 41 40 -
trunk/libtransmission/peer-common.h
r7404 r7456 61 61 float progress; /* for PEER_PROGRESS */ 62 62 int err; /* errno for GOT_ERROR */ 63 intwasPieceData; /* for GOT_DATA */63 tr_bool wasPieceData; /* for GOT_DATA */ 64 64 tr_bool uploadOnly; /* for UPLOAD_ONLY */ 65 65 } -
trunk/libtransmission/peer-io.c
r7446 r7456 466 466 467 467 const char* 468 tr_peerIoAddrStr( const tr_address * addr, 469 tr_port port ) 468 tr_peerIoAddrStr( const tr_address * addr, tr_port port ) 470 469 { 471 470 static char buf[512]; -
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 ); -
trunk/libtransmission/peer-msgs.c
r7448 r7456 402 402 403 403 static void 404 protocolSendRequest( tr_peermsgs *msgs,404 protocolSendRequest( tr_peermsgs * msgs, 405 405 const struct peer_request * req ) 406 406 { … … 420 420 421 421 static void 422 protocolSendCancel( tr_peermsgs *msgs,422 protocolSendCancel( tr_peermsgs * msgs, 423 423 const struct peer_request * req ) 424 424 { … … 448 448 tr_peerIoWriteUint32( io, out, index ); 449 449 450 dbgmsg( msgs, "sending Have %u ...", index );450 dbgmsg( msgs, "sending Have %u", index ); 451 451 dbgOutMessageLen( msgs ); 452 452 pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS ); … … 773 773 tr_peerIoWriteUint32( msgs->peer->io, out, sizeof( uint8_t ) ); 774 774 tr_peerIoWriteUint8 ( msgs->peer->io, out, weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED ); 775 775 776 pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS ); 776 777 dbgOutMessageLen( msgs ); … … 876 877 oldestAllowed = now - QUEUED_REQUEST_TTL_SECS; 877 878 reqListCopy( &tmp, &msgs->clientWillAskFor ); 878 for( i = 0; i <tmp.count; ++i ) {879 for( i=0; i<tmp.count; ++i ) { 879 880 const struct peer_request * req = &tmp.requests[i]; 880 881 if( req->time_requested < oldestAllowed ) … … 934 935 if( sent ) 935 936 dbgmsg( msgs, "pump sent %d requests, now have %d active and %d queued", 936 sent, 937 msgs->clientAskedFor.count, 938 msgs->clientWillAskFor.count ); 937 sent, msgs->clientAskedFor.count, msgs->clientWillAskFor.count ); 939 938 940 939 if( count < max ) … … 953 952 uint32_t index, 954 953 uint32_t offset, 955 uint32_t length, 956 int doForce ) 954 uint32_t length ) 957 955 { 958 956 struct peer_request req; … … 967 965 968 966 /* don't send requests to choked clients */ 969 if( !doForce &&msgs->peer->clientIsChoked ) {967 if( msgs->peer->clientIsChoked ) { 970 968 dbgmsg( msgs, "declining request because they're choking us" ); 971 969 return TR_ADDREQ_CLIENT_CHOKED; … … 973 971 974 972 /* peer doesn't have this piece */ 975 if( ! doForce && !tr_bitfieldHas( msgs->peer->have, index ) )973 if( !tr_bitfieldHas( msgs->peer->have, index ) ) 976 974 return TR_ADDREQ_MISSING; 977 975 978 976 /* peer's queue is full */ 979 if( !doForce &&requestQueueIsFull( msgs ) ) {977 if( requestQueueIsFull( msgs ) ) { 980 978 dbgmsg( msgs, "declining request because we're full" ); 981 979 return TR_ADDREQ_FULL; … … 986 984 req.offset = offset; 987 985 req.length = length; 988 if( !doForce ) { 989 if( reqListFind( &msgs->clientAskedFor, &req ) != -1 ) { 990 dbgmsg( msgs, "declining because it's a duplicate" ); 991 return TR_ADDREQ_DUPLICATE; 992 } 993 if( reqListFind( &msgs->clientWillAskFor, &req ) != -1 ) { 994 dbgmsg( msgs, "declining because it's a duplicate" ); 995 return TR_ADDREQ_DUPLICATE; 996 } 986 if( reqListFind( &msgs->clientAskedFor, &req ) != -1 ) { 987 dbgmsg( msgs, "declining because it's a duplicate" ); 988 return TR_ADDREQ_DUPLICATE; 989 } 990 if( reqListFind( &msgs->clientWillAskFor, &req ) != -1 ) { 991 dbgmsg( msgs, "declining because it's a duplicate" ); 992 return TR_ADDREQ_DUPLICATE; 997 993 } 998 994 … … 1582 1578 break; 1583 1579 1584 1585 1580 case BT_FEXT_HAVE_NONE: 1586 1581 dbgmsg( msgs, "Got a BT_FEXT_HAVE_NONE" ); … … 1781 1776 size_t bytesWritten = 0; 1782 1777 struct peer_request req; 1783 const inthaveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0;1778 const tr_bool haveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0; 1784 1779 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); 1785 1780 … … 1881 1876 tr_peerMsgsPulse( tr_peermsgs * msgs ) 1882 1877 { 1883 if( msgs )1878 if( msgs != NULL ) 1884 1879 peerPulse( msgs ); 1885 1880 } … … 2203 2198 tr_peermsgs* 2204 2199 tr_peerMsgsNew( struct tr_torrent * torrent, 2205 struct tr_peer *peer,2200 struct tr_peer * peer, 2206 2201 tr_delivery_func func, 2207 void *userData,2208 tr_publisher_tag *setme )2202 void * userData, 2203 tr_publisher_tag * setme ) 2209 2204 { 2210 2205 tr_peermsgs * m; -
trunk/libtransmission/peer-msgs.h
r7404 r7456 54 54 uint32_t pieceIndex, 55 55 uint32_t offset, 56 uint32_t length, 57 int doForce ); 56 uint32_t length ); 58 57 59 58 void tr_peerMsgsUnsubscribe( tr_peermsgs * peer, -
trunk/libtransmission/transmission.h
r7446 r7456 1409 1409 tr_bool tr_isDirection( tr_direction ); 1410 1410 1411 1412 1411 /** @} */ 1413 1412
Note: See TracChangeset
for help on using the changeset viewer.