Changeset 3163


Ignore:
Timestamp:
Sep 25, 2007, 12:04:29 AM (15 years ago)
Author:
charles
Message:
  • follow the BT spec more closely by disallowing peers to request blocks of more than 16KiB from us.
  • don't register the choke and connection timers for torrents that aren't running. It doesn't hurt anything but does waste a few cycles.
Location:
trunk/libtransmission
Files:
2 edited

Legend:

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

    r3161 r3163  
    560560
    561561static void
     562restartReconnectTimer( Torrent * t )
     563{
     564    tr_timerFree( &t->reconnectTimer );
     565    if( t->isRunning )
     566        t->reconnectTimer = tr_timerNew( t->manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC );
     567}
     568
     569static void
    562570reconnectNow( Torrent * t )
    563571{
    564572    reconnectPulse( t );
    565     tr_timerFree( &t->reconnectTimer );
    566     t->reconnectTimer = tr_timerNew( t->manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC );
     573    restartReconnectTimer( t );
    567574}
    568575
     
    591598
    592599static void
     600restartChokeTimer( Torrent * t )
     601{
     602    tr_timerFree( &t->rechokeTimer );
     603    if( t->isRunning )
     604        t->rechokeTimer = tr_timerNew( t->manager->handle, rechokePulse, t, RECHOKE_PERIOD_MSEC );
     605}
     606
     607static void
    593608rechokeNow( Torrent * t )
    594609{
    595610    rechokePulse( t );
    596     tr_timerFree( &t->rechokeTimer );
    597     t->rechokeTimer = tr_timerNew( t->manager->handle, rechokePulse, t, RECHOKE_PERIOD_MSEC );
     611    restartChokeTimer( t );
    598612}
    599613
     
    877891    Torrent * t = getExistingTorrent( manager, torrentHash );
    878892    t->isRunning = 1;
     893    restartChokeTimer( t );
    879894    reconnectNow( t );
    880895}
     
    886901    Torrent * t = getExistingTorrent( manager, torrentHash );
    887902    t->isRunning = 0;
    888     reconnectNow( t );
     903    tr_timerFree( &t->rechokeTimer );
     904    tr_timerFree( &t->reconnectTimer );
     905    reconnectPulse( t );
    889906}
    890907
     
    903920    t->peers = tr_ptrArrayNew( );
    904921    t->requested = tr_bitfieldNew( tor->blockCount );
    905     t->rechokeTimer = tr_timerNew( manager->handle, rechokePulse, t, RECHOKE_PERIOD_MSEC );
    906     t->reconnectTimer = tr_timerNew( manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC );
     922    restartChokeTimer( t );
     923    restartReconnectTimer( t );
    907924
    908925    memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH );
  • trunk/libtransmission/peer-msgs.c

    r3162 r3163  
    4545enum
    4646{
    47     BT_CHOKE           = 0,
    48     BT_UNCHOKE         = 1,
    49     BT_INTERESTED      = 2,
    50     BT_NOT_INTERESTED  = 3,
    51     BT_HAVE            = 4,
    52     BT_BITFIELD        = 5,
    53     BT_REQUEST         = 6,
    54     BT_PIECE           = 7,
    55     BT_CANCEL          = 8,
    56     BT_PORT            = 9,
    57     BT_SUGGEST         = 13,
    58     BT_HAVE_ALL        = 14,
    59     BT_HAVE_NONE       = 15,
    60     BT_REJECT          = 16,
    61     BT_ALLOWED_FAST    = 17,
    62     BT_LTEP            = 20,
    63 
    64     LTEP_HANDSHAKE     = 0,
    65 
    66     OUR_LTEP_PEX       = 1
     47    BT_CHOKE                  = 0,
     48    BT_UNCHOKE                = 1,
     49    BT_INTERESTED             = 2,
     50    BT_NOT_INTERESTED         = 3,
     51    BT_HAVE                   = 4,
     52    BT_BITFIELD               = 5,
     53    BT_REQUEST                = 6,
     54    BT_PIECE                  = 7,
     55    BT_CANCEL                 = 8,
     56    BT_PORT                   = 9,
     57    BT_SUGGEST                = 13,
     58    BT_HAVE_ALL               = 14,
     59    BT_HAVE_NONE              = 15,
     60    BT_REJECT                 = 16,
     61    BT_ALLOWED_FAST           = 17,
     62    BT_LTEP                   = 20,
     63
     64    LTEP_HANDSHAKE            = 0,
     65
     66    OUR_LTEP_PEX              = 1,
     67
     68    /* disregard requests that want more than this many bytes.
     69       it's common practice in for BT clients to use a 16K threshold */
     70    MAX_REQUEST_BYTE_COUNT    = (16 * 1024)
    6771};
    6872
     
    612616    const tr_torrent * tor = msgs->torrent;
    613617    assert( req != NULL );
    614     assert( req->index < (uint32_t)tor->info.pieceCount );
    615     assert( (int)req->offset < tr_torPieceCountBytes( tor, (int)req->index ) );
    616     assert( tr_pieceOffset( tor, req->index, req->offset, req->length ) <= tor->info.totalSize );
     618
     619    if( req->index >= (uint32_t) tor->info.pieceCount )
     620        return FALSE;
     621    if ( (int)req->offset >= tr_torPieceCountBytes( tor, (int)req->index ) )
     622        return FALSE;
     623    if( req->length > MAX_REQUEST_BYTE_COUNT )
     624        return FALSE;
     625    if( tr_pieceOffset( tor, req->index, req->offset, req->length ) > tor->info.totalSize )
     626        return FALSE;
     627
    617628    return TRUE;
    618629}
Note: See TracChangeset for help on using the changeset viewer.