Changeset 7455 for branches/1.4x/libtransmission/peer-mgr.c
- Timestamp:
- Dec 22, 2008, 12:51:14 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.4x/libtransmission/peer-mgr.c
r7354 r7455 58 58 59 59 /* how frequently to reallocate bandwidth */ 60 BANDWIDTH_PERIOD_MSEC = 250,60 BANDWIDTH_PERIOD_MSEC = 500, 61 61 62 62 /* max # of peers to ask fer per torrent per reconnect pulse */ … … 90 90 **/ 91 91 92 /* We keep one of these for every peer we know about, whether 93 * it's connected or not, so the struct must be small. 94 * When our current connections underperform, we dip back 95 * into this list for new ones. */ 92 enum 93 { 94 UPLOAD_ONLY_UKNOWN, 95 UPLOAD_ONLY_YES, 96 UPLOAD_ONLY_NO 97 }; 98 99 /** 100 * Peer information that should be kept even before we've connected and 101 * after we've disconnected. These are kept in a pool of peer_atoms to decide 102 * which ones would make good candidates for connecting to, and to watch out 103 * for banned peers. 104 * 105 * @see tr_peer 106 * @see tr_peermsgs 107 */ 96 108 struct peer_atom 97 109 { 98 uint8_t from; 99 uint8_t flags; /* these match the added_f flags */ 100 uint8_t myflags; /* flags that aren't defined in added_f */ 101 uint16_t port; 102 uint16_t numFails; 103 struct in_addr addr; 104 time_t time; /* when the peer's connection status last changed */ 105 time_t piece_data_time; 110 uint8_t from; 111 uint8_t flags; /* these match the added_f flags */ 112 uint8_t myflags; /* flags that aren't defined in added_f */ 113 uint8_t uploadOnly; /* UPLOAD_ONLY_ */ 114 tr_port port; 115 uint16_t numFails; 116 tr_address addr; 117 time_t time; /* when the peer's connection status last changed */ 118 time_t piece_data_time; 106 119 }; 107 120 … … 131 144 tr_ptrArray * torrents; /* Torrent */ 132 145 tr_ptrArray * incomingHandshakes; /* tr_handshake */ 146 tr_ptrArray * finishedHandshakes; /* tr_handshake */ 133 147 tr_timer * bandwidthTimer; 134 148 }; … … 185 199 186 200 static int 187 compareAddresses( const struct in_addr * a, 188 const struct in_addr * b ) 189 { 190 if( a->s_addr != b->s_addr ) 191 return a->s_addr < b->s_addr ? -1 : 1; 192 193 return 0; 194 } 195 196 static int 197 handshakeCompareToAddr( const void * va, 198 const void * vb ) 201 handshakeCompareToAddr( const void * va, const void * vb ) 199 202 { 200 203 const tr_handshake * a = va; 201 204 202 return compareAddresses( tr_handshakeGetAddr( a, NULL ), vb ); 203 } 204 205 static int 206 handshakeCompare( const void * a, 207 const void * b ) 205 return tr_compareAddresses( tr_handshakeGetAddr( a, NULL ), vb ); 206 } 207 208 static int 209 handshakeCompare( const void * a, const void * b ) 208 210 { 209 211 return handshakeCompareToAddr( a, tr_handshakeGetAddr( b, NULL ) ); … … 211 213 212 214 static tr_handshake* 213 getExistingHandshake( tr_ptrArray * handshakes, 214 const struct in_addr * in_addr ) 215 { 216 return tr_ptrArrayFindSorted( handshakes, 217 in_addr, 218 handshakeCompareToAddr ); 219 } 220 221 static int 222 comparePeerAtomToAddress( const void * va, 223 const void * vb ) 215 getExistingHandshake( tr_ptrArray * handshakes, 216 const tr_address * addr ) 217 { 218 return tr_ptrArrayFindSorted( handshakes, addr, handshakeCompareToAddr ); 219 } 220 221 static int 222 comparePeerAtomToAddress( const void * va, const void * vb ) 224 223 { 225 224 const struct peer_atom * a = va; 226 225 227 return compareAddresses( &a->addr, vb ); 228 } 229 230 static int 231 comparePeerAtoms( const void * va, 232 const void * vb ) 226 return tr_compareAddresses( &a->addr, vb ); 227 } 228 229 static int 230 comparePeerAtoms( const void * va, const void * vb ) 233 231 { 234 232 const struct peer_atom * b = vb; … … 271 269 272 270 static int 273 peerCompare( const void * va, 274 const void * vb ) 271 peerCompare( const void * va, const void * vb ) 275 272 { 276 273 const tr_peer * a = va; 277 274 const tr_peer * b = vb; 278 275 279 return compareAddresses( &a->in_addr, &b->in_addr ); 280 } 281 282 static int 283 peerCompareToAddr( const void * va, 284 const void * vb ) 276 return tr_compareAddresses( &a->addr, &b->addr ); 277 } 278 279 static int 280 peerCompareToAddr( const void * va, const void * vb ) 285 281 { 286 282 const tr_peer * a = va; 287 283 288 return compareAddresses( &a->in_addr, vb );284 return tr_compareAddresses( &a->addr, vb ); 289 285 } 290 286 291 287 static tr_peer* 292 getExistingPeer( Torrent *torrent,293 const struct in_addr * in_addr )288 getExistingPeer( Torrent * torrent, 289 const tr_address * addr ) 294 290 { 295 291 assert( torrentIsLocked( torrent ) ); 296 assert( in_addr ); 297 298 return tr_ptrArrayFindSorted( torrent->peers, 299 in_addr, 300 peerCompareToAddr ); 292 assert( addr ); 293 294 return tr_ptrArrayFindSorted( torrent->peers, addr, peerCompareToAddr ); 301 295 } 302 296 303 297 static struct peer_atom* 304 getExistingAtom( const Torrent* t,305 const struct in_addr* addr )298 getExistingAtom( const Torrent * t, 299 const tr_address * addr ) 306 300 { 307 301 assert( torrentIsLocked( t ) ); … … 309 303 } 310 304 311 static int312 peerIsInUse( const Torrent *ct,313 const struct in_addr* addr )305 static tr_bool 306 peerIsInUse( const Torrent * ct, 307 const tr_address * addr ) 314 308 { 315 309 Torrent * t = (Torrent*) ct; … … 318 312 319 313 return getExistingPeer( t, addr ) 320 321 314 || getExistingHandshake( t->outgoingHandshakes, addr ) 315 || getExistingHandshake( t->manager->incomingHandshakes, addr ); 322 316 } 323 317 324 318 static tr_peer* 325 peerConstructor( tr_torrent * tor, const struct in_addr * in_addr )319 peerConstructor( tr_torrent * tor, const tr_address * addr ) 326 320 { 327 321 tr_peer * p; 328 329 322 p = tr_new0( tr_peer, 1 ); 330 memcpy( &p->in_addr, in_addr, sizeof( struct in_addr ) );323 p->addr = *addr; 331 324 p->bandwidth = tr_bandwidthNew( tor->session, tor->bandwidth ); 332 325 return p; … … 334 327 335 328 static tr_peer* 336 getPeer( Torrent *torrent,337 const struct in_addr * in_addr )329 getPeer( Torrent * torrent, 330 const tr_address * addr ) 338 331 { 339 332 tr_peer * peer; … … 341 334 assert( torrentIsLocked( torrent ) ); 342 335 343 peer = getExistingPeer( torrent, in_addr );336 peer = getExistingPeer( torrent, addr ); 344 337 345 338 if( peer == NULL ) 346 339 { 347 peer = peerConstructor( torrent->tor, in_addr );340 peer = peerConstructor( torrent->tor, addr ); 348 341 tr_ptrArrayInsertSorted( torrent->peers, peer, peerCompare ); 349 342 } … … 356 349 { 357 350 assert( peer ); 358 assert( peer->msgs ); 359 360 tr_peerMsgsUnsubscribe( peer->msgs, peer->msgsTag ); 361 tr_peerMsgsFree( peer->msgs ); 351 352 if( peer->msgs != NULL ) 353 { 354 tr_peerMsgsUnsubscribe( peer->msgs, peer->msgsTag ); 355 tr_peerMsgsFree( peer->msgs ); 356 } 362 357 363 358 tr_peerIoFree( peer->io ); … … 381 376 assert( torrentIsLocked( t ) ); 382 377 383 atom = getExistingAtom( t, &peer-> in_addr );378 atom = getExistingAtom( t, &peer->addr ); 384 379 assert( atom ); 385 380 atom->time = time( NULL ); … … 456 451 } 457 452 458 /**459 * For explanation, see http://www.bittorrent.org/fast_extensions.html460 * Also see the "test-allowed-set" unit test461 *462 * @param k number of pieces in set463 * @param sz number of pieces in the torrent464 * @param infohash torrent's SHA1 hash465 * @param ip peer's address466 */467 struct tr_bitfield *468 tr_peerMgrGenerateAllowedSet(469 const uint32_t k,470 const uint32_t sz,471 const uint8_t *472 infohash,473 const struct in_addr * ip )474 {475 uint8_t w[SHA_DIGEST_LENGTH + 4];476 uint8_t x[SHA_DIGEST_LENGTH];477 tr_bitfield * a;478 uint32_t a_size;479 480 *(uint32_t*)w = ntohl( htonl( ip->s_addr ) & 0xffffff00 ); /* (1) */481 memcpy( w + 4, infohash, SHA_DIGEST_LENGTH ); /* (2) */482 tr_sha1( x, w, sizeof( w ), NULL ); /* (3) */483 484 a = tr_bitfieldNew( sz );485 a_size = 0;486 487 while( a_size < k )488 {489 int i;490 for( i = 0; i < 5 && a_size < k; ++i ) /* (4) */491 {492 uint32_t j = i * 4; /* (5) */493 uint32_t y = ntohl( *( uint32_t* )( x + j ) ); /* (6) */494 uint32_t index = y % sz; /* (7) */495 if( !tr_bitfieldHas( a, index ) ) /* (8) */496 {497 tr_bitfieldAdd( a, index ); /* (9) */498 ++a_size;499 }500 }501 tr_sha1( x, x, sizeof( x ), NULL ); /* (3) */502 }503 504 return a;505 }506 453 507 454 static int bandwidthPulse( void * vmgr ); … … 516 463 m->torrents = tr_ptrArrayNew( ); 517 464 m->incomingHandshakes = tr_ptrArrayNew( ); 465 m->finishedHandshakes = tr_ptrArrayNew( ); 518 466 m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); 519 467 return m; … … 523 471 tr_peerMgrFree( tr_peerMgr * manager ) 524 472 { 473 tr_handshake * handshake; 474 525 475 managerLock( manager ); 526 476 … … 534 484 tr_ptrArrayFree( manager->incomingHandshakes, NULL ); 535 485 486 while(( handshake = tr_ptrArrayPop( manager->finishedHandshakes ))) 487 tr_handshakeFree( handshake ); 488 489 tr_ptrArrayFree( manager->finishedHandshakes, NULL ); 490 536 491 /* free the torrents. */ 537 492 tr_ptrArrayFree( manager->torrents, torrentDestructor ); … … 542 497 543 498 static tr_peer** 544 getConnectedPeers( Torrent * t, 545 int * setmeCount ) 546 { 547 int i, peerCount, connectionCount; 499 getConnectedPeers( Torrent * t, int * setmeCount ) 500 { 501 int i, peerCount, connectionCount; 548 502 tr_peer **peers; 549 503 tr_peer **ret; … … 578 532 ***/ 579 533 580 int 581 tr_peerMgrPeerIsSeed( const tr_peerMgr *mgr,582 const uint8_t *torrentHash,583 const struct in_addr* addr )584 { 585 intisSeed = FALSE;586 const Torrent * 534 tr_bool 535 tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 536 const uint8_t * torrentHash, 537 const tr_address * addr ) 538 { 539 tr_bool isSeed = FALSE; 540 const Torrent * t = NULL; 587 541 const struct peer_atom * atom = NULL; 588 542 … … 648 602 649 603 static int 650 compareRefillPiece( const void * aIn, 651 const void * bIn ) 604 compareRefillPiece( const void * aIn, const void * bIn ) 652 605 { 653 606 const struct tr_refill_piece * a = aIn; … … 678 631 679 632 static tr_piece_index_t * 680 getPreferredPieces( Torrent * t, 681 tr_piece_index_t * pieceCount ) 633 getPreferredPieces( Torrent * t, tr_piece_index_t * pieceCount ) 682 634 { 683 635 const tr_torrent * tor = t->tor; … … 877 829 for( j=0; !handled && j<peerCount; ) 878 830 { 879 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, 880 index, offset, length ); 831 const tr_addreq_t val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length ); 881 832 switch( val ) 882 833 { … … 905 856 for( j=0; !handled && j<webseedCount; ) 906 857 { 907 const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], 908 index, offset, length ); 858 const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], index, offset, length ); 909 859 switch( val ) 910 860 { … … 943 893 assert( torrentIsLocked( t ) ); 944 894 895 tordbg( t, "got a block; cancelling any duplicate requests from peers %"PRIu32":%"PRIu32"->%"PRIu32, index, offset, length ); 945 896 peers = getConnectedPeers( t, &size ); 946 897 for( i=0; i<size; ++i ) … … 954 905 { 955 906 tordbg( t, "increasing peer %s strike count to %d", 956 tr_peerIoAddrStr( &peer-> in_addr,907 tr_peerIoAddrStr( &peer->addr, 957 908 peer->port ), peer->strikes + 1 ); 958 909 959 910 if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER ) 960 911 { 961 struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );912 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 962 913 atom->myflags |= MYFLAG_BANNED; 963 914 peer->doPurge = 1; … … 988 939 989 940 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 = (Torrent *) vt; 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 947 assert( t ); 948 assert( peer ); 949 assert( peer->msgs ); 950 951 /* is this a valid piece? */ 952 if( pieceIndex >= t->tor->info.pieceCount ) 953 return; 954 955 /* don't ask for it if we've already got it */ 956 if( tr_cpPieceIsComplete( t->tor->completion, pieceIndex ) ) 957 return; 958 959 /* don't ask for it if they don't have it */ 960 if( !tr_bitfieldHas( peer->have, pieceIndex ) ) 961 return; 962 963 /* don't ask for it if we're choked and it's not fast */ 964 if( !isFastAllowed && peer->clientIsChoked ) 965 return; 966 967 /* request the blocks that we don't have in this piece */ 968 { 969 tr_block_index_t block; 970 const tr_torrent * tor = t->tor; 971 const tr_block_index_t start = tr_torPieceFirstBlock( tor, pieceIndex ); 972 const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, pieceIndex ); 973 974 for( block=start; block<end; ++block ) 975 { 976 if( !tr_cpBlockIsComplete( tor->completion, block ) ) 977 { 978 const uint32_t offset = getBlockOffsetInPiece( tor, block ); 979 const uint32_t length = tr_torBlockCountBytes( tor, block ); 980 tr_peerMsgsAddRequest( peer->msgs, pieceIndex, offset, length ); 981 incrementPieceRequests( t, pieceIndex ); 982 } 983 } 984 } 985 #endif 986 } 987 988 static void 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 … … 1000 997 switch( e->eventType ) 1001 998 { 999 case TR_PEER_UPLOAD_ONLY: 1000 /* update our atom */ 1001 if( peer ) { 1002 struct peer_atom * a = getExistingAtom( t, &peer->addr ); 1003 a->uploadOnly = e->uploadOnly ? UPLOAD_ONLY_YES : UPLOAD_ONLY_NO; 1004 } 1005 break; 1006 1002 1007 case TR_PEER_NEED_REQ: 1003 1008 refillSoon( t ); … … 1024 1029 /* update our atom */ 1025 1030 if( peer ) { 1026 struct peer_atom * a = getExistingAtom( t, &peer-> in_addr );1031 struct peer_atom * a = getExistingAtom( t, &peer->addr ); 1027 1032 if( e->wasPieceData ) 1028 1033 a->piece_data_time = now; … … 1031 1036 break; 1032 1037 } 1038 1039 case TR_PEER_CLIENT_GOT_SUGGEST: 1040 if( peer ) 1041 peerSuggestedPiece( t, peer, e->pieceIndex, FALSE ); 1042 break; 1043 1044 case TR_PEER_CLIENT_GOT_ALLOWED_FAST: 1045 if( peer ) 1046 peerSuggestedPiece( t, peer, e->pieceIndex, TRUE ); 1047 break; 1033 1048 1034 1049 case TR_PEER_CLIENT_GOT_DATA: … … 1036 1051 const time_t now = time( NULL ); 1037 1052 tr_torrent * tor = t->tor; 1038 1039 1053 tor->activityDate = now; 1040 1054 … … 1054 1068 /* update our atom */ 1055 1069 if( peer ) { 1056 struct peer_atom * a = getExistingAtom( t, &peer-> in_addr );1070 struct peer_atom * a = getExistingAtom( t, &peer->addr ); 1057 1071 if( e->wasPieceData ) 1058 1072 a->piece_data_time = now; … … 1066 1080 if( peer ) 1067 1081 { 1068 struct peer_atom * atom = getExistingAtom( t, 1069 &peer->in_addr ); 1070 const int peerIsSeed = e->progress >= 1.0; 1071 if( peerIsSeed ) 1072 { 1073 tordbg( t, "marking peer %s as a seed", 1074 tr_peerIoAddrStr( &atom->addr, 1075 atom->port ) ); 1082 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1083 const int peerIsSeed = e->progress >= 1.0; 1084 if( peerIsSeed ) { 1085 tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1076 1086 atom->flags |= ADDED_F_SEED_FLAG; 1077 } 1078 else 1079 { 1080 tordbg( t, "marking peer %s as a non-seed", 1081 tr_peerIoAddrStr( &atom->addr, 1082 atom->port ) ); 1087 } else { 1088 tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1083 1089 atom->flags &= ~ADDED_F_SEED_FLAG; 1084 1090 } … … 1091 1097 tr_torrent * tor = t->tor; 1092 1098 1093 tr_block_index_t block = _tr_block( tor, e->pieceIndex, 1094 e->offset ); 1099 tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset ); 1095 1100 1096 1101 tr_cpBlockAdd( tor->completion, block ); … … 1102 1107 { 1103 1108 const tr_piece_index_t p = e->pieceIndex; 1104 const intok = tr_ioTestPiece( tor, p );1109 const tr_bool ok = tr_ioTestPiece( tor, p ); 1105 1110 1106 1111 if( !ok ) 1107 1112 { 1108 tr_torerr( tor, 1109 _( "Piece %lu, which was just downloaded, failed its checksum test" ), 1110 (unsigned long)p ); 1113 tr_torerr( tor, _( "Piece %lu, which was just downloaded, failed its checksum test" ), 1114 (unsigned long)p ); 1111 1115 } 1112 1116 … … 1119 1123 else 1120 1124 { 1121 int 1125 int i, peerCount; 1122 1126 tr_peer ** peers = getConnectedPeers( t, &peerCount ); 1123 1127 for( i = 0; i < peerCount; ++i ) … … 1136 1140 addStrike( t, peer ); 1137 1141 peer->doPurge = 1; 1142 tordbg( t, "setting doPurge because we got an EINVAL error" ); 1138 1143 } 1139 1144 else if( ( e->err == ERANGE ) … … 1143 1148 /* some protocol error from the peer */ 1144 1149 peer->doPurge = 1; 1150 tordbg( t, "setting doPurge because we got an ERANGE, EMSGSIZE, or ENOTCONN error" ); 1145 1151 } 1146 1152 else /* a local error, such as an IO error */ … … 1162 1168 1163 1169 static void 1164 ensureAtomExists( Torrent *t,1165 const struct in_addr* addr,1166 uint16_tport,1167 uint8_t 1168 uint8_t 1170 ensureAtomExists( Torrent * t, 1171 const tr_address * addr, 1172 tr_port port, 1173 uint8_t flags, 1174 uint8_t from ) 1169 1175 { 1170 1176 if( getExistingAtom( t, addr ) == NULL ) … … 1176 1182 a->flags = flags; 1177 1183 a->from = from; 1178 tordbg( t, "got a new atom: %s", 1179 tr_peerIoAddrStr( &a->addr, a->port ) ); 1184 tordbg( t, "got a new atom: %s", tr_peerIoAddrStr( &a->addr, a->port ) ); 1180 1185 tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms ); 1181 1186 } … … 1191 1196 getPeerCount( const Torrent * t ) 1192 1197 { 1193 return tr_ptrArraySize( t->peers ) + tr_ptrArraySize( 1194 t->outgoingHandshakes ); 1198 return tr_ptrArraySize( t->peers ) + tr_ptrArraySize( t->outgoingHandshakes ); 1195 1199 } 1196 1200 1197 1201 /* FIXME: this is kind of a mess. */ 1198 static int1199 myHandshakeDoneCB( tr_handshake *handshake,1200 tr_peerIo *io,1202 static tr_bool 1203 myHandshakeDoneCB( tr_handshake * handshake, 1204 tr_peerIo * io, 1201 1205 int isConnected, 1202 1206 const uint8_t * peer_id, 1203 void *vmanager )1204 { 1205 intok = isConnected;1206 intsuccess = FALSE;1207 uint16_tport;1208 const struct in_addr* addr;1209 tr_peerMgr * manager = (tr_peerMgr*)vmanager;1210 Torrent *t;1211 tr_handshake *ours;1207 void * vmanager ) 1208 { 1209 tr_bool ok = isConnected; 1210 tr_bool success = FALSE; 1211 tr_port port; 1212 const tr_address * addr; 1213 tr_peerMgr * manager = vmanager; 1214 Torrent * t; 1215 tr_handshake * ours; 1212 1216 1213 1217 assert( io ); … … 1243 1247 ++atom->numFails; 1244 1248 } 1245 1246 tr_peerIoFree( io );1247 1249 } 1248 1250 else /* looking good */ … … 1257 1259 { 1258 1260 tordbg( t, "banned peer %s tried to reconnect", 1259 tr_peerIoAddrStr( &atom->addr, 1260 atom->port ) ); 1261 tr_peerIoFree( io ); 1261 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1262 1262 } 1263 1263 else if( tr_peerIoIsIncoming( io ) … … 1265 1265 1266 1266 { 1267 tr_peerIoFree( io );1268 1267 } 1269 1268 else … … 1273 1272 if( peer ) /* we already have this peer */ 1274 1273 { 1275 tr_peerIoFree( io );1276 1274 } 1277 1275 else … … 1289 1287 1290 1288 peer->port = port; 1291 peer->io = io;1292 peer->msgs =tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag );1289 peer->io = tr_handshakeStealIO( handshake ); 1290 tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag ); 1293 1291 tr_peerIoSetBandwidth( io, peer->bandwidth ); 1294 1292 … … 1298 1296 } 1299 1297 1298 if( !success ) 1299 tr_ptrArrayAppend( manager->finishedHandshakes, handshake ); 1300 1300 1301 if( t ) 1301 1302 torrentUnlock( t ); … … 1305 1306 1306 1307 void 1307 tr_peerMgrAddIncoming( tr_peerMgr * 1308 struct in_addr* addr,1309 uint16_tport,1310 int 1308 tr_peerMgrAddIncoming( tr_peerMgr * manager, 1309 tr_address * addr, 1310 tr_port port, 1311 int socket ) 1311 1312 { 1312 1313 managerLock( manager ); … … 1314 1315 if( tr_sessionIsAddressBlocked( manager->session, addr ) ) 1315 1316 { 1316 tr_dbg( "Banned IP address \"%s\" tried to connect to us", 1317 inet_ntoa( *addr ) ); 1317 tr_dbg( "Banned IP address \"%s\" tried to connect to us", inet_ntoa( *addr ) ); 1318 1318 tr_netClose( socket ); 1319 1319 } … … 1339 1339 1340 1340 managerUnlock( manager ); 1341 } 1342 1343 static tr_bool 1344 tr_isPex( const tr_pex * pex ) 1345 { 1346 return pex && tr_isAddress( &pex->addr ); 1341 1347 } 1342 1348 … … 1347 1353 const tr_pex * pex ) 1348 1354 { 1349 Torrent * t; 1350 1351 managerLock( manager ); 1352 1353 t = getExistingTorrent( manager, torrentHash ); 1354 if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->in_addr ) ) 1355 ensureAtomExists( t, &pex->in_addr, pex->port, pex->flags, from ); 1356 1357 managerUnlock( manager ); 1355 if( tr_isPex( pex ) ) /* safeguard against corrupt data */ 1356 { 1357 Torrent * t; 1358 managerLock( manager ); 1359 1360 t = getExistingTorrent( manager, torrentHash ); 1361 if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) ) 1362 ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from ); 1363 1364 managerUnlock( manager ); 1365 } 1358 1366 } 1359 1367 … … 1372 1380 for( i = 0; i < n; ++i ) 1373 1381 { 1374 memcpy( &pex[i]. in_addr, walk, 4 ); walk += 4;1382 memcpy( &pex[i].addr, walk, 4 ); walk += 4; 1375 1383 memcpy( &pex[i].port, walk, 2 ); walk += 2; 1376 1384 if( added_f && ( n == added_f_len ) ) … … 1406 1414 if( tr_bitfieldHas( peer->blame, pieceIndex ) ) 1407 1415 { 1408 tordbg( 1409 t, 1410 "peer %s contributed to corrupt piece (%d); now has %d strikes", 1411 tr_peerIoAddrStr( &peer->in_addr, peer->port ), 1412 pieceIndex, (int)peer->strikes + 1 ); 1416 tordbg( t, "peer %s contributed to corrupt piece (%d); now has %d strikes", 1417 tr_peerIoAddrStr( &peer->addr, peer->port ), 1418 pieceIndex, (int)peer->strikes + 1 ); 1413 1419 addStrike( t, peer ); 1414 1420 } … … 1418 1424 1419 1425 int 1420 tr_pexCompare( const void * va, 1421 const void * vb ) 1426 tr_pexCompare( const void * va, const void * vb ) 1422 1427 { 1423 1428 const tr_pex * a = va; 1424 1429 const tr_pex * b = vb; 1425 int i = 1426 memcmp( &a->in_addr, &b->in_addr, sizeof( struct in_addr ) ); 1427 1428 if( i ) return i; 1429 if( a->port < b->port ) return -1; 1430 if( a->port > b->port ) return 1; 1430 int i; 1431 1432 assert( tr_isPex( a ) ); 1433 assert( tr_isPex( b ) ); 1434 1435 if(( i = tr_compareAddresses( &a->addr, &b->addr ))) 1436 return i; 1437 1438 if( a->port != b->port ) 1439 return a->port < b->port ? -1 : 1; 1440 1431 1441 return 0; 1432 1442 } 1433 1434 int tr_pexCompare( const void * a,1435 const void * b );1436 1443 1437 1444 static int … … 1448 1455 1449 1456 int 1450 tr_peerMgrGetPeers( tr_peerMgr *manager,1451 const uint8_t * torrentHash,1452 tr_pex **setme_pex )1457 tr_peerMgrGetPeers( tr_peerMgr * manager, 1458 const uint8_t * torrentHash, 1459 tr_pex ** setme_pex ) 1453 1460 { 1454 1461 int peerCount = 0; … … 1458 1465 1459 1466 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1460 if( !t)1467 if( t == NULL ) 1461 1468 { 1462 1469 *setme_pex = NULL; … … 1469 1476 tr_pex * walk = pex; 1470 1477 1471 for( i = 0; i <peerCount; ++i, ++walk )1478 for( i=0; i<peerCount; ++i, ++walk ) 1472 1479 { 1473 1480 const tr_peer * peer = peers[i]; 1474 walk->in_addr = peer->in_addr; 1481 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1482 1483 assert( tr_isAddress( &peer->addr ) ); 1484 walk->addr = peer->addr; 1475 1485 walk->port = peer->port; 1476 1486 walk->flags = 0; 1477 if( peerPrefersCrypto( peer ) ) walk->flags |= ADDED_F_ENCRYPTION_FLAG; 1478 if( peer->progress >= 1.0 ) walk->flags |= ADDED_F_SEED_FLAG; 1487 if( peerPrefersCrypto( peer ) ) 1488 walk->flags |= ADDED_F_ENCRYPTION_FLAG; 1489 if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ) ) 1490 walk->flags |= ADDED_F_SEED_FLAG; 1479 1491 } 1480 1492 … … 1603 1615 const tr_torrent * tor; 1604 1616 float interval; 1605 int isComplete;1617 tr_bool isSeed; 1606 1618 int peerCount; 1607 1619 const tr_peer ** peers; … … 1612 1624 tor = t->tor; 1613 1625 interval = tor->info.pieceCount / (float)tabCount; 1614 isComplete = tor 1615 && ( tr_cpGetStatus ( tor->completion ) == TR_CP_COMPLETE ); 1626 isSeed = tor && ( tr_cpGetStatus ( tor->completion ) == TR_CP_COMPLETE ); 1616 1627 peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount ); 1617 1628 … … 1622 1633 const int piece = i * interval; 1623 1634 1624 if( is Complete|| tr_cpPieceIsComplete( tor->completion, piece ) )1635 if( isSeed || tr_cpPieceIsComplete( tor->completion, piece ) ) 1625 1636 tab[i] = -1; 1626 else if( peerCount ) 1627 { 1637 else if( peerCount ) { 1628 1638 int j; 1629 1639 for( j = 0; j < peerCount; ++j ) … … 1645 1655 tr_peer ** peers; 1646 1656 tr_bitfield * pieces; 1647 1648 1657 managerLock( manager ); 1649 1658 … … 1663 1672 const uint8_t * torrentHash ) 1664 1673 { 1665 int 1674 int ret; 1666 1675 const Torrent * t; 1667 1668 1676 managerLock( manager ); 1669 1677 1670 1678 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1671 ret = t && ( !tr_ptrArrayEmpty( t->peers ) 1672 || !tr_ptrArrayEmpty( t->webseeds ) ); 1679 ret = t && ( !tr_ptrArrayEmpty( t->peers ) || !tr_ptrArrayEmpty( t->webseeds ) ); 1673 1680 1674 1681 managerUnlock( manager ); … … 1678 1685 void 1679 1686 tr_peerMgrTorrentStats( const tr_peerMgr * manager, 1680 const uint8_t *torrentHash,1681 int *setmePeersKnown,1682 int *setmePeersConnected,1683 int *setmeSeedsConnected,1684 int *setmeWebseedsSendingToUs,1685 int *setmePeersSendingToUs,1686 int *setmePeersGettingFromUs,1687 int *setmePeersFrom )1688 { 1689 int 1690 const Torrent * 1691 const tr_peer ** 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 i, size; 1697 const Torrent * t; 1698 const tr_peer ** peers; 1692 1699 const tr_webseed ** webseeds; 1693 1700 … … 1704 1711 *setmeWebseedsSendingToUs = 0; 1705 1712 1706 for( i = 0; i <TR_PEER_FROM__MAX; ++i )1713 for( i=0; i<TR_PEER_FROM__MAX; ++i ) 1707 1714 setmePeersFrom[i] = 0; 1708 1715 1709 for( i = 0; i <size; ++i )1710 { 1711 const tr_peer * 1712 const struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );1716 for( i=0; i<size; ++i ) 1717 { 1718 const tr_peer * peer = peers[i]; 1719 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1713 1720 1714 1721 if( peer->io == NULL ) /* not connected */ 1715 1722 continue; 1716 1723 1717 ++ *setmePeersConnected;1724 ++*setmePeersConnected; 1718 1725 1719 1726 ++setmePeersFrom[atom->from]; 1720 1727 1721 1728 if( clientIsDownloadingFrom( peer ) ) 1722 ++ *setmePeersSendingToUs;1729 ++*setmePeersSendingToUs; 1723 1730 1724 1731 if( clientIsUploadingTo( peer ) ) 1725 ++ *setmePeersGettingFromUs;1732 ++*setmePeersGettingFromUs; 1726 1733 1727 1734 if( atom->flags & ADDED_F_SEED_FLAG ) 1728 ++ *setmeSeedsConnected;1735 ++*setmeSeedsConnected; 1729 1736 } 1730 1737 1731 1738 webseeds = (const tr_webseed **) tr_ptrArrayPeek( t->webseeds, &size ); 1732 for( i = 0; i < size; ++i ) 1733 { 1739 for( i=0; i<size; ++i ) 1734 1740 if( tr_webseedIsActive( webseeds[i] ) ) 1735 ++ * setmeWebseedsSendingToUs; 1736 } 1741 ++*setmeWebseedsSendingToUs; 1737 1742 1738 1743 managerUnlock( manager ); … … 1743 1748 const uint8_t * torrentHash ) 1744 1749 { 1745 const Torrent * 1750 const Torrent * t; 1746 1751 const tr_webseed ** webseeds; 1747 int 1748 int 1749 float * 1752 int i; 1753 int webseedCount; 1754 float * ret; 1750 1755 1751 1756 assert( manager ); … … 1758 1763 ret = tr_new0( float, webseedCount ); 1759 1764 1760 for( i = 0; i <webseedCount; ++i )1765 for( i=0; i<webseedCount; ++i ) 1761 1766 if( !tr_webseedGetSpeed( webseeds[i], &ret[i] ) ) 1762 1767 ret[i] = -1.0; … … 1767 1772 1768 1773 double 1769 tr_peerGetPieceSpeed( const tr_peer * peer, 1770 tr_direction direction ) 1774 tr_peerGetPieceSpeed( const tr_peer * peer, tr_direction direction ) 1771 1775 { 1772 1776 assert( peer ); … … 1798 1802 char * pch; 1799 1803 const tr_peer * peer = peers[i]; 1800 const struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );1804 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1801 1805 tr_peer_stat * stat = ret + i; 1802 1806 1803 tr_netNtop( &peer-> in_addr, stat->addr, sizeof( stat->addr ) );1807 tr_netNtop( &peer->addr, stat->addr, sizeof( stat->addr ) ); 1804 1808 tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ), 1805 1809 sizeof( stat->client ) ); … … 1817 1821 stat->isDownloadingFrom = clientIsDownloadingFrom( peer ); 1818 1822 stat->isUploadingTo = clientIsUploadingTo( peer ); 1823 stat->isSeed = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ); 1819 1824 1820 1825 pch = stat->flagStr; … … 1824 1829 if( stat->isUploadingTo ) *pch++ = 'U'; 1825 1830 else if( stat->peerIsInterested ) *pch++ = 'u'; 1826 if( !stat->clientIsChoked && !stat->clientIsInterested ) *pch++ = 1827 'K'; 1831 if( !stat->clientIsChoked && !stat->clientIsInterested ) *pch++ = 'K'; 1828 1832 if( !stat->peerIsChoked && !stat->peerIsInterested ) *pch++ = '?'; 1829 1833 if( stat->isEncrypted ) *pch++ = 'E'; … … 1899 1903 { 1900 1904 tr_peer * peer = peers[i]; 1905 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1906 1901 1907 if( peer->progress >= 1.0 ) /* choke all seeds */ 1908 { 1902 1909 tr_peerMsgsSetChoke( peer->msgs, TRUE ); 1903 else if( chokeAll ) 1910 } 1911 else if( atom->uploadOnly == UPLOAD_ONLY_YES ) /* choke partial seeds */ 1912 { 1904 1913 tr_peerMsgsSetChoke( peer->msgs, TRUE ); 1905 else { 1914 } 1915 else if( chokeAll ) /* choke everyone if we're not uploading */ 1916 { 1917 tr_peerMsgsSetChoke( peer->msgs, TRUE ); 1918 } 1919 else 1920 { 1906 1921 struct ChokeData * n = &choke[size++]; 1907 1922 n->peer = peer; … … 1928 1943 */ 1929 1944 unchokedInterested = 0; 1930 for( i = 0; i < size && unchokedInterested < MAX_UNCHOKED_PEERS; ++i ) 1931 { 1945 for( i=0; i<size && unchokedInterested<MAX_UNCHOKED_PEERS; ++i ) { 1932 1946 choke[i].doUnchoke = 1; 1933 1947 if( choke[i].isInterested ) … … 1938 1952 if( i < size ) 1939 1953 { 1940 int 1954 int n; 1941 1955 struct ChokeData * c; 1942 tr_ptrArray * 1943 1944 for( ; i <size; ++i )1956 tr_ptrArray * randPool = tr_ptrArrayNew( ); 1957 1958 for( ; i<size; ++i ) 1945 1959 { 1946 1960 if( choke[i].isInterested ) 1947 1961 { 1948 1962 const tr_peer * peer = choke[i].peer; 1949 int 1963 int x = 1, y; 1950 1964 if( isNew( peer ) ) x *= 3; 1951 1965 if( isSame( peer ) ) x *= 3; 1952 for( y = 0; y <x; ++y )1966 for( y=0; y<x; ++y ) 1953 1967 tr_ptrArrayAppend( randPool, &choke[i] ); 1954 1968 } 1955 1969 } 1956 1970 1957 if( ( n = tr_ptrArraySize( randPool ) ))1971 if(( n = tr_ptrArraySize( randPool ))) 1958 1972 { 1959 c = tr_ptrArrayNth( randPool, tr_cryptoWeakRandInt( n ) 1973 c = tr_ptrArrayNth( randPool, tr_cryptoWeakRandInt( n )); 1960 1974 c->doUnchoke = 1; 1961 1975 t->optimistic = c->peer; … … 1965 1979 } 1966 1980 1967 for( i = 0; i <size; ++i )1981 for( i=0; i<size; ++i ) 1968 1982 tr_peerMsgsSetChoke( choke[i].peer->msgs, !choke[i].doUnchoke ); 1969 1983 … … 1997 2011 const tr_torrent * tor = t->tor; 1998 2012 const time_t now = time( NULL ); 1999 const struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );2013 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 2000 2014 2001 2015 /* if it's marked for purging, close it */ … … 2003 2017 { 2004 2018 tordbg( t, "purging peer %s because its doPurge flag is set", 2005 tr_peerIoAddrStr( &atom->addr, 2006 atom->port ) ); 2019 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2007 2020 return TRUE; 2008 2021 } … … 2017 2030 else if( peer->progress < tr_cpPercentDone( tor->completion ) ) 2018 2031 peerHasEverything = FALSE; 2019 else 2020 { 2021 tr_bitfield * tmp = 2022 tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) ); 2032 else { 2033 tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) ); 2023 2034 tr_bitfieldDifference( tmp, peer->have ); 2024 2035 peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0; 2025 2036 tr_bitfieldFree( tmp ); 2026 2037 } 2027 if( peerHasEverything 2028 && ( !tr_torrentAllowsPex( tor ) || ( now - atom->time >= 30 ) ))2038 2039 if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 ))) 2029 2040 { 2030 2041 tordbg( t, "purging peer %s because we're both seeds", 2031 tr_peerIoAddrStr( &atom->addr, 2032 atom->port ) ); 2042 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2033 2043 return TRUE; 2034 2044 } … … 2060 2070 2061 2071 static tr_peer ** 2062 getPeersToClose( Torrent * t, 2063 int * setmeSize ) 2064 { 2065 int i, peerCount, outsize; 2066 tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, 2067 &peerCount ); 2072 getPeersToClose( Torrent * t, int * setmeSize ) 2073 { 2074 int i, peerCount, outsize; 2075 tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount ); 2068 2076 struct tr_peer ** ret = tr_new( tr_peer *, peerCount ); 2069 2077 … … 2101 2109 return a->time < b->time ? -1 : 1; 2102 2110 2111 /* all other things being equal, prefer peers whose 2112 * information comes from a more reliable source */ 2113 if( a->from != b->from ) 2114 return a->from < b->from ? -1 : 1; 2115 2103 2116 return 0; 2104 2117 } … … 2113 2126 * data, try to reconnect to them sooner rather that later -- we don't 2114 2127 * want network troubles to get in the way of a good peer. */ 2115 if( ( now - atom->piece_data_time ) <= 2116 ( MINIMUM_RECONNECT_INTERVAL_SECS * 2 ) ) 2128 if( ( now - atom->piece_data_time ) <= ( MINIMUM_RECONNECT_INTERVAL_SECS * 2 ) ) 2117 2129 sec = MINIMUM_RECONNECT_INTERVAL_SECS; 2118 2130 … … 2123 2135 /* otherwise, the interval depends on how many times we've tried 2124 2136 * and failed to connect to the peer */ 2125 else switch( atom->numFails ) 2126 { 2127 case 0: 2128 sec = 0; break; 2129 2130 case 1: 2131 sec = 5; break; 2132 2133 case 2: 2134 sec = 2 * 60; break; 2135 2136 case 3: 2137 sec = 15 * 60; break; 2138 2139 case 4: 2140 sec = 30 * 60; break; 2141 2142 case 5: 2143 sec = 60 * 60; break; 2144 2145 default: 2146 sec = 120 * 60; break; 2147 } 2137 else switch( atom->numFails ) { 2138 case 0: sec = 0; break; 2139 case 1: sec = 5; break; 2140 case 2: sec = 2 * 60; break; 2141 case 3: sec = 15 * 60; break; 2142 case 4: sec = 30 * 60; break; 2143 case 5: sec = 60 * 60; break; 2144 default: sec = 120 * 60; break; 2145 } 2148 2146 2149 2147 return sec; … … 2151 2149 2152 2150 static struct peer_atom ** 2153 getPeerCandidates( Torrent * t, 2154 int * setmeSize ) 2151 getPeerCandidates( Torrent * t, int * setmeSize ) 2155 2152 { 2156 2153 int i, atomCount, retCount; … … 2185 2182 2186 2183 /* no need to connect if we're both seeds... */ 2187 if( seed && ( atom->flags & ADDED_F_SEED_FLAG ) ) 2184 if( seed && ( ( atom->flags & ADDED_F_SEED_FLAG ) || 2185 ( atom->uploadOnly == UPLOAD_ONLY_YES ) ) ) 2188 2186 continue; 2189 2187 … … 2192 2190 if( ( now - atom->time ) < interval ) 2193 2191 { 2194 tordbg( 2195 t, 2196 "RECONNECT peer %d (%s) is in its grace period of %d seconds..", 2197 i, tr_peerIoAddrStr( &atom->addr, 2198 atom->port ), interval ); 2192 tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..", 2193 i, tr_peerIoAddrStr( &atom->addr, atom->port ), interval ); 2199 2194 continue; 2200 2195 } … … 2235 2230 else 2236 2231 { 2237 int 2232 int i, nCandidates, nBad; 2238 2233 struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates ); 2239 struct tr_peer ** 2234 struct tr_peer ** connections = getPeersToClose( t, &nBad ); 2240 2235 2241 2236 if( nBad || nCandidates ) 2242 tordbg( 2243 t, "reconnect pulse for [%s]: %d bad connections, " 2244 "%d connection candidates, %d atoms, max per pulse is %d", 2245 t->tor->info.name, nBad, nCandidates, 2246 tr_ptrArraySize( t->pool ), 2247 (int)MAX_RECONNECTIONS_PER_PULSE ); 2237 tordbg( t, "reconnect pulse for [%s]: %d bad connections, " 2238 "%d connection candidates, %d atoms, max per pulse is %d", 2239 t->tor->info.name, nBad, nCandidates, 2240 tr_ptrArraySize( t->pool ), 2241 (int)MAX_RECONNECTIONS_PER_PULSE ); 2248 2242 2249 2243 /* disconnect some peers. … … 2251 2245 so reset their `numFails' weight to zero. otherwise we connected 2252 2246 to them fruitlessly, so mark it as another fail */ 2253 for( i = 0; i < nBad; ++i ) 2254 { 2255 tr_peer * peer = connections[i]; 2256 struct peer_atom * atom = getExistingAtom( t, &peer->in_addr ); 2247 for( i = 0; i < nBad; ++i ) { 2248 tr_peer * peer = connections[i]; 2249 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 2257 2250 if( atom->piece_data_time ) 2258 2251 atom->numFails = 0; 2259 2252 else 2260 2253 ++atom->numFails; 2261 tordbg( t, "removing bad peer %s", 2262 tr_peerIoGetAddrStr( peer->io ) ); 2254 tordbg( t, "removing bad peer %s", tr_peerIoGetAddrStr( peer->io ) ); 2263 2255 removePeer( t, peer ); 2264 2256 } … … 2268 2260 && ( i < MAX_RECONNECTIONS_PER_PULSE ) 2269 2261 && ( getPeerCount( t ) < getMaxPeerCount( t->tor ) ) 2270 && ( newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND ); 2271 ++i ) 2262 && ( newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND ); ++i ) 2272 2263 { 2273 2264 tr_peerMgr * mgr = t->manager; … … 2278 2269 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 2279 2270 2280 io = 2281 tr_peerIoNewOutgoing( mgr->session, &atom->addr, atom->port, 2282 t->hash ); 2271 io = tr_peerIoNewOutgoing( mgr->session, &atom->addr, atom->port, t->hash ); 2283 2272 if( io == NULL ) 2284 2273 { … … 2287 2276 else 2288 2277 { 2289 tr_handshake * handshake = tr_handshakeNew( 2290 io, 2291 mgr->session-> 2292 encryptionMode, 2293 myHandshakeDoneCB, 2294 mgr ); 2278 tr_handshake * handshake = tr_handshakeNew( io, 2279 mgr->session->encryptionMode, 2280 myHandshakeDoneCB, 2281 mgr ); 2295 2282 2296 2283 assert( tr_peerIoGetTorrentHash( io ) ); … … 2340 2327 bandwidthPulse( void * vmgr ) 2341 2328 { 2329 tr_handshake * handshake; 2342 2330 tr_peerMgr * mgr = vmgr; 2343 2331 managerLock( mgr ); 2344 2332 2333 /* FIXME: this next line probably isn't necessary... */ 2345 2334 pumpAllPeers( mgr ); 2335 2336 /* allocate bandwidth to the peers */ 2346 2337 tr_bandwidthAllocate( mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC ); 2347 2338 tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC ); 2348 pumpAllPeers( mgr ); 2339 2340 /* free all the finished handshakes */ 2341 while(( handshake = tr_ptrArrayPop( mgr->finishedHandshakes ))) 2342 tr_handshakeFree( handshake ); 2349 2343 2350 2344 managerUnlock( mgr );
Note: See TracChangeset
for help on using the changeset viewer.