Ignore:
Timestamp:
Feb 8, 2010, 4:47:30 PM (13 years ago)
Author:
charles
Message:

(trunk) per-tier up/down/corrupt byte counts for announcing to trackers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r10099 r10141  
    348348typedef struct
    349349{
     350    /* number of up/down/corrupt bytes since the last time we sent an
     351     * "event=stopped" message that was acknowledged by the tracker */
     352    uint64_t byteCounts[3];
     353
    350354    tr_ptrArray trackers; /* tr_tracker_item */
    351355    tr_tracker_item * currentTracker;
     
    669673                              torrent->peer_id,
    670674                              (int)tr_sessionGetPeerPort( announcer->session ),
    671                               torrent->uploadedCur,
    672                               torrent->downloadedCur,
     675                              tier->byteCounts[TR_ANN_UP],
     676                              tier->byteCounts[TR_ANN_DOWN],
    673677                              tr_cpLeftUntilComplete( &torrent->completion ),
    674678                              numwant,
    675679                              tracker->key_param );
    676680
    677     if( torrent->corruptCur )
    678         evbuffer_add_printf( buf, "&corrupt=%" PRIu64, torrent->corruptCur );
     681    if( tier->byteCounts[TR_ANN_CORRUPT] )
     682        evbuffer_add_printf( buf, "&corrupt=%" PRIu64, tier->byteCounts[TR_ANN_CORRUPT] );
    679683
    680684    str = eventName;
     
    920924}
    921925
     926/***
     927****
     928***/
     929
     930void
     931tr_announcerAddBytes( tr_torrent * tor, int type, uint32_t byteCount )
     932{
     933    int i, n;
     934    tr_torrent_tiers * tiers;
     935
     936    assert( tr_isTorrent( tor ) );
     937    assert( type==TR_ANN_UP || type==TR_ANN_DOWN || type==TR_ANN_CORRUPT );
     938
     939    tiers = tor->tiers;
     940    n = tr_ptrArraySize( &tiers->tiers );
     941    for( i=0; i<n; ++i )
     942    {
     943        tr_tier * tier = tr_ptrArrayNth( &tiers->tiers, i );
     944        tier->byteCounts[ type ] += byteCount;
     945    }
     946}
     947
     948void
     949tr_announcerSubtractBytes( tr_torrent * tor, int type, uint32_t byteCount )
     950{
     951    int i, n;
     952    tr_torrent_tiers * tiers;
     953
     954    assert( tr_isTorrent( tor ) );
     955    assert( type==TR_ANN_UP || type==TR_ANN_DOWN || type==TR_ANN_CORRUPT );
     956
     957    tiers = tor->tiers;
     958    n = tr_ptrArraySize( &tiers->tiers );
     959    for( i=0; i<n; ++i )
     960    {
     961        tr_tier * tier = tr_ptrArrayNth( &tiers->tiers, i );
     962        uint64_t * setme = &tier->byteCounts[type];
     963        *setme -= MIN( *setme, byteCount );
     964    }
     965}
     966
     967/***
     968****
     969***/
    922970
    923971void
     
    937985            {
    938986                struct stop_message * s = tr_new0( struct stop_message, 1 );
    939                 s->up = tor->uploadedCur;
    940                 s->down = tor->downloadedCur;
     987                s->up = tier->byteCounts[TR_ANN_UP];
     988                s->down = tier->byteCounts[TR_ANN_DOWN];
    941989                s->url = createAnnounceURL( announcer, tor, tier, "stopped" );
    942990                s->host = tier->currentTracker->host;
     
    10081056    /* upload comes before download */
    10091057    if( !ret )
    1010         ret = compareTransfer( a->tor->uploadedCur, a->tor->downloadedCur,
    1011                                b->tor->uploadedCur, b->tor->downloadedCur );
     1058        ret = compareTransfer( a->byteCounts[TR_ANN_UP], a->byteCounts[TR_ANN_DOWN],
     1059                               b->byteCounts[TR_ANN_UP], b->byteCounts[TR_ANN_DOWN] );
    10121060
    10131061    /* incomplete comes before complete */
     
    12261274            success = parseAnnounceResponse( tier, response, responseLen, isStopped, &gotScrape );
    12271275            dbgmsg( tier, "success is %d", success );
     1276
     1277            if( isStopped )
     1278            {
     1279                /* now that we've successfully stopped the torrent,
     1280                 * we can reset the up/down/corrupt count we've kept
     1281                 * for this tracker */
     1282                tier->byteCounts[ TR_ANN_UP ] = 0;
     1283                tier->byteCounts[ TR_ANN_DOWN ] = 0;
     1284                tier->byteCounts[ TR_ANN_CORRUPT ] = 0;
     1285            }
    12281286        }
    12291287        else if( responseCode )
Note: See TracChangeset for help on using the changeset viewer.