Changeset 5029


Ignore:
Timestamp:
Feb 13, 2008, 5:18:29 PM (15 years ago)
Author:
charles
Message:

(1.0x) #690: get multitracker torrents working with the evhttp code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0x/libtransmission/tracker.c

    r4877 r5029  
    283283
    284284static const char*
    285 updateAddresses( tr_tracker * t, const struct evhttp_request * req )
     285updateAddresses( tr_tracker * t, const struct evhttp_request * req, int * tryAgain )
    286286{
    287287    const char * ret = NULL;
     
    337337    }
    338338
     339    *tryAgain = moveToNextAddress;
     340
    339341    if( moveToNextAddress )
    340         if ( ++t->addressIndex >= t->addressCount )
     342    {
     343        if ( ++t->addressIndex >= t->addressCount ) /* we've tried them all */
     344        {
     345            *tryAgain = FALSE;
    341346            t->addressIndex = 0;
     347            ret = "Tracker hasn't responded yet.  Retrying...";
     348            tr_inf( ret );
     349        }
     350    }
     351
    342352
    343353    return ret;
     
    387397{
    388398    const char * warning;
     399    int tryAgain;
    389400    int responseCode;
    390401    struct torrent_hash * torrent_hash = (struct torrent_hash*) vhash;
     
    474485    }
    475486
    476     if (( warning = updateAddresses( t, req ) )) {
     487    if (( warning = updateAddresses( t, req, &tryAgain ) )) {
    477488        publishWarning( t, warning );
    478489        tr_err( warning );
     
    483494    **/
    484495
    485     responseCode = req ? req->response_code : 503;
     496    if( tryAgain )
     497        responseCode = 300;
     498    else if( req )
     499        responseCode = req->response_code;
     500    else
     501        responseCode = 503;
    486502
    487503    if( 200<=responseCode && responseCode<=299 )
     
    544560{
    545561    const char * warning;
     562    int tryAgain;
    546563    time_t nextScrapeSec = 60;
    547564    struct torrent_hash * torrent_hash = (struct torrent_hash*) vhash;
     
    607624    }
    608625
    609     if (( warning = updateAddresses( t, req ) )) {
     626    if (( warning = updateAddresses( t, req, &tryAgain ) ))
     627    {
    610628        tr_err( warning );
    611629        publishWarning( t, warning );
    612630    }
    613631
    614     t->scrapeAt = time( NULL ) + t->randOffset + nextScrapeSec;
     632    if( tryAgain )
     633        t->scrapeAt = time( NULL );
     634    else
     635        t->scrapeAt = time( NULL ) + t->randOffset + nextScrapeSec;
    615636}
    616637
     
    851872    dbgmsg( t, "sending '%s' to tracker %s:%d, timeout is %d", req->uri, req->address, req->port, (int)req->timeout );
    852873    evhttp_connection_set_timeout( evcon, req->timeout );
     874    ++handle->tracker->socketCount;
    853875    if( evhttp_make_request( evcon, req->req, EVHTTP_REQ_GET, req->uri ))
    854         publishErrorMessageAndStop( t, "Tracker could not be reached." );
    855     else {
    856         ++handle->tracker->socketCount;
     876        (*req->req->cb)(req->req, req->req->cb_arg);
     877    else
    857878        dbgmsg( t, "incremented socket count to %d", handle->tracker->socketCount );
    858     }
    859879}
    860880
Note: See TracChangeset for help on using the changeset viewer.