Changeset 7441 for trunk/libtransmission/peer-mgr.c
- Timestamp:
- Dec 20, 2008, 10:19:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r7434 r7441 58 58 59 59 /* how frequently to reallocate bandwidth */ 60 BANDWIDTH_PERIOD_MSEC = 100,60 BANDWIDTH_PERIOD_MSEC = 500, 61 61 62 62 /* max # of peers to ask fer per torrent per reconnect pulse */ … … 144 144 tr_ptrArray * torrents; /* Torrent */ 145 145 tr_ptrArray * incomingHandshakes; /* tr_handshake */ 146 tr_ptrArray * finishedHandshakes; /* tr_handshake */ 146 147 tr_timer * bandwidthTimer; 147 148 }; … … 464 465 m->torrents = tr_ptrArrayNew( ); 465 466 m->incomingHandshakes = tr_ptrArrayNew( ); 467 m->finishedHandshakes = tr_ptrArrayNew( ); 466 468 m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); 467 469 return m; … … 471 473 tr_peerMgrFree( tr_peerMgr * manager ) 472 474 { 475 tr_handshake * handshake; 476 473 477 managerLock( manager ); 474 478 … … 481 485 482 486 tr_ptrArrayFree( manager->incomingHandshakes, NULL ); 487 488 while(( handshake = tr_ptrArrayPop( manager->finishedHandshakes ))) 489 tr_handshakeFree( handshake ); 490 491 tr_ptrArrayFree( manager->finishedHandshakes, NULL ); 483 492 484 493 /* free the torrents. */ … … 1195 1204 /* FIXME: this is kind of a mess. */ 1196 1205 static tr_bool 1197 myHandshakeDoneCB( tr_handshake * handshake,1198 tr_peerIo *io,1206 myHandshakeDoneCB( tr_handshake * handshake, 1207 tr_peerIo * io, 1199 1208 int isConnected, 1200 1209 const uint8_t * peer_id, 1201 void *vmanager )1210 void * vmanager ) 1202 1211 { 1203 1212 tr_bool ok = isConnected; … … 1241 1250 ++atom->numFails; 1242 1251 } 1243 1244 tr_peerIoFree( io );1245 1252 } 1246 1253 else /* looking good */ … … 1256 1263 tordbg( t, "banned peer %s tried to reconnect", 1257 1264 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1258 tr_peerIoFree( io );1259 1265 } 1260 1266 else if( tr_peerIoIsIncoming( io ) … … 1262 1268 1263 1269 { 1264 tr_peerIoFree( io );1265 1270 } 1266 1271 else … … 1270 1275 if( peer ) /* we already have this peer */ 1271 1276 { 1272 tr_peerIoFree( io );1273 1277 } 1274 1278 else … … 1286 1290 1287 1291 peer->port = port; 1288 peer->io = io;1292 peer->io = tr_handshakeStealIO( handshake ); 1289 1293 tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag ); 1290 1294 tr_peerIoSetBandwidth( io, peer->bandwidth ); … … 1294 1298 } 1295 1299 } 1300 1301 if( !success ) 1302 tr_ptrArrayAppend( manager->finishedHandshakes, handshake ); 1296 1303 1297 1304 if( t ) … … 1545 1552 } 1546 1553 1547 #warning this for loop can be removed when we are sure the bug is fixed1548 for( i=0; i<peersReturning; ++i )1549 assert( tr_isAddress( &pex[i].addr ) );1550 1551 1554 assert( ( walk - pex ) == peersReturning ); 1552 1555 qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare ); 1553 1554 #warning this for loop can be removed when we are sure the bug is fixed1555 for( i=0; i<peersReturning; ++i )1556 assert( tr_isAddress( &pex[i].addr ) );1557 1556 1558 1557 *setme_pex = pex; … … 2395 2394 bandwidthPulse( void * vmgr ) 2396 2395 { 2396 tr_handshake * handshake; 2397 2397 tr_peerMgr * mgr = vmgr; 2398 2398 managerLock( mgr ); 2399 2399 2400 /* FIXME: this next line probably isn't necessary... */ 2400 2401 pumpAllPeers( mgr ); 2402 2403 /* allocate bandwidth to the peers */ 2401 2404 tr_bandwidthAllocate( mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC ); 2402 2405 tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC ); 2403 pumpAllPeers( mgr ); 2406 2407 /* free all the finished handshakes */ 2408 while(( handshake = tr_ptrArrayPop( mgr->finishedHandshakes ))) 2409 tr_handshakeFree( handshake ); 2404 2410 2405 2411 managerUnlock( mgr );
Note: See TracChangeset
for help on using the changeset viewer.