Changeset 11820


Ignore:
Timestamp:
Feb 3, 2011, 4:17:48 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) #3519 "Webseeds don't work" -- handle nonresponsive webseeds

Don't keep trying to use nonresponsive webseeds or it will generate unnecessary network traffic and kill us during endgame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/webseed.c

    r11782 r11820  
    5252    int                  torrent_id;
    5353    tr_bool              is_stopping;
     54    int                  consecutive_failures;
    5455};
    5556
    5657enum
    5758{
    58     TR_IDLE_TIMER_MSEC = 2000
     59    TR_IDLE_TIMER_MSEC = 2000,
     60
     61    MAX_CONSECUIVE_FAILURES = 5
    5962};
    6063
     
    8588
    8689static void
    87 fire_client_got_block( tr_torrent * tor, tr_webseed * w, tr_block_index_t block )
     90fire_client_got_rej( tr_torrent * tor, tr_webseed * w, tr_block_index_t block )
    8891{
    8992    tr_peer_event e = blank_event;
     93    e.eventType = TR_PEER_CLIENT_GOT_REJ;
    9094    e.pieceIndex = tr_torBlockPiece( tor, block );
    9195    e.offset = tor->blockSize * block - tor->info.pieceSize * e.pieceIndex;
    9296    e.length = tr_torBlockCountBytes( tor, block );
     97    publish( w, &e );
     98}
     99
     100static void
     101fire_client_got_block( tr_torrent * tor, tr_webseed * w, tr_block_index_t block )
     102{
     103    tr_peer_event e = blank_event;
    93104    e.eventType = TR_PEER_CLIENT_GOT_BLOCK;
     105    e.pieceIndex = tr_torBlockPiece( tor, block );
     106    e.offset = tor->blockSize * block - tor->info.pieceSize * e.pieceIndex;
     107    e.length = tr_torBlockCountBytes( tor, block );
    94108    publish( w, &e );
    95109}
     
    141155        webseed_free( w );
    142156    }
    143     else if( !w->is_stopping && tor && tor->isRunning && !tr_torrentIsSeed( tor ) )
     157    else if( !w->is_stopping && tor
     158                             && tor->isRunning
     159                             && !tr_torrentIsSeed( tor )
     160                             && ( w->consecutive_failures < MAX_CONSECUIVE_FAILURES ) )
    144161    {
    145162        int i;
     
    186203{
    187204    struct tr_webseed_task * t = vtask;
     205    tr_webseed * w = t->webseed;
    188206    tr_torrent * tor = tr_torrentFindFromId( session, t->torrent_id );
    189207    const int success = ( response_code == 206 );
    190208
    191     if( success && tor )
    192     {
    193         if( evbuffer_get_length( t->content ) < t->length )
     209    if( success )
     210        w->consecutive_failures = 0;
     211    else
     212        ++w->consecutive_failures;
     213
     214    if( tor )
     215    {
     216        if( !success )
    194217        {
    195             task_request_next_chunk( t );
     218            fire_client_got_rej( tor, w, t->block );
     219
     220            tr_list_remove_data( &w->tasks, t );
     221            evbuffer_free( t->content );
     222            tr_free( t );
    196223        }
    197224        else
    198225        {
    199             tr_webseed * w = t->webseed;
    200 
    201             tr_cacheWriteBlock( session->cache, tor,
    202                                 t->piece_index, t->piece_offset, t->length,
    203                                 t->content );
    204             fire_client_got_block( tor, w, t->block );
    205 
    206             tr_list_remove_data( &w->tasks, t );
    207             evbuffer_free( t->content );
    208             tr_free( t );
    209 
    210             on_idle( w );
     226            if( evbuffer_get_length( t->content ) < t->length )
     227            {
     228                task_request_next_chunk( t );
     229            }
     230            else
     231            {
     232                tr_cacheWriteBlock( session->cache, tor,
     233                                    t->piece_index, t->piece_offset, t->length,
     234                                    t->content );
     235                fire_client_got_block( tor, w, t->block );
     236
     237                tr_list_remove_data( &w->tasks, t );
     238                evbuffer_free( t->content );
     239                tr_free( t );
     240
     241                on_idle( w );
     242            }
    211243        }
    212244    }
Note: See TracChangeset for help on using the changeset viewer.