Changeset 2876


Ignore:
Timestamp:
Aug 20, 2007, 2:29:36 AM (14 years ago)
Author:
charles
Message:

minor improvements to.. you guessed it.. the tracker/libevent code

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r2846 r2876  
    309309    if( success )
    310310    {
    311         tr_inf( "Piece %d hash OK", pieceIndex );
     311        tr_dbg( "Piece %d hash OK", pieceIndex );
    312312        tr_cpPieceAdd( tor->completion, pieceIndex );
    313313    }
  • trunk/libtransmission/tracker.c

    r2868 r2876  
    5151#define REQ_TIMEOUT_INTERVAL_SEC 60
    5252
    53 /* the number of peers that is our goal */
     53/* the value of the 'numwant' argument passed in tracker requests */
    5454#define NUMWANT 75
    5555
     
    184184    static tr_ptrArray_t * connections = NULL;
    185185    if( !connections )
    186         connections = tr_ptrArrayNew( );
     186         connections = tr_ptrArrayNew( );
    187187
    188188    tmp.address = (char*) address;
     
    236236    event.peerCount = count;
    237237    event.peerCompact = peers;
    238     tr_inf( "torrent %s got %d new peers", tor->torrent->info.name, count );
     238    tr_inf( "Torrent \"%s\" got %d new peers", tor->torrent->info.name, count );
    239239    tr_publisherPublish( tor->publisher, tor, &event );
    240240}
     
    282282
    283283    if( !t->scrapeTag )
    284          t->scrapeTag = tr_timerNew( t->handle, onTrackerScrapeNow, t, NULL, 1000 );
     284         t->scrapeTag = tr_timerNew( t->handle,
     285                                     onTrackerScrapeNow, t,
     286                                     NULL, 1000 );
    285287}
    286288
     
    358360
    359361static void
    360 escape( char * out, const uint8_t * in, int in_len )
     362escape( char * out, const uint8_t * in, int in_len ) /* rfc2396 */
    361363{
    362364    const uint8_t *end = in + in_len;
     
    570572    Tracker * t = (Tracker*) vt;
    571573
    572     tr_inf( "scrape response from  '%s': %s",
     574    tr_inf( "Got scrape response from  '%s': %s",
    573575            t->primaryAddress,
    574576            (req ? req->response_code_line : "(null)") );
     
    578580        int numResponses = 0;
    579581        benc_val_t benc, *files;
    580         int n_scraping = tr_ptrArraySize( t->scraping );
     582        const int n_scraping = tr_ptrArraySize( t->scraping );
    581583        const int bencLoaded = !parseBencResponse( req, &benc );
    582584
     
    621623                                              tor, NULL,
    622624                                              t->scrapeIntervalMsec );
    623                 tr_dbg( "torrent '%s' scraped.  re-scraping in %d seconds",
     625                tr_dbg( "Torrent '%s' scrape successful."
     626                        "  Rescraping in %d seconds",
    624627                        tor->torrent->info.name, t->scrapeIntervalMsec/1000 );
    625628            }
     
    638641                    tr_trackerStop( torrents[i] );
    639642                tr_ptrArrayClear( t->scraping );
    640                 n_scraping = 0;
    641643
    642644                t->multiscrapeMax = INT_MAX;
     
    652654        if( ( 0 < numResponses ) && ( numResponses < n_scraping ) )
    653655            t->multiscrapeMax = numResponses;
    654     }
    655     else if( !req )
    656     {
    657         int i, n;
    658         Torrent ** torrents = (Torrent**)
    659             tr_ptrArrayPeek( t->scraping, &n );
    660         for( i=0; i<n; ++i )
    661             torrents[i]->scrapeTag = tr_timerNew( t->handle,
    662                                                   onTorrentScrapeNow,
    663                                                   torrents[i], NULL,
    664                                                   t->scrapeIntervalMsec );
    665         tr_ptrArrayClear( t->scraping );
    666 
    667         t->multiscrapeMax = INT_MAX;
    668656    }
    669657
     
    732720        tr_ptrArrayErase( t->scrapeQueue, 0, ask_n );
    733721
    734         /* don't scrape again until we have some response from the tracker */
    735         tr_timerFree( &t->scrapeTag );
    736 
    737722        /* ping the tracker */
    738         tr_inf( "scrape to %s:%d: %s", address->address, address->port, uri );
     723        tr_inf( "Sending scrape to tracker %s:%d: %s",
     724                address->address, address->port, uri );
    739725        evcon = getConnection( address->address, address->port );
    740         assert( evcon != NULL );
    741726        evhttp_connection_set_timeout( evcon, SCRAPE_TIMEOUT_INTERVAL_SEC );
    742727        req = evhttp_request_new( onScrapeResponse, t );
     
    746731    }
    747732
     733    t->scrapeTag = NULL;
    748734    return FALSE;
    749735}
     
    756742
    757743static int
    758 torrentIsRunning( Torrent * tor )
    759 {
    760     return tor->lastRequest && strcmp( tor->lastRequest, "stopped" );
     744torrentIsRunning( const Torrent * tor )
     745{
     746    return ( tor != NULL )
     747        && ( tor->lastRequest != NULL )
     748        && ( strcmp( tor->lastRequest, "stopped" ) );
    761749}
    762750
     
    835823}
    836824
    837 static int
    838 onReannounceNow( void * vtor );
    839 
    840825/* handle braindead trackers whose minimums is higher
    841826   than the interval. */
     
    856841        t->announceIntervalMsec = t->minAnnounceIntervalMsec;
    857842}
     843
     844static int onReannounceNow( void * vtor );
    858845
    859846static void
     
    865852    int reannounceInterval;
    866853
    867     tr_inf( "torrent \"%s\" tracker response: %s",
     854    tr_inf( "Torrent \"%s\" tracker response: %s",
    868855            tor->torrent->info.name,
    869856            ( req ? req->response_code_line : "(null)") );
     
    971958    struct evhttp_connection * evcon = NULL;
    972959
    973     tr_inf( "tracker request to %s:%d: %s", address->address,
    974                                             address->port, uri );
     960    tr_inf( "Torrent \"%s\" sending '%s' to tracker %s:%d: %s",
     961            tor->torrent->info.name,
     962            (eventName ? eventName : "periodic announce"),
     963            address->address, address->port,
     964            uri );
    975965
    976966    /* kill any pending requests */
     
    987977        tor->httpReq = evhttp_request_new( onTrackerResponse, tor );
    988978        addCommonHeaders( tor->tracker, tor->httpReq );
    989         tr_evhttp_make_request( tor->tracker->handle, evcon, tor->httpReq, EVHTTP_REQ_GET, uri );
     979        tr_evhttp_make_request( tor->tracker->handle, evcon,
     980                                tor->httpReq, EVHTTP_REQ_GET, uri );
    990981    }
    991982
     
    996987onReannounceNow( void * vtor )
    997988{
    998     sendTrackerRequest( (Torrent*)vtor, "" );
     989    Torrent * tor = (Torrent *) vtor;
     990    sendTrackerRequest( tor, "" );
     991    tor->reannounceTag = NULL;
    999992    return FALSE;
    1000993}
     
    10301023    /* return true if this torrent's currently running
    10311024       and it's been long enough since the last announce */
    1032     return ( tor != NULL )
    1033         && ( tor->reannounceTag != NULL )
     1025    return ( torrentIsRunning( tor ) )
    10341026        && ( tr_date() >= tor->manualAnnounceAllowedAt );
    10351027}
     
    10411033                     int                 * setme_seederCount )
    10421034{
    1043     if( setme_completedCount)
     1035    if( setme_completedCount )
    10441036       *setme_completedCount = tor->timesDownloaded;
    10451037
    1046     if( setme_leecherCount)
     1038    if( setme_leecherCount )
    10471039       *setme_leecherCount = tor->leechers;
    10481040
    1049     if( setme_seederCount)
     1041    if( setme_seederCount )
    10501042       *setme_seederCount = tor->seeders;
    10511043}
  • trunk/libtransmission/trevent.c

    r2874 r2876  
    3434#include "utils.h"
    3535
    36 //#define DEBUG
     36/* #define DEBUG */
    3737#ifdef DEBUG
    3838#undef tr_dbg
  • trunk/libtransmission/trevent.h

    r2874 r2876  
    1616**/
    1717
    18 extern void tr_eventInit( struct tr_handle_s * tr_handle );
     18void tr_eventInit( struct tr_handle_s * tr_handle );
    1919
    20 extern void tr_eventClose( struct tr_handle_s * tr_handle );
     20void tr_eventClose( struct tr_handle_s * tr_handle );
    2121
    2222/**
Note: See TracChangeset for help on using the changeset viewer.