Changeset 3265


Ignore:
Timestamp:
Oct 2, 2007, 12:05:40 AM (15 years ago)
Author:
charles
Message:

some cleanup... remove some dead/obsolete code

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r3263 r3265  
    6363    MAX_CONNECTED_PEERS_PER_TORRENT = 60,
    6464
    65     MAX_RECONNECTIONS_PER_MINUTE = MAX_CONNECTED_PEERS_PER_TORRENT,
    66     MAX_RECONNECTIONS_PER_PULSE = ((MAX_RECONNECTIONS_PER_MINUTE * RECONNECT_PERIOD_MSEC) / (60*1000)),
    67 
     65    /* another arbitrary number */
     66    MAX_RECONNECTIONS_PER_MINUTE = 60,
     67
     68    MAX_RECONNECTIONS_PER_PULSE =
     69        ((MAX_RECONNECTIONS_PER_MINUTE * RECONNECT_PERIOD_MSEC) / (60*1000)),
     70
     71    /* corresponds to ut_pex's added.f flags */
    6872    ADDED_F_ENCRYPTION_FLAG = 1,
     73
     74    /* corresponds to ut_pex's added.f flags */
    6975    ADDED_F_SEED_FLAG = 2
    7076};
     
    94100    tr_ptrArray * peers; /* tr_peer */
    95101    tr_timer * reconnectTimer;
    96     tr_timer * reconnectSoonTimer;
    97102    tr_timer * rechokeTimer;
    98103    tr_timer * rechokeSoonTimer;
     
    142147torrentIsLocked( const Torrent * t )
    143148{
    144     return ( t != NULL )
    145         && ( tr_globalIsLocked( t->manager->handle ) );
     149    return tr_globalIsLocked( t->manager->handle );
    146150}
    147151
     
    360364
    361365    tr_timerFree( &t->reconnectTimer );
    362     tr_timerFree( &t->reconnectSoonTimer );
    363366    tr_timerFree( &t->rechokeTimer );
    364367    tr_timerFree( &t->rechokeSoonTimer );
     
    460463}
    461464
    462 static tr_peer**
    463 getConnectedPeers( Torrent * t, int * setmeCount )
    464 {
    465     int i, peerCount, connectionCount;
    466     tr_peer **peers;
    467     tr_peer **ret;
    468 
    469     assert( torrentIsLocked( t ) );
    470 
    471     peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
    472     ret = tr_new( tr_peer*, peerCount );
    473 
    474     for( i=connectionCount=0; i<peerCount; ++i )
    475         if( peers[i]->msgs != NULL )
    476             ret[connectionCount++] = peers[i];
    477 
    478     *setmeCount = connectionCount;
    479     return ret;
    480 }
    481 
    482465/***
    483466****  Refill
     
    542525    assert( torrentIsLocked( t ) );
    543526
    544     peers = getConnectedPeers( t, &peerCount );
     527    peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );
    545528
    546529    for( i=0; i<inf->pieceCount; ++i )
     
    588571fprintf (stderr, "\n");
    589572#endif
    590     tr_free( peers );
    591573
    592574    *pieceCount = poolSize;
     
    663645
    664646    blocks = getPreferredBlocks( t, &blockCount );
    665     peers = getConnectedPeers( t, &peerCount );
     647    peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );
    666648
    667649/*fprintf( stderr, "REFILL refillPulse for {%s} got %d blocks\n", tor->info.name, (int)blockCount );*/
     
    695677
    696678                case TR_ADDREQ_OK:
    697                     /*fprintf( stderr, "REFILL peer %p took the request for block %d\n", peers[j]->msgs, block );*/
    698679                    tr_bitfieldAdd( t->requested, block );
    699680                    j = peerCount;
     
    708689
    709690    /* cleanup */
    710     tr_free( peers );
    711691    tr_free( blocks );
    712692
     
    725705    assert( torrentIsLocked( t ) );
    726706
    727     peers = getConnectedPeers( t, &size );
     707    peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &size );
    728708    for( i=0; i<size; ++i )
    729709        tr_peerMsgsHave( peers[i]->msgs, index );
    730     tr_free( peers );
    731710}
    732711
     
    739718    assert( torrentIsLocked( t ) );
    740719
    741     peers = getConnectedPeers( t, &size );
     720    peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &size );
    742721    for( i=0; i<size; ++i )
    743722        tr_peerMsgsCancel( peers[i]->msgs, index, offset, length );
    744     tr_free( peers );
    745723}
    746724
     
    757735    if( t->isRunning )
    758736        t->reconnectTimer = tr_timerNew( t->manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC );
    759 }
    760 
    761 static void
    762 reconnectNow( Torrent * t )
    763 {
    764     reconnectPulse( t );
    765     restartReconnectTimer( t );
    766 }
    767 
    768 static int
    769 reconnectSoonCB( void * vt )
    770 {
    771     Torrent * t = vt;
    772     reconnectNow( t );
    773     t->reconnectSoonTimer = NULL;
    774     return FALSE;
    775 }
    776 
    777 static void
    778 reconnectSoon( Torrent * t )
    779 {
    780     if( t->reconnectSoonTimer == NULL )
    781         t->reconnectSoonTimer = tr_timerNew( t->manager->handle,
    782                                              reconnectSoonCB, t, SOON_MSEC );
    783737}
    784738
     
    860814        case TR_PEERMSG_GOT_ERROR:
    861815            peer->doPurge = 1;
    862             reconnectSoon( t );
    863816            break;
    864817
     
    1012965    for( end=pex+pexCount; pex!=end; ++pex )
    1013966        ensureAtomExists( t, &pex->in_addr, pex->port, pex->flags, from );
    1014     reconnectSoon( t );
    1015967
    1016968    managerUnlock( manager );
     
    1039991        ensureAtomExists( t, &addr, port, 0, from );
    1040992    }
    1041     reconnectSoon( t );
    1042993
    1043994    managerUnlock( manager );
     
    1047998***
    1048999**/
    1049 
    1050 int
    1051 tr_peerMgrIsAcceptingConnections( const tr_peerMgr * manager UNUSED )
    1052 {
    1053     return TRUE; /* manager->connectionCount < MAX_CONNECTED_PEERS; */
    1054 }
    10551000
    10561001void
     
    10661011tr_pexCompare( const void * va, const void * vb )
    10671012{
    1068     const tr_pex * a = (const tr_pex *) va;
    1069     const tr_pex * b = (const tr_pex *) vb;
    1070     int i = memcmp( &a->in_addr, &b->in_addr, sizeof(struct in_addr) );
    1071     if( i ) return i;
    1072     if( a->port < b->port ) return -1;
    1073     if( a->port > b->port ) return 1;
    1074     return 0;
    1075 }
    1076 
    1077 int tr_pexCompare( const void * a, const void * b );
     1013    const tr_pex * a = va;
     1014    const tr_pex * b = vb;
     1015    return memcmp( &a->in_addr, &b->in_addr, sizeof(struct in_addr) );
     1016}
    10781017
    10791018static int
     
    11381077    t->isRunning = 1;
    11391078    restartChokeTimer( t );
    1140     reconnectSoon( t );
     1079    restartReconnectTimer( t );
    11411080
    11421081    managerUnlock( manager );
     
    11461085stopTorrent( Torrent * t )
    11471086{
    1148     int i, size;
    1149     tr_peer ** peers;
    1150 
    11511087    assert( torrentIsLocked( t ) );
    11521088
     
    11541090    tr_timerFree( &t->rechokeTimer );
    11551091    tr_timerFree( &t->reconnectTimer );
    1156 
    1157     peers = getConnectedPeers( t, &size );
    1158     for( i=0; i<size; ++i )
    1159         disconnectPeer( peers[i] );
    1160 
    1161     tr_free( peers );
     1092    removeAllPeers( t );
    11621093}
    11631094void
     
    13831314compareChoke( const void * va, const void * vb )
    13841315{
    1385     const ChokeData * a = ( const ChokeData * ) va;
    1386     const ChokeData * b = ( const ChokeData * ) vb;
     1316    const ChokeData * a = va;
     1317    const ChokeData * b = vb;
    13871318
    13881319    if( a->preferred != b->preferred )
     
    14181349    int i, peerCount, size=0, unchoked=0;
    14191350    const time_t ignorePeersNewerThan = time(NULL) - MIN_CHOKE_PERIOD_SEC;
    1420     tr_peer ** peers = getConnectedPeers( t, &peerCount );
     1351    tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );
    14211352    ChokeData * choke = tr_new0( ChokeData, peerCount );
    14221353
     
    14581389    /* cleanup */
    14591390    tr_free( choke );
    1460     tr_free( peers );
    14611391}
    14621392
     
    14691399    assert( torrentIsLocked( t ) );
    14701400
    1471     peers = getConnectedPeers( t, &size );
    1472 
    1473     /* FIXME */
     1401    peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &size );
    14741402    for( i=0; i<size; ++i )
    14751403        tr_peerMsgsSetChoke( peers[i]->msgs, FALSE );
    1476 
    1477     tr_free( peers );
    14781404}
    14791405
     
    15421468        if( peer->doPurge )
    15431469            isWeak = TRUE;
    1544         if( peerIsSeed && clientIsSeed && (now-atom->time >= 30) ) /* pex time */
     1470        if( peerIsSeed && clientIsSeed && (now-atom->time >= 20) ) /* pex time */
    15451471            isWeak = TRUE;
    15461472        else if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS )
  • trunk/libtransmission/peer-mgr.h

    r3258 r3265  
    3636
    3737void tr_peerMgrFree( tr_peerMgr * manager );
    38 
    39 int tr_peerMgrIsAcceptingConnections( const tr_peerMgr * manager );
    4038
    4139void tr_peerMgrAddIncoming( tr_peerMgr      * manager,
  • trunk/libtransmission/peer-msgs.c

    r3260 r3265  
    109109
    110110    struct evbuffer * outMessages; /* buffer of all the non-piece messages */
    111     struct evbuffer * outBlock;    /* the block we're currently sending */
    112111    struct evbuffer * inBlock;     /* the block we're currently receiving */
    113112    tr_list * peerAskedFor;
     
    12341233    {
    12351234    }
    1236 #if 0
    1237     else if(( len = EVBUFFER_LENGTH( msgs->outBlock ) ))
    1238     {
    1239         while ( len && canUpload( msgs ) )
    1240         {
    1241             const size_t outlen = len; //MIN( len, 2048 );
    1242             tr_peerIoWrite( msgs->io, EVBUFFER_DATA(msgs->outBlock), outlen );
    1243             evbuffer_drain( msgs->outBlock, outlen );
    1244             peerGotBytes( msgs, outlen );
    1245             len -= outlen;
    1246             msgs->info->clientSentPieceDataAt = now;
    1247             msgs->clientSentAnythingAt = now;
    1248             dbgmsg( msgs, "wrote %d bytes; %d left in block", (int)outlen, (int)len );
    1249         }
    1250     }
    1251 #endif
    12521235    else if(( len = EVBUFFER_LENGTH( msgs->outMessages ) ))
    12531236    {
     
    12591242        if( canUpload( msgs ) )
    12601243        {
    1261             struct peer_request * req = tr_list_pop_front( &msgs->peerAskedFor );
    1262             uint8_t * tmp = tr_new( uint8_t, req->length );
    1263             const uint32_t msglen = sizeof(uint8_t) + 2*sizeof(uint32_t) + req->length;
     1244            struct peer_request * r = tr_list_pop_front( &msgs->peerAskedFor );
     1245            uint8_t * tmp = tr_new( uint8_t, r->length );
     1246            const uint32_t msglen = sizeof(uint8_t) + 2*sizeof(uint32_t) + r->length;
    12641247            struct evbuffer * out = evbuffer_new( );
    1265             assert( requestIsValid( msgs, req ) );
     1248            assert( requestIsValid( msgs, r ) );
    12661249
    12671250            tr_peerIoWriteUint32( msgs->io, out, msglen );
    12681251            tr_peerIoWriteUint8 ( msgs->io, out, BT_PIECE );
    1269             tr_peerIoWriteUint32( msgs->io, out, req->index );
    1270             tr_peerIoWriteUint32( msgs->io, out, req->offset );
     1252            tr_peerIoWriteUint32( msgs->io, out, r->index );
     1253            tr_peerIoWriteUint32( msgs->io, out, r->offset );
    12711254            tr_peerIoWriteBuf( msgs->io, out );
    12721255
    1273             tr_ioRead( msgs->torrent, req->index, req->offset, req->length, tmp );
    1274             tr_peerIoWrite( msgs->io, tmp, req->length );
    1275             peerGotBytes( msgs, req->length );
    1276 
    1277             dbgmsg( msgs, "putting req into out queue: index %d, offset %d, length %d ... %d blocks left in our queue", (int)req->index, (int)req->offset, (int)req->length, tr_list_size(msgs->peerAskedFor) );
    1278 
    1279             tr_free( req );
     1256            tr_ioRead( msgs->torrent, r->index, r->offset, r->length, tmp );
     1257            tr_peerIoWrite( msgs->io, tmp, r->length );
     1258            peerGotBytes( msgs, r->length );
     1259
     1260            dbgmsg( msgs, "putting req into out queue: index %d, offset %d, length %d ... %d blocks left in our queue", (int)r->index, (int)r->offset, (int)r->length, tr_list_size(msgs->peerAskedFor) );
     1261
     1262            tr_free( r );
    12801263            tr_free( tmp );
    12811264            evbuffer_free( out );
     
    12911274
    12921275static void
    1293 didWrite( struct bufferevent * evin UNUSED, void * vpeer )
    1294 {
    1295     pulse( (tr_peermsgs *) vpeer );
     1276didWrite( struct bufferevent * evin UNUSED, void * vmsgs )
     1277{
     1278    pulse( vmsgs );
    12961279}
    12971280
     
    14881471    msgs->pexTimer = tr_timerNew( msgs->handle, pexPulse, msgs, PEX_INTERVAL );
    14891472    msgs->outMessages = evbuffer_new( );
    1490     msgs->outBlock = evbuffer_new( );
    14911473    msgs->inBlock = evbuffer_new( );
    14921474    msgs->peerAllowedPieces = NULL;
     
    15611543        tr_list_free( &msgs->peerAskedFor, tr_free );
    15621544        evbuffer_free( msgs->outMessages );
    1563         evbuffer_free( msgs->outBlock );
    15641545        evbuffer_free( msgs->inBlock );
    15651546        tr_free( msgs->pex );
  • trunk/libtransmission/shared.c

    r3254 r3265  
    268268        struct in_addr addr;
    269269
    270         if( s->bindSocket < 0 || !tr_peerMgrIsAcceptingConnections( s->h->peerMgr ) )
     270        if( s->bindSocket < 0 )
    271271            break;
    272272
Note: See TracChangeset for help on using the changeset viewer.