Changeset 7289
- Timestamp:
- Dec 5, 2008, 10:56:19 PM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/handshake.c
r7266 r7289 247 247 uint8_t hash[SHA_DIGEST_LENGTH]; 248 248 249 dbgmsg( handshake, "payload: need %d, got % d", (int)HANDSHAKE_SIZE,250 (int)EVBUFFER_LENGTH( inbuf ) );249 dbgmsg( handshake, "payload: need %d, got %zu", 250 (int)HANDSHAKE_SIZE, EVBUFFER_LENGTH( inbuf ) ); 251 251 252 252 if( EVBUFFER_LENGTH( inbuf ) < HANDSHAKE_SIZE ) … … 396 396 return READ_LATER; 397 397 398 isEncrypted = memcmp( EVBUFFER_DATA( 399 inbuf ), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN ); 398 isEncrypted = memcmp( EVBUFFER_DATA( inbuf ), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN ); 400 399 if( isEncrypted ) 401 400 { … … 408 407 ( isEncrypted ? "encrypted" : "plaintext" ) ); 409 408 410 tr_peerIoSetEncryption( 411 handshake->io, isEncrypted ? PEER_ENCRYPTION_RC4 412 : PEER_ENCRYPTION_NONE ); 409 tr_peerIoSetEncryption( handshake->io, isEncrypted ? PEER_ENCRYPTION_RC4 410 : PEER_ENCRYPTION_NONE ); 413 411 if( !isEncrypted ) 414 412 { … … 440 438 uint8_t buf[SHA_DIGEST_LENGTH]; 441 439 tr_sha1( req2, "req2", 4, 442 tr_cryptoGetTorrentHash( 443 handshake->crypto ),SHA_DIGEST_LENGTH, NULL );440 tr_cryptoGetTorrentHash( handshake->crypto ), 441 SHA_DIGEST_LENGTH, NULL ); 444 442 tr_sha1( req3, "req3", 4, secret, KEY_LEN, NULL ); 445 443 for( i = 0; i < SHA_DIGEST_LENGTH; ++i ) … … 562 560 uint8_t * tmp; 563 561 564 dbgmsg( handshake, "pad d: need %d, got %d", (int)needlen, 565 (int)EVBUFFER_LENGTH( 566 inbuf ) ); 562 dbgmsg( handshake, "pad d: need %zu, got %zu", 563 needlen, EVBUFFER_LENGTH( inbuf ) ); 567 564 if( EVBUFFER_LENGTH( inbuf ) < needlen ) 568 565 return READ_LATER; … … 594 591 uint8_t hash[SHA_DIGEST_LENGTH]; 595 592 596 dbgmsg( handshake, "payload: need %d, got %d", 597 (int)INCOMING_HANDSHAKE_LEN, (int)EVBUFFER_LENGTH( 598 inbuf ) ); 593 dbgmsg( handshake, "payload: need %d, got %zu", 594 (int)INCOMING_HANDSHAKE_LEN, EVBUFFER_LENGTH( inbuf ) ); 599 595 600 596 if( EVBUFFER_LENGTH( inbuf ) < INCOMING_HANDSHAKE_LEN ) … … 714 710 715 711 /* peer id */ 716 tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id, 717 PEER_ID_LEN ); 712 tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id, PEER_ID_LEN ); 718 713 tr_peerIoSetPeersId( handshake->io, handshake->peer_id ); 719 714 handshake->havePeerID = TRUE; 720 715 tr_clientForId( client, sizeof( client ), handshake->peer_id ); 721 716 dbgmsg( handshake, "peer-id is [%s] ... isIncoming is %d", client, 722 tr_peerIoIsIncoming( 723 handshake->io ) ); 717 tr_peerIoIsIncoming( handshake->io ) ); 724 718 725 719 /* if we've somehow connected to ourselves, don't keep the connection */ … … 739 733 int len; 740 734 741 dbgmsg( handshake, "in readYa... need %d, have %d", (int)KEY_LEN, 742 (int)EVBUFFER_LENGTH( 743 inbuf ) ); 735 dbgmsg( handshake, "in readYa... need %d, have %zu", 736 (int)KEY_LEN, EVBUFFER_LENGTH( inbuf ) ); 744 737 if( EVBUFFER_LENGTH( inbuf ) < KEY_LEN ) 745 738 return READ_LATER; … … 772 765 uint8_t * pch; 773 766 774 dbgmsg( 775 handshake, 776 "looking to get past pad a... & resync on hash('req',S) ... have %d bytes", 777 (int)EVBUFFER_LENGTH( inbuf ) ); 767 dbgmsg( handshake, "looking to get past pad a... & resync on hash('req',S) ... have %zu bytes", 768 EVBUFFER_LENGTH( inbuf ) ); 778 769 /** 779 770 *** Resynchronizing on HASH('req1',S) … … 785 776 if( pch == NULL ) 786 777 { 787 dbgmsg( handshake, "no luck so far.. draining %d bytes", 788 (int)EVBUFFER_LENGTH( 789 inbuf ) ); 778 dbgmsg( handshake, "no luck so far.. draining %zu bytes", 779 EVBUFFER_LENGTH( inbuf ) ); 790 780 evbuffer_drain( inbuf, EVBUFFER_LENGTH( inbuf ) ); 791 781 return READ_LATER; … … 850 840 obfuscatedTorrentHash ) ) ) 851 841 { 852 dbgmsg( 853 handshake, 854 "got INCOMING connection's encrypted handshake for torrent [%s]", 855 tor->info.name ); 842 dbgmsg( handshake, "got INCOMING connection's encrypted handshake for torrent [%s]", 843 tor->info.name ); 856 844 tr_peerIoSetTorrentHash( handshake->io, tor->info.hash ); 857 845 if( !tr_torrentAllowsPex( tor ) … … 914 902 uint32_t crypto_select; 915 903 916 dbgmsg( handshake, "reading IA... have %d, need %d", 917 (int)EVBUFFER_LENGTH( 918 inbuf ), (int)needlen ); 904 dbgmsg( handshake, "reading IA... have %zu, need %zu", 905 EVBUFFER_LENGTH( inbuf ), needlen ); 919 906 if( EVBUFFER_LENGTH( inbuf ) < needlen ) 920 907 return READ_LATER; 921 908 922 909 /** 923 *** B->A: ENCRYPT(VC, crypto_select, len(padD), padD), ENCRYPT2(Payload 924 ***Stream) 910 *** B->A: ENCRYPT(VC, crypto_select, len(padD), padD), ENCRYPT2(Payload Stream) 925 911 **/ 926 912 … … 951 937 952 938 dbgmsg( handshake, "sending pad d" ); 953 /* ENCRYPT(VC, crypto_provide, len(Pad C), PadC939 /* ENCRYPT(VC, crypto_provide, len(PadD), PadD 954 940 * PadD is reserved for future extensions to the handshake... 955 941 * standard practice at this time is for it to be zero-length */ … … 989 975 const size_t needlen = HANDSHAKE_SIZE; 990 976 991 dbgmsg( handshake, "reading payload stream... have % d, need %d",992 (int)EVBUFFER_LENGTH( inbuf ), (int)needlen );977 dbgmsg( handshake, "reading payload stream... have %zu, need %zu", 978 EVBUFFER_LENGTH( inbuf ), needlen ); 993 979 if( EVBUFFER_LENGTH( inbuf ) < needlen ) 994 980 return READ_LATER; … … 1013 999 canRead( struct tr_iobuf * iobuf, void * arg, size_t * piece ) 1014 1000 { 1015 tr_handshake *handshake = arg;1001 tr_handshake * handshake = arg; 1016 1002 struct evbuffer * inbuf = tr_iobuf_input( iobuf ); 1017 1003 ReadState ret; 1018 intreadyForMore = TRUE;1004 tr_bool readyForMore = TRUE; 1019 1005 1020 1006 /* no piece data in handshake */ -
trunk/libtransmission/handshake.h
r7231 r7289 25 25 26 26 /* returns true on success, false on error */ 27 typedef int( *handshakeDoneCB )( struct tr_handshake * handshake,28 struct tr_peerIo * io,29 int isConnected,30 const uint8_t * peerId,31 void * userData );27 typedef tr_bool ( *handshakeDoneCB )( struct tr_handshake * handshake, 28 struct tr_peerIo * io, 29 int isConnected, 30 const uint8_t * peerId, 31 void * userData ); 32 32 33 33 tr_handshake * tr_handshakeNew( struct tr_peerIo * io, -
trunk/libtransmission/peer-io.c
r7234 r7289 496 496 void 497 497 tr_peerIoEnableFEXT( tr_peerIo * io, 498 intflag )498 tr_bool flag ) 499 499 { 500 500 assert( isPeerIo( io ) ); … … 505 505 } 506 506 507 int 507 tr_bool 508 508 tr_peerIoSupportsFEXT( const tr_peerIo * io ) 509 509 { … … 518 518 519 519 void 520 tr_peerIoEnableLTEP( tr_peerIo * io,521 intflag )520 tr_peerIoEnableLTEP( tr_peerIo * io, 521 tr_bool flag ) 522 522 { 523 523 assert( isPeerIo( io ) ); … … 528 528 } 529 529 530 int 530 tr_bool 531 531 tr_peerIoSupportsLTEP( const tr_peerIo * io ) 532 532 { -
trunk/libtransmission/peer-io.h
r7234 r7289 50 50 **/ 51 51 52 void tr_peerIoEnableLTEP( tr_peerIo * io, intflag );53 54 inttr_peerIoSupportsLTEP( const tr_peerIo * io );55 56 void tr_peerIoEnableFEXT( tr_peerIo * io, intflag );57 58 inttr_peerIoSupportsFEXT( const tr_peerIo * io );52 void tr_peerIoEnableLTEP( tr_peerIo * io, tr_bool flag ); 53 54 tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io ); 55 56 void tr_peerIoEnableFEXT( tr_peerIo * io, tr_bool flag ); 57 58 tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io ); 59 59 60 60 /** -
trunk/libtransmission/peer-mgr.c
r7248 r7289 300 300 } 301 301 302 static int302 static tr_bool 303 303 peerIsInUse( const Torrent * ct, 304 304 const tr_address * addr ) … … 309 309 310 310 return getExistingPeer( t, addr ) 311 312 311 || getExistingHandshake( t->outgoingHandshakes, addr ) 312 || getExistingHandshake( t->manager->incomingHandshakes, addr ); 313 313 } 314 314 … … 317 317 { 318 318 tr_peer * p; 319 320 319 p = tr_new0( tr_peer, 1 ); 321 320 p->addr = *addr; … … 487 486 488 487 static tr_peer** 489 getConnectedPeers( Torrent * t, 490 int * setmeCount ) 491 { 492 int i, peerCount, connectionCount; 488 getConnectedPeers( Torrent * t, int * setmeCount ) 489 { 490 int i, peerCount, connectionCount; 493 491 tr_peer **peers; 494 492 tr_peer **ret; … … 523 521 ***/ 524 522 525 int 526 tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,527 const uint8_t * torrentHash,528 const tr_address * addr )529 { 530 intisSeed = FALSE;531 const Torrent * 523 tr_bool 524 tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 525 const uint8_t * torrentHash, 526 const tr_address * addr ) 527 { 528 tr_bool isSeed = FALSE; 529 const Torrent * t = NULL; 532 530 const struct peer_atom * atom = NULL; 533 531 … … 593 591 594 592 static int 595 compareRefillPiece( const void * aIn, 596 const void * bIn ) 593 compareRefillPiece( const void * aIn, const void * bIn ) 597 594 { 598 595 const struct tr_refill_piece * a = aIn; … … 623 620 624 621 static tr_piece_index_t * 625 getPreferredPieces( Torrent * t, 626 tr_piece_index_t * pieceCount ) 622 getPreferredPieces( Torrent * t, tr_piece_index_t * pieceCount ) 627 623 { 628 624 const tr_torrent * tor = t->tor; … … 822 818 for( j=0; !handled && j<peerCount; ) 823 819 { 824 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length, FALSE );820 const tr_addreq_t val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length, FALSE ); 825 821 switch( val ) 826 822 { … … 1043 1039 const time_t now = time( NULL ); 1044 1040 tr_torrent * tor = t->tor; 1045 1046 1041 tor->activityDate = now; 1047 1042 … … 1073 1068 { 1074 1069 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1075 const int peerIsSeed = e->progress >= 1.0; 1076 if( peerIsSeed ) 1077 { 1078 tordbg( t, "marking peer %s as a seed", 1079 tr_peerIoAddrStr( &atom->addr, 1080 atom->port ) ); 1070 const int peerIsSeed = e->progress >= 1.0; 1071 if( peerIsSeed ) { 1072 tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1081 1073 atom->flags |= ADDED_F_SEED_FLAG; 1082 } 1083 else 1084 { 1085 tordbg( t, "marking peer %s as a non-seed", 1086 tr_peerIoAddrStr( &atom->addr, 1087 atom->port ) ); 1074 } else { 1075 tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1088 1076 atom->flags &= ~ADDED_F_SEED_FLAG; 1089 1077 } … … 1096 1084 tr_torrent * tor = t->tor; 1097 1085 1098 tr_block_index_t block = _tr_block( tor, e->pieceIndex, 1099 e->offset ); 1086 tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset ); 1100 1087 1101 1088 tr_cpBlockAdd( tor->completion, block ); … … 1107 1094 { 1108 1095 const tr_piece_index_t p = e->pieceIndex; 1109 const intok = tr_ioTestPiece( tor, p );1096 const tr_bool ok = tr_ioTestPiece( tor, p ); 1110 1097 1111 1098 if( !ok ) 1112 1099 { 1113 tr_torerr( tor, 1114 _( "Piece %lu, which was just downloaded, failed its checksum test" ), 1115 (unsigned long)p ); 1100 tr_torerr( tor, _( "Piece %lu, which was just downloaded, failed its checksum test" ), 1101 (unsigned long)p ); 1116 1102 } 1117 1103 … … 1124 1110 else 1125 1111 { 1126 int 1112 int i, peerCount; 1127 1113 tr_peer ** peers = getConnectedPeers( t, &peerCount ); 1128 1114 for( i = 0; i < peerCount; ++i ) … … 1181 1167 a->flags = flags; 1182 1168 a->from = from; 1183 tordbg( t, "got a new atom: %s", 1184 tr_peerIoAddrStr( &a->addr, a->port ) ); 1169 tordbg( t, "got a new atom: %s", tr_peerIoAddrStr( &a->addr, a->port ) ); 1185 1170 tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms ); 1186 1171 } … … 1196 1181 getPeerCount( const Torrent * t ) 1197 1182 { 1198 return tr_ptrArraySize( t->peers ) + tr_ptrArraySize( 1199 t->outgoingHandshakes ); 1183 return tr_ptrArraySize( t->peers ) + tr_ptrArraySize( t->outgoingHandshakes ); 1200 1184 } 1201 1185 1202 1186 /* FIXME: this is kind of a mess. */ 1203 static int1187 static tr_bool 1204 1188 myHandshakeDoneCB( tr_handshake * handshake, 1205 1189 tr_peerIo * io, … … 1208 1192 void * vmanager ) 1209 1193 { 1210 intok = isConnected;1211 intsuccess = FALSE;1194 tr_bool ok = isConnected; 1195 tr_bool success = FALSE; 1212 1196 tr_port port; 1213 1197 const tr_address * addr; … … 1261 1245 { 1262 1246 tordbg( t, "banned peer %s tried to reconnect", 1263 tr_peerIoAddrStr( &atom->addr, 1264 atom->port ) ); 1247 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1265 1248 tr_peerIoFree( io ); 1266 1249 } … … 1318 1301 if( tr_sessionIsAddressBlocked( manager->session, addr ) ) 1319 1302 { 1320 tr_dbg( "Banned IP address \"%s\" tried to connect to us", 1321 tr_ntop_non_ts( addr ) ); 1303 tr_dbg( "Banned IP address \"%s\" tried to connect to us", tr_ntop_non_ts( addr ) ); 1322 1304 tr_netClose( socket ); 1323 1305 } … … 1411 1393 if( tr_bitfieldHas( peer->blame, pieceIndex ) ) 1412 1394 { 1413 tordbg( 1414 t, 1415 "peer %s contributed to corrupt piece (%d); now has %d strikes", 1416 tr_peerIoAddrStr( &peer->addr, peer->port ), 1417 pieceIndex, (int)peer->strikes + 1 ); 1395 tordbg( t, "peer %s contributed to corrupt piece (%d); now has %d strikes", 1396 tr_peerIoAddrStr( &peer->addr, peer->port ), 1397 pieceIndex, (int)peer->strikes + 1 ); 1418 1398 addStrike( t, peer ); 1419 1399 } … … 1423 1403 1424 1404 int 1425 tr_pexCompare( const void * va, 1426 const void * vb ) 1405 tr_pexCompare( const void * va, const void * vb ) 1427 1406 { 1428 1407 const tr_pex * a = va; 1429 1408 const tr_pex * b = vb; 1430 int 1409 int i = tr_compareAddresses( &a->addr, &b->addr ); 1431 1410 1432 1411 if( i ) return i; … … 1436 1415 } 1437 1416 1438 int tr_pexCompare( const void * a,1439 const void * b );1440 1441 1417 static int 1442 1418 peerPrefersCrypto( const tr_peer * peer ) … … 1461 1437 managerLock( manager ); 1462 1438 1463 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );1464 if( !t)1439 t = getExistingTorrent( manager, torrentHash ); 1440 if( t == NULL ) 1465 1441 { 1466 1442 *setme_pex = NULL; … … 1473 1449 tr_pex * walk = pex; 1474 1450 1475 for( i = 0; i <peerCount; ++i, ++walk )1451 for( i=0; i<peerCount; ++i, ++walk ) 1476 1452 { 1477 1453 const tr_peer * peer = peers[i]; … … 1652 1628 tr_peer ** peers; 1653 1629 tr_bitfield * pieces; 1654 1655 1630 managerLock( manager ); 1656 1631 … … 1670 1645 const uint8_t * torrentHash ) 1671 1646 { 1672 int 1647 int ret; 1673 1648 const Torrent * t; 1674 1675 1649 managerLock( manager ); 1676 1650 1677 1651 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1678 ret = t && ( !tr_ptrArrayEmpty( t->peers ) 1679 || !tr_ptrArrayEmpty( t->webseeds ) ); 1652 ret = t && ( !tr_ptrArrayEmpty( t->peers ) || !tr_ptrArrayEmpty( t->webseeds ) ); 1680 1653 1681 1654 managerUnlock( manager ); … … 1685 1658 void 1686 1659 tr_peerMgrTorrentStats( const tr_peerMgr * manager, 1687 const uint8_t *torrentHash,1688 int *setmePeersKnown,1689 int *setmePeersConnected,1690 int *setmeSeedsConnected,1691 int *setmeWebseedsSendingToUs,1692 int *setmePeersSendingToUs,1693 int *setmePeersGettingFromUs,1694 int *setmePeersFrom )1695 { 1696 int 1697 const Torrent * 1698 const tr_peer ** 1660 const uint8_t * torrentHash, 1661 int * setmePeersKnown, 1662 int * setmePeersConnected, 1663 int * setmeSeedsConnected, 1664 int * setmeWebseedsSendingToUs, 1665 int * setmePeersSendingToUs, 1666 int * setmePeersGettingFromUs, 1667 int * setmePeersFrom ) 1668 { 1669 int i, size; 1670 const Torrent * t; 1671 const tr_peer ** peers; 1699 1672 const tr_webseed ** webseeds; 1700 1673 … … 1711 1684 *setmeWebseedsSendingToUs = 0; 1712 1685 1713 for( i = 0; i <TR_PEER_FROM__MAX; ++i )1686 for( i=0; i<TR_PEER_FROM__MAX; ++i ) 1714 1687 setmePeersFrom[i] = 0; 1715 1688 1716 for( i = 0; i <size; ++i )1717 { 1718 const tr_peer * 1689 for( i=0; i<size; ++i ) 1690 { 1691 const tr_peer * peer = peers[i]; 1719 1692 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1720 1693 … … 1722 1695 continue; 1723 1696 1724 ++ *setmePeersConnected;1697 ++*setmePeersConnected; 1725 1698 1726 1699 ++setmePeersFrom[atom->from]; 1727 1700 1728 1701 if( clientIsDownloadingFrom( peer ) ) 1729 ++ *setmePeersSendingToUs;1702 ++*setmePeersSendingToUs; 1730 1703 1731 1704 if( clientIsUploadingTo( peer ) ) 1732 ++ *setmePeersGettingFromUs;1705 ++*setmePeersGettingFromUs; 1733 1706 1734 1707 if( atom->flags & ADDED_F_SEED_FLAG ) 1735 ++ *setmeSeedsConnected;1708 ++*setmeSeedsConnected; 1736 1709 } 1737 1710 1738 1711 webseeds = (const tr_webseed **) tr_ptrArrayPeek( t->webseeds, &size ); 1739 for( i = 0; i <size; ++i )1712 for( i=0; i<size; ++i ) 1740 1713 { 1741 1714 if( tr_webseedIsActive( webseeds[i] ) ) 1742 ++ *setmeWebseedsSendingToUs;1715 ++*setmeWebseedsSendingToUs; 1743 1716 } 1744 1717 … … 1750 1723 const uint8_t * torrentHash ) 1751 1724 { 1752 const Torrent * 1725 const Torrent * t; 1753 1726 const tr_webseed ** webseeds; 1754 int 1755 int 1756 float * 1727 int i; 1728 int webseedCount; 1729 float * ret; 1757 1730 1758 1731 assert( manager ); … … 1765 1738 ret = tr_new0( float, webseedCount ); 1766 1739 1767 for( i = 0; i <webseedCount; ++i )1740 for( i=0; i<webseedCount; ++i ) 1768 1741 if( !tr_webseedGetSpeed( webseeds[i], &ret[i] ) ) 1769 1742 ret[i] = -1.0; … … 1774 1747 1775 1748 double 1776 tr_peerGetPieceSpeed( const tr_peer * peer, 1777 tr_direction direction ) 1749 tr_peerGetPieceSpeed( const tr_peer * peer, tr_direction direction ) 1778 1750 { 1779 1751 assert( peer ); … … 1808 1780 tr_peer_stat * stat = ret + i; 1809 1781 1810 tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) ); 1811 tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ), 1812 sizeof( stat->client ) ); 1782 tr_ntop( &peer->addr, stat->addr, sizeof(stat->addr) ); 1783 tr_strlcpy( stat->client, (peer->client ? peer->client : ""), sizeof(stat->client) ); 1813 1784 stat->port = ntohs( peer->port ); 1814 1785 stat->from = atom->from; … … 1832 1803 if( stat->isUploadingTo ) *pch++ = 'U'; 1833 1804 else if( stat->peerIsInterested ) *pch++ = 'u'; 1834 if( !stat->clientIsChoked && !stat->clientIsInterested ) *pch++ = 1835 'K'; 1805 if( !stat->clientIsChoked && !stat->clientIsInterested ) *pch++ = 'K'; 1836 1806 if( !stat->peerIsChoked && !stat->peerIsInterested ) *pch++ = '?'; 1837 1807 if( stat->isEncrypted ) *pch++ = 'E'; … … 1947 1917 */ 1948 1918 unchokedInterested = 0; 1949 for( i = 0; i < size && unchokedInterested < MAX_UNCHOKED_PEERS; ++i ) 1950 { 1919 for( i=0; i<size && unchokedInterested<MAX_UNCHOKED_PEERS; ++i ) { 1951 1920 choke[i].doUnchoke = 1; 1952 1921 if( choke[i].isInterested ) … … 1957 1926 if( i < size ) 1958 1927 { 1959 int 1928 int n; 1960 1929 struct ChokeData * c; 1961 tr_ptrArray * 1962 1963 for( ; i <size; ++i )1930 tr_ptrArray * randPool = tr_ptrArrayNew( ); 1931 1932 for( ; i<size; ++i ) 1964 1933 { 1965 1934 if( choke[i].isInterested ) 1966 1935 { 1967 1936 const tr_peer * peer = choke[i].peer; 1968 int 1937 int x = 1, y; 1969 1938 if( isNew( peer ) ) x *= 3; 1970 1939 if( isSame( peer ) ) x *= 3; 1971 for( y = 0; y <x; ++y )1940 for( y=0; y<x; ++y ) 1972 1941 tr_ptrArrayAppend( randPool, &choke[i] ); 1973 1942 } 1974 1943 } 1975 1944 1976 if( ( n = tr_ptrArraySize( randPool ) ))1945 if(( n = tr_ptrArraySize( randPool ))) 1977 1946 { 1978 c = tr_ptrArrayNth( randPool, tr_cryptoWeakRandInt( n ) 1947 c = tr_ptrArrayNth( randPool, tr_cryptoWeakRandInt( n )); 1979 1948 c->doUnchoke = 1; 1980 1949 t->optimistic = c->peer; … … 2022 1991 { 2023 1992 tordbg( t, "purging peer %s because its doPurge flag is set", 2024 tr_peerIoAddrStr( &atom->addr, 2025 atom->port ) ); 1993 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2026 1994 return TRUE; 2027 1995 } … … 2036 2004 else if( peer->progress < tr_cpPercentDone( tor->completion ) ) 2037 2005 peerHasEverything = FALSE; 2038 else 2039 { 2040 tr_bitfield * tmp = 2041 tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) ); 2006 else { 2007 tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) ); 2042 2008 tr_bitfieldDifference( tmp, peer->have ); 2043 2009 peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0; 2044 2010 tr_bitfieldFree( tmp ); 2045 2011 } 2046 if( peerHasEverything 2047 && ( !tr_torrentAllowsPex( tor ) || ( now - atom->time >= 30 ) ) ) 2048 { 2012 if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 ))) { 2049 2013 tordbg( t, "purging peer %s because we're both seeds", 2050 tr_peerIoAddrStr( &atom->addr, 2051 atom->port ) ); 2014 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2052 2015 return TRUE; 2053 2016 } … … 2057 2020 * this is on a sliding scale based on number of available peers... */ 2058 2021 { 2059 const int relaxStrictnessIfFewerThanN = 2060 (int)( ( getMaxPeerCount( tor ) * 0.9 ) + 0.5 ); 2022 const int relaxStrictnessIfFewerThanN = (int)( ( getMaxPeerCount( tor ) * 0.9 ) + 0.5 ); 2061 2023 /* if we have >= relaxIfFewerThan, strictness is 100%. 2062 2024 * if we have zero connections, strictness is 0% */ 2063 const float strictness = peerCount >= relaxStrictnessIfFewerThanN 2064 ? 1.0 2065 : peerCount / 2066 (float)relaxStrictnessIfFewerThanN; 2067 const int lo = MIN_UPLOAD_IDLE_SECS; 2068 const int hi = MAX_UPLOAD_IDLE_SECS; 2069 const int limit = lo + ( ( hi - lo ) * strictness ); 2025 const float strictness = peerCount >= relaxStrictnessIfFewerThanN 2026 ? 1.0 2027 : peerCount / (float)relaxStrictnessIfFewerThanN; 2028 const int lo = MIN_UPLOAD_IDLE_SECS; 2029 const int hi = MAX_UPLOAD_IDLE_SECS; 2030 const int limit = lo + ( ( hi - lo ) * strictness ); 2070 2031 const time_t then = peer->pieceDataActivityDate; 2071 const int idleTime = then ? ( now - then ) : 0; 2072 if( idleTime > limit ) 2073 { 2074 tordbg( 2075 t, 2076 "purging peer %s because it's been %d secs since we shared anything", 2077 tr_peerIoAddrStr( &atom->addr, atom->port ), idleTime ); 2032 const int idleTime = then ? ( now - then ) : 0; 2033 if( idleTime > limit ) { 2034 tordbg( t, "purging peer %s because it's been %d secs since we shared anything", 2035 tr_peerIoAddrStr( &atom->addr, atom->port ), idleTime ); 2078 2036 return TRUE; 2079 2037 } … … 2084 2042 2085 2043 static tr_peer ** 2086 getPeersToClose( Torrent * t, 2087 int * setmeSize ) 2088 { 2089 int i, peerCount, outsize; 2090 tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, 2091 &peerCount ); 2044 getPeersToClose( Torrent * t, int * setmeSize ) 2045 { 2046 int i, peerCount, outsize; 2047 tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount ); 2092 2048 struct tr_peer ** ret = tr_new( tr_peer *, peerCount ); 2093 2049 … … 2142 2098 * data, try to reconnect to them sooner rather that later -- we don't 2143 2099 * want network troubles to get in the way of a good peer. */ 2144 if( ( now - atom->piece_data_time ) <= 2145 ( MINIMUM_RECONNECT_INTERVAL_SECS * 2 ) ) 2100 if( ( now - atom->piece_data_time ) <= ( MINIMUM_RECONNECT_INTERVAL_SECS * 2 ) ) 2146 2101 sec = MINIMUM_RECONNECT_INTERVAL_SECS; 2147 2102 … … 2152 2107 /* otherwise, the interval depends on how many times we've tried 2153 2108 * and failed to connect to the peer */ 2154 else switch( atom->numFails ) 2155 { 2156 case 0: 2157 sec = 0; break; 2158 2159 case 1: 2160 sec = 5; break; 2161 2162 case 2: 2163 sec = 2 * 60; break; 2164 2165 case 3: 2166 sec = 15 * 60; break; 2167 2168 case 4: 2169 sec = 30 * 60; break; 2170 2171 case 5: 2172 sec = 60 * 60; break; 2173 2174 default: 2175 sec = 120 * 60; break; 2176 } 2109 else switch( atom->numFails ) { 2110 case 0: sec = 0; break; 2111 case 1: sec = 5; break; 2112 case 2: sec = 2 * 60; break; 2113 case 3: sec = 15 * 60; break; 2114 case 4: sec = 30 * 60; break; 2115 case 5: sec = 60 * 60; break; 2116 default: sec = 120 * 60; break; 2117 } 2177 2118 2178 2119 return sec; … … 2180 2121 2181 2122 static struct peer_atom ** 2182 getPeerCandidates( Torrent * t, 2183 int * setmeSize ) 2123 getPeerCandidates( Torrent * t, int * setmeSize ) 2184 2124 { 2185 2125 int i, atomCount, retCount; … … 2222 2162 if( ( now - atom->time ) < interval ) 2223 2163 { 2224 tordbg( 2225 t, 2226 "RECONNECT peer %d (%s) is in its grace period of %d seconds..", 2227 i, tr_peerIoAddrStr( &atom->addr, 2228 atom->port ), interval ); 2164 tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..", 2165 i, tr_peerIoAddrStr( &atom->addr, atom->port ), interval ); 2229 2166 continue; 2230 2167 } … … 2265 2202 else 2266 2203 { 2267 int 2204 int i, nCandidates, nBad; 2268 2205 struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates ); 2269 struct tr_peer ** 2206 struct tr_peer ** connections = getPeersToClose( t, &nBad ); 2270 2207 2271 2208 if( nBad || nCandidates ) 2272 tordbg( 2273 t, "reconnect pulse for [%s]: %d bad connections, " 2209 tordbg( t, "reconnect pulse for [%s]: %d bad connections, " 2274 2210 "%d connection candidates, %d atoms, max per pulse is %d", 2275 t->tor->info.name, nBad, nCandidates,2276 tr_ptrArraySize( t->pool ),2277 (int)MAX_RECONNECTIONS_PER_PULSE );2211 t->tor->info.name, nBad, nCandidates, 2212 tr_ptrArraySize( t->pool ), 2213 (int)MAX_RECONNECTIONS_PER_PULSE ); 2278 2214 2279 2215 /* disconnect some peers. … … 2281 2217 so reset their `numFails' weight to zero. otherwise we connected 2282 2218 to them fruitlessly, so mark it as another fail */ 2283 for( i = 0; i < nBad; ++i ) 2284 { 2285 tr_peer * peer = connections[i]; 2219 for( i = 0; i < nBad; ++i ) { 2220 tr_peer * peer = connections[i]; 2286 2221 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 2287 2222 if( peer->pieceDataActivityDate ) … … 2289 2224 else 2290 2225 ++atom->numFails; 2291 tordbg( t, "removing bad peer %s", 2292 tr_peerIoGetAddrStr( peer->io ) ); 2226 tordbg( t, "removing bad peer %s", tr_peerIoGetAddrStr( peer->io ) ); 2293 2227 removePeer( t, peer ); 2294 2228 } … … 2298 2232 && ( i < MAX_RECONNECTIONS_PER_PULSE ) 2299 2233 && ( getPeerCount( t ) < getMaxPeerCount( t->tor ) ) 2300 && ( newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND ); 2301 ++i ) 2234 && ( newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND ); ++i ) 2302 2235 { 2303 2236 tr_peerMgr * mgr = t->manager; … … 2308 2241 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2309 2242 2310 io = 2311 tr_peerIoNewOutgoing( mgr->session, &atom->addr, atom->port, 2312 t->hash ); 2243 io = tr_peerIoNewOutgoing( mgr->session, &atom->addr, atom->port, t->hash ); 2313 2244 if( io == NULL ) 2314 2245 { … … 2317 2248 else 2318 2249 { 2319 tr_handshake * handshake = tr_handshakeNew( 2320 io, 2321 mgr->session-> 2322 encryptionMode, 2323 myHandshakeDoneCB, 2324 mgr ); 2250 tr_handshake * handshake = tr_handshakeNew( io, 2251 mgr->session->encryptionMode, 2252 myHandshakeDoneCB, 2253 mgr ); 2325 2254 2326 2255 assert( tr_peerIoGetTorrentHash( io ) ); -
trunk/libtransmission/peer-mgr.h
r7231 r7289 54 54 void tr_peerMgrFree( tr_peerMgr * manager ); 55 55 56 inttr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,57 const uint8_t * torrentHash,58 const tr_address * addr );56 tr_bool tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 57 const uint8_t * torrentHash, 58 const tr_address * addr ); 59 59 60 60 void tr_peerMgrAddIncoming( tr_peerMgr * manager, -
trunk/libtransmission/peer-msgs.c
r7274 r7289 123 123 124 124 static int 125 compareRequest( const void * va, 126 const void * vb ) 125 compareRequest( const void * va, const void * vb ) 127 126 { 128 127 const struct peer_request * a = va; … … 171 170 172 171 static void 173 reqListCopy( struct request_list * dest, 174 const struct request_list * src ) 172 reqListCopy( struct request_list * dest, const struct request_list * src ) 175 173 { 176 174 dest->count = dest->max = src->count; 177 dest->requests = 178 tr_memdup( src->requests, dest->count * sizeof( struct peer_request ) ); 175 dest->requests = tr_memdup( src->requests, dest->count * sizeof( struct peer_request ) ); 179 176 } 180 177 … … 186 183 187 184 memmove( &list->requests[i], 188 &list->requests[i + 1],189 sizeof( struct peer_request ) * ( --list->count - i ) );185 &list->requests[i + 1], 186 sizeof( struct peer_request ) * ( --list->count - i ) ); 190 187 } 191 188 … … 317 314 318 315 static void 319 myDebug( const char * file, 320 int line, 316 myDebug( const char * file, int line, 321 317 const struct tr_peermsgs * msgs, 322 const char * fmt, 323 ... ) 318 const char * fmt, ... ) 324 319 { 325 320 FILE * fp = tr_getLog( ); … … 517 512 518 513 static void 519 publish( tr_peermsgs * msgs, 520 tr_peer_event * e ) 514 publish( tr_peermsgs * msgs, tr_peer_event * e ) 521 515 { 522 516 assert( msgs->info ); … … 527 521 528 522 static void 529 fireError( tr_peermsgs * msgs, 530 int err ) 523 fireError( tr_peermsgs * msgs, int err ) 531 524 { 532 525 tr_peer_event e = blankEvent; 533 534 526 e.eventType = TR_PEER_ERROR; 535 527 e.err = err; … … 558 550 { 559 551 tr_peer_event e = blankEvent; 560 561 552 e.eventType = TR_PEER_PEER_PROGRESS; 562 553 e.progress = msgs->info->progress; … … 565 556 566 557 static void 567 fireGotBlock( tr_peermsgs * msgs, 568 const struct peer_request * req ) 558 fireGotBlock( tr_peermsgs * msgs, const struct peer_request * req ) 569 559 { 570 560 tr_peer_event e = blankEvent; 571 572 561 e.eventType = TR_PEER_CLIENT_GOT_BLOCK; 573 562 e.pieceIndex = req->index; … … 692 681 { 693 682 #if 0 694 const intfext = tr_peerIoSupportsFEXT( msgs->io );683 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->io ); 695 684 const int peerIsNeedy = msgs->info->progress < 0.10; 696 685 … … 724 713 725 714 return ( !torrent->info.pieces[piece].dnd ) /* we want it */ 726 && ( !tr_cpPieceIsComplete( torrent->completion, piece ) ) /* !have 727 */ 728 && ( tr_bitfieldHas( peer->info->have, piece ) ); /* peer has it */ 715 && ( !tr_cpPieceIsComplete( torrent->completion, piece ) ) /* !have */ 716 && ( tr_bitfieldHas( peer->info->have, piece ) ); /* peer has it */ 729 717 } 730 718 … … 769 757 770 758 msgs->info->clientIsInterested = weAreInterested; 771 dbgmsg( msgs, "Sending %s", 772 weAreInterested ? "Interested" : "Not Interested" ); 759 dbgmsg( msgs, "Sending %s", weAreInterested ? "Interested" : "Not Interested" ); 773 760 tr_peerIoWriteUint32( msgs->io, out, sizeof( uint8_t ) ); 774 tr_peerIoWriteUint8 ( 775 msgs->io, out, weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED ); 761 tr_peerIoWriteUint8 ( msgs->io, out, weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED ); 776 762 pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS ); 777 dbg msg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH( out ));763 dbgOutMessageLen( msgs ); 778 764 } 779 765 … … 820 806 if( msgs->info->chokeChangedAt > fibrillationTime ) 821 807 { 822 dbgmsg( msgs, "Not changing choke to %d to avoid fibrillation", 823 choke ); 808 dbgmsg( msgs, "Not changing choke to %d to avoid fibrillation", choke ); 824 809 } 825 810 else if( msgs->info->peerIsChoked != choke ) … … 869 854 expireOldRequests( tr_peermsgs * msgs, const time_t now ) 870 855 { 871 int 872 time_t 856 int i; 857 time_t oldestAllowed; 873 858 struct request_list tmp = REQUEST_LIST_INIT; 874 const intfext = tr_peerIoSupportsFEXT( msgs->io );859 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->io ); 875 860 876 861 /* cancel requests that have been queued for too long */ … … 916 901 while( ( count < max ) && reqListPop( &msgs->clientWillAskFor, &req ) ) 917 902 { 918 const tr_block_index_t block = 919 _tr_block( msgs->torrent, req.index, req.offset ); 903 const tr_block_index_t block = _tr_block( msgs->torrent, req.index, req.offset ); 920 904 921 905 assert( requestIsValid( msgs, &req ) ); … … 936 920 937 921 if( sent ) 938 dbgmsg( msgs, 939 "pump sent %d requests, now have %d active and %d queued", 922 dbgmsg( msgs, "pump sent %d requests, now have %d active and %d queued", 940 923 sent, 941 924 msgs->clientAskedFor.count, … … 1015 998 cancelAllRequestsToPeer( tr_peermsgs * msgs, tr_bool sendCancel ) 1016 999 { 1017 int 1000 int i; 1018 1001 struct request_list a = msgs->clientWillAskFor; 1019 1002 struct request_list b = msgs->clientAskedFor; … … 1075 1058 sendLtepHandshake( tr_peermsgs * msgs ) 1076 1059 { 1077 tr_benc 1078 char * 1079 int 1080 int 1060 tr_benc val, *m; 1061 char * buf; 1062 int len; 1063 int pex; 1081 1064 struct evbuffer * out = msgs->outMessages; 1082 1065 … … 1095 1078 pex = 1; 1096 1079 1097 tr_bencInitDict( &val, 4);1080 tr_bencInitDict( &val, 5 ); 1098 1081 tr_bencDictAddInt( &val, "e", msgs->session->encryptionMode != TR_CLEAR_PREFERRED ); 1099 1082 tr_bencDictAddInt( &val, "p", tr_sessionGetPeerPort( msgs->session ) ); … … 1110 1093 tr_peerIoWriteBytes ( msgs->io, out, buf, len ); 1111 1094 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 1112 dbg msg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH( out ));1095 dbgOutMessageLen( msgs ); 1113 1096 1114 1097 /* cleanup */ … … 1129 1112 msgs->peerSentLtepHandshake = 1; 1130 1113 1131 if( tr_bencLoad( tmp, len, &val, NULL ) || val.type != TYPE_DICT)1114 if( tr_bencLoad( tmp, len, &val, NULL ) || !tr_bencIsDict( &val ) ) 1132 1115 { 1133 1116 dbgmsg( msgs, "GET extended-handshake, couldn't get dictionary" ); … … 1141 1124 if( tr_bencDictFindInt( &val, "e", &i ) ) 1142 1125 msgs->info->encryption_preference = i ? ENCRYPTION_PREFERENCE_YES 1143 : ENCRYPTION_PREFERENCE_NO;1126 : ENCRYPTION_PREFERENCE_NO; 1144 1127 1145 1128 /* check supported messages for utorrent pex */ 1146 1129 msgs->peerSupportsPex = 0; 1147 if( tr_bencDictFindDict( &val, "m", &sub ) ) 1148 { 1149 if( tr_bencDictFindInt( sub, "ut_pex", &i ) ) 1150 { 1130 if( tr_bencDictFindDict( &val, "m", &sub ) ) { 1131 if( tr_bencDictFindInt( sub, "ut_pex", &i ) ) { 1151 1132 msgs->ut_pex_id = (uint8_t) i; 1152 1133 msgs->peerSupportsPex = msgs->ut_pex_id == 0 ? 0 : 1; … … 1160 1141 1161 1142 /* get peer's listening port */ 1162 if( tr_bencDictFindInt( &val, "p", &i ) ) 1163 { 1143 if( tr_bencDictFindInt( &val, "p", &i ) ) { 1164 1144 msgs->info->port = htons( (uint16_t)i ); 1165 1145 dbgmsg( msgs, "msgs->port is now %hu", msgs->info->port ); … … 1171 1151 1172 1152 static void 1173 parseUtPex( tr_peermsgs * msgs, 1174 int msglen, 1175 struct evbuffer * inbuf ) 1176 { 1177 int loaded = 0; 1178 uint8_t * tmp = tr_new( uint8_t, msglen ); 1179 tr_benc val; 1153 parseUtPex( tr_peermsgs * msgs, int msglen, struct evbuffer * inbuf ) 1154 { 1155 int loaded = 0; 1156 uint8_t * tmp = tr_new( uint8_t, msglen ); 1157 tr_benc val; 1180 1158 const tr_torrent * tor = msgs->torrent; 1181 const uint8_t * 1182 size_t 1159 const uint8_t * added; 1160 size_t added_len; 1183 1161 1184 1162 tr_peerIoReadBytes( msgs->io, inbuf, tmp, msglen ); 1185 1163 1186 1164 if( tr_torrentAllowsPex( tor ) 1187 && ( ( loaded = !tr_bencLoad( tmp, msglen, &val, NULL ) ))1188 && tr_bencDictFindRaw( &val, "added", &added, &added_len ) 1165 && (( loaded = !tr_bencLoad( tmp, msglen, &val, NULL ))) 1166 && tr_bencDictFindRaw( &val, "added", &added, &added_len )) 1189 1167 { 1190 1168 const uint8_t * added_f = NULL; … … 1193 1171 size_t added_f_len = 0; 1194 1172 tr_bencDictFindRaw( &val, "added.f", &added_f, &added_f_len ); 1195 pex = 1196 tr_peerMgrCompactToPex( added, added_len, added_f, added_f_len, 1197 &n ); 1198 for( i = 0; i < n; ++i ) 1173 pex = tr_peerMgrCompactToPex( added, added_len, added_f, added_f_len, &n ); 1174 for( i=0; i<n; ++i ) 1199 1175 tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash, 1200 1176 TR_PEER_FROM_PEX, pex + i ); … … 1309 1285 const struct peer_request * req ) 1310 1286 { 1311 const intfext = tr_peerIoSupportsFEXT( msgs->io );1287 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->io ); 1312 1288 const int reqIsValid = requestIsValid( msgs, req ); 1313 1289 const int clientHasPiece = reqIsValid && tr_cpPieceIsComplete( msgs->torrent->completion, req->index ); … … 1332 1308 1333 1309 static int 1334 messageLengthIsCorrect( const tr_peermsgs * msg, 1335 uint8_t id, 1336 uint32_t len ) 1310 messageLengthIsCorrect( const tr_peermsgs * msg, uint8_t id, uint32_t len ) 1337 1311 { 1338 1312 switch( id ) … … 1396 1370 tr_peerIoReadUint32( msgs->io, inbuf, &req->offset ); 1397 1371 req->length = msgs->incoming.length - 9; 1398 dbgmsg( msgs, "got incoming block header %u:%u->%u", req->index, 1399 req->offset, 1400 req->length ); 1372 dbgmsg( msgs, "got incoming block header %u:%u->%u", req->index, req->offset, req->length ); 1401 1373 return READ_NOW; 1402 1374 } 1403 1375 else 1404 1376 { 1405 int 1377 int err; 1406 1378 1407 1379 /* read in another chunk of data */ 1408 const size_t nLeft = req->length - EVBUFFER_LENGTH( 1409 msgs->incoming.block ); 1410 size_t n = MIN( nLeft, inlen ); 1411 uint8_t * buf = tr_new( uint8_t, n ); 1380 const size_t nLeft = req->length - EVBUFFER_LENGTH( msgs->incoming.block ); 1381 size_t n = MIN( nLeft, inlen ); 1382 uint8_t * buf = tr_new( uint8_t, n ); 1412 1383 assert( EVBUFFER_LENGTH( inbuf ) >= n ); 1413 1384 tr_peerIoReadBytes( msgs->io, inbuf, buf, n ); … … 1416 1387 *setme_piece_bytes_read += n; 1417 1388 tr_free( buf ); 1418 dbgmsg( msgs, "got % dbytes for block %u:%u->%u ... %d remain",1419 (int)n, req->index, req->offset, req->length,1389 dbgmsg( msgs, "got %zu bytes for block %u:%u->%u ... %d remain", 1390 n, req->index, req->offset, req->length, 1420 1391 (int)( req->length - EVBUFFER_LENGTH( msgs->incoming.block ) ) ); 1421 1392 if( EVBUFFER_LENGTH( msgs->incoming.block ) < req->length ) … … 1423 1394 1424 1395 /* we've got the whole block ... process it */ 1425 err = clientGotBlock( msgs, EVBUFFER_DATA( 1426 msgs->incoming.block ), req ); 1396 err = clientGotBlock( msgs, EVBUFFER_DATA( msgs->incoming.block ), req ); 1427 1397 1428 1398 /* cleanup */ 1429 evbuffer_drain( msgs->incoming.block, 1430 EVBUFFER_LENGTH( msgs->incoming.block ) ); 1399 evbuffer_drain( msgs->incoming.block, EVBUFFER_LENGTH( msgs->incoming.block ) ); 1431 1400 req->length = 0; 1432 1401 msgs->state = AWAITING_BT_LENGTH; 1433 1402 if( !err ) 1434 1403 return READ_NOW; 1435 else 1436 { 1404 else { 1437 1405 fireError( msgs, err ); 1438 1406 return READ_ERR; … … 1442 1410 1443 1411 static int 1444 readBtMessage( tr_peermsgs * msgs, 1445 struct evbuffer * inbuf, 1446 size_t inlen ) 1412 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) 1447 1413 { 1448 1414 uint32_t ui32; … … 1450 1416 const uint8_t id = msgs->incoming.id; 1451 1417 const size_t startBufLen = EVBUFFER_LENGTH( inbuf ); 1452 const intfext = tr_peerIoSupportsFEXT( msgs->io );1418 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->io ); 1453 1419 1454 1420 --msglen; /* id length */ … … 1457 1423 return READ_LATER; 1458 1424 1459 dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, 1460 (int)msglen, 1461 (int)inlen ); 1425 dbgmsg( msgs, "got BT id %d, len %d, buffer size is %zu", (int)id, (int)msglen, inlen ); 1462 1426 1463 1427 if( !messageLengthIsCorrect( msgs, id, msglen + 1 ) ) 1464 1428 { 1465 dbgmsg( msgs, "bad packet - BT message #%d with a length of %d", 1466 (int)id, (int)msglen ); 1429 dbgmsg( msgs, "bad packet - BT message #%d with a length of %d", (int)id, (int)msglen ); 1467 1430 fireError( msgs, EMSGSIZE ); 1468 1431 return READ_ERR; … … 1497 1460 tr_peerIoReadUint32( msgs->io, inbuf, &ui32 ); 1498 1461 dbgmsg( msgs, "got Have: %u", ui32 ); 1499 if( tr_bitfieldAdd( msgs->info->have, ui32 ) ) 1500 { 1462 if( tr_bitfieldAdd( msgs->info->have, ui32 ) ) { 1501 1463 fireError( msgs, ERANGE ); 1502 1464 return READ_ERR; … … 1511 1473 dbgmsg( msgs, "got a bitfield" ); 1512 1474 msgs->peerSentBitfield = 1; 1513 tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, 1514 msglen ); 1475 tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen ); 1515 1476 updatePeerProgress( msgs ); 1516 1477 fireNeedReq( msgs ); … … 1630 1591 1631 1592 static void 1632 decrementDownloadedCount( tr_peermsgs * msgs, 1633 uint32_t byteCount ) 1593 decrementDownloadedCount( tr_peermsgs * msgs, uint32_t byteCount ) 1634 1594 { 1635 1595 tr_torrent * tor = msgs->torrent; … … 1639 1599 1640 1600 static void 1641 clientGotUnwantedBlock( tr_peermsgs * msgs, 1642 const struct peer_request * req ) 1601 clientGotUnwantedBlock( tr_peermsgs * msgs, const struct peer_request * req ) 1643 1602 { 1644 1603 decrementDownloadedCount( msgs, req->length ); … … 1646 1605 1647 1606 static void 1648 addPeerToBlamefield( tr_peermsgs * msgs, 1649 uint32_t index ) 1607 addPeerToBlamefield( tr_peermsgs * msgs, uint32_t index ) 1650 1608 { 1651 1609 if( !msgs->info->blame ) 1652 msgs->info->blame = tr_bitfieldNew( msgs->torrent->info.pieceCount );1610 msgs->info->blame = tr_bitfieldNew( msgs->torrent->info.pieceCount ); 1653 1611 tr_bitfieldAdd( msgs->info->blame, index ); 1654 1612 } … … 1660 1618 const struct peer_request * req ) 1661 1619 { 1662 int 1663 tr_torrent * 1620 int err; 1621 tr_torrent * tor = msgs->torrent; 1664 1622 const tr_block_index_t block = _tr_block( tor, req->index, req->offset ); 1665 1623 … … 1667 1625 assert( req ); 1668 1626 1669 if( req->length != tr_torBlockCountBytes( msgs->torrent, block ) ) 1670 { 1627 if( req->length != tr_torBlockCountBytes( msgs->torrent, block ) ) { 1671 1628 dbgmsg( msgs, "wrong block size -- expected %u, got %d", 1672 1629 tr_torBlockCountBytes( msgs->torrent, block ), req->length ); … … 1675 1632 1676 1633 /* save the block */ 1677 dbgmsg( msgs, "got block %u:%u->%u", req->index, req->offset, 1678 req->length ); 1634 dbgmsg( msgs, "got block %u:%u->%u", req->index, req->offset, req->length ); 1679 1635 1680 1636 /** … … 1682 1638 **/ 1683 1639 1684 if( !reqListRemove( &msgs->clientAskedFor, req ) ) 1685 { 1640 if( !reqListRemove( &msgs->clientAskedFor, req ) ) { 1686 1641 clientGotUnwantedBlock( msgs, req ); 1687 1642 dbgmsg( msgs, "we didn't ask for this message..." ); … … 1696 1651 **/ 1697 1652 1698 if( tr_cpBlockIsComplete( tor->completion, block ) ) 1699 { 1653 if( tr_cpBlockIsComplete( tor->completion, block ) ) { 1700 1654 dbgmsg( msgs, "we have this block already..." ); 1701 1655 clientGotUnwantedBlock( msgs, req ); … … 1788 1742 struct peer_request req; 1789 1743 const int haveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0; 1790 const intfext = tr_peerIoSupportsFEXT( msgs->io );1744 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->io ); 1791 1745 1792 1746 /** … … 1947 1901 tr_peerIoWriteUint8 ( msgs->io, out, BT_BITFIELD ); 1948 1902 tr_peerIoWriteBytes ( msgs->io, out, field->bits, field->byteCount ); 1949 dbgmsg( msgs, "sending bitfield... outMessage size is now % d",1950 (int)EVBUFFER_LENGTH( out ) );1903 dbgmsg( msgs, "sending bitfield... outMessage size is now %zu", 1904 EVBUFFER_LENGTH( out ) ); 1951 1905 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 1952 1906 … … 1960 1914 tellPeerWhatWeHave( tr_peermsgs * msgs ) 1961 1915 { 1962 const intfext = tr_peerIoSupportsFEXT( msgs->io );1916 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->io ); 1963 1917 1964 1918 if( fext && ( tr_cpGetStatus( msgs->torrent->completion ) == TR_SEED ) ) -
trunk/libtransmission/webseed.c
r7238 r7289 66 66 { 67 67 tr_peer_event e = blankEvent; 68 69 68 e.eventType = TR_PEER_NEED_REQ; 70 69 publish( w, &e ); … … 72 71 73 72 static void 74 fireClientGotBlock( tr_webseed * w, 75 uint32_t pieceIndex, 76 uint32_t offset, 77 uint32_t length ) 73 fireClientGotBlock( tr_webseed * w, uint32_t pieceIndex, uint32_t offset, uint32_t length ) 78 74 { 79 75 tr_peer_event e = blankEvent; 80 81 76 e.eventType = TR_PEER_CLIENT_GOT_BLOCK; 82 77 e.pieceIndex = pieceIndex; … … 87 82 88 83 static void 89 fireClientGotData( tr_webseed * w, 90 uint32_t length ) 84 fireClientGotData( tr_webseed * w, uint32_t length ) 91 85 { 92 86 tr_peer_event e = blankEvent; 93 94 87 e.eventType = TR_PEER_CLIENT_GOT_DATA; 95 88 e.length = length; 96 89 e.wasPieceData = TRUE; 97 98 90 publish( w, &e ); 99 91 } … … 125 117 switch( *str ) 126 118 { 127 case ',': 128 case '-': 129 case '.': 130 case '/': 131 case '0': 132 case '1': 133 case '2': 134 case '3': 135 case '4': 136 case '5': 137 case '6': 138 case '7': 139 case '8': 140 case '9': 141 case 'a': 142 case 'b': 143 case 'c': 144 case 'd': 145 case 'e': 146 case 'f': 147 case 'g': 148 case 'h': 149 case 'i': 150 case 'j': 151 case 'k': 152 case 'l': 153 case 'm': 154 case 'n': 155 case 'o': 156 case 'p': 157 case 'q': 158 case 'r': 159 case 's': 160 case 't': 161 case 'u': 162 case 'v': 163 case 'w': 164 case 'x': 165 case 'y': 166 case 'z': 167 case 'A': 168 case 'B': 169 case 'C': 170 case 'D': 171 case 'E': 172 case 'F': 173 case 'G': 174 case 'H': 175 case 'I': 176 case 'J': 177 case 'K': 178 case 'L': 179 case 'M': 180 case 'N': 181 case 'O': 182 case 'P': 183 case 'Q': 184 case 'R': 185 case 'S': 186 case 'T': 187 case 'U': 188 case 'V': 189 case 'W': 190 case 'X': 191 case 'Y': 192 case 'Z': 119 case ',': case '-': case '.': case '/': 120 case '0': case '1': case '2': case '3': case '4': 121 case '5': case '6': case '7': case '8': case '9': 122 case 'a': case 'b': case 'c': case 'd': case 'e': 123 case 'f': case 'g': case 'h': case 'i': case 'j': 124 case 'k': case 'l': case 'm': case 'n': case 'o': 125 case 'p': case 'q': case 'r': case 's': case 't': 126 case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': 127 case 'A': case 'B': case 'C': case 'D': case 'E': 128 case 'F': case 'G': case 'H': case 'I': case 'J': 129 case 'K': case 'L': case 'M': case 'N': case 'O': 130 case 'P': case 'Q': case 'R': case 'S': case 'T': 131 case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': 193 132 evbuffer_add( out, str, 1 ); 194 133 break; 195 196 134 default: 197 135 evbuffer_add_printf( out, "%%%02X", *str ); … … 315 253 316 254 int 317 tr_webseedGetSpeed( const tr_webseed * w, 318 float * setme_KiBs ) 255 tr_webseedGetSpeed( const tr_webseed * w, float * setme_KiBs ) 319 256 { 320 257 const int isActive = tr_webseedIsActive( w );
Note: See TracChangeset
for help on using the changeset viewer.