Changeset 10238


Ignore:
Timestamp:
Feb 20, 2010, 3:36:25 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2922 "announce's 'download' field should follow the de facto standard" -- added to trunk for 1.91

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r10199 r10238  
    10351035}
    10361036
    1037 void
    1038 tr_announcerSubtractBytes( tr_torrent * tor, int type, uint32_t byteCount )
    1039 {
    1040     int i, n;
    1041     tr_torrent_tiers * tiers;
    1042 
    1043     assert( tr_isTorrent( tor ) );
    1044     assert( type==TR_ANN_UP || type==TR_ANN_DOWN || type==TR_ANN_CORRUPT );
    1045 
    1046     tiers = tor->tiers;
    1047     n = tr_ptrArraySize( &tiers->tiers );
    1048     for( i=0; i<n; ++i )
    1049     {
    1050         tr_tier * tier = tr_ptrArrayNth( &tiers->tiers, i );
    1051         uint64_t * setme = &tier->byteCounts[type];
    1052         *setme -= MIN( *setme, byteCount );
    1053     }
    1054 }
    1055 
    10561037/***
    10571038****
     
    15151496    assert( tr_isTorrent( tier->tor ) );
    15161497
    1517     /* rule #1: if "stopped" is in the queue, ignore everything before it */
     1498    /* special case #1: if "stopped" is in the queue, ignore everything before it */
    15181499    events = (char**) tr_ptrArrayPeek( &tier->announceEvents, &n );
    1519     for( i=0; pos<0 && i<n; ++i )
    1520         if( !strcmp( events[i], "stopped" ) )
     1500    if( pos == -1 ) {
     1501        for( i=0; i<n; ++i )
     1502            if( !strcmp( events[i], "stopped" ) )
     1503                break;
     1504        if( i <  n )
    15211505            pos = i;
    1522 
    1523     /* rule #2: if the next two events are the same, ignore the first one */
    1524     for( i=0; pos<0 && i<=n-2; ++i )
    1525         if( strcmp( events[i], events[i+1] ) )
     1506    }
     1507
     1508    /* special case #2: don't use empty strings if something follows them */
     1509    if( pos == -1 ) {
     1510        for( i = 0; i < n; ++i )
     1511            if( *events[i] )
     1512                break;
     1513        if( i < n )
    15261514            pos = i;
    1527 
    1528     /* otherwise use the next announce event in line */
    1529     if( ( pos < 0 ) && ( n > 0 ) )
     1515    }
     1516
     1517    /* default: use the next in the queue */
     1518    if( ( pos == -1 ) && ( n > 0 ) )
    15301519        pos = 0;
    15311520
    1532     /* rule #3: BEP 21: "In order to tell the tracker that a peer is a
     1521    /* special case #3: if there are duplicate requests in a row, skip to the last one */
     1522    if( pos >= 0 ) {
     1523        for( i=pos+1; i<n; ++i )
     1524            if( events[pos] != events[i] )
     1525                break;
     1526        pos = i - 1;
     1527    }
     1528
     1529for( i=0; i<n; ++i ) fprintf( stderr, "(%d)\"%s\" ", i, events[i] );
     1530fprintf( stderr, "\n" );
     1531fprintf( stderr, "using (%d)\"%s\"\n", pos, events[pos] );
     1532
     1533    /* special case #4: BEP 21: "In order to tell the tracker that a peer is a
    15331534     * partial seed, it MUST send an event=paused parameter in every
    15341535     * announce while it is a partial seed." */
  • trunk/libtransmission/announcer.h

    r10141 r10238  
    9494enum { TR_ANN_UP, TR_ANN_DOWN, TR_ANN_CORRUPT };
    9595void tr_announcerAddBytes( tr_torrent *, int up_down_or_corrupt, uint32_t byteCount );
    96 void tr_announcerSubtractBytes( tr_torrent *, int up_down_or_corrupt, uint32_t byteCount );
    9796
    9897time_t tr_announcerNextManualAnnounce( const tr_torrent * );
  • trunk/libtransmission/peer-mgr.c

    r10141 r10238  
    11871187
    11881188    tr_announcerAddBytes( tor, TR_ANN_CORRUPT, byteCount );
    1189     tr_announcerSubtractBytes( tor, TR_ANN_DOWN, byteCount );
    11901189}
    11911190
     
    12361235    }
    12371236#endif
    1238 }
    1239 
    1240 static void
    1241 decrementDownloadedCount( tr_torrent * tor, uint32_t byteCount )
    1242 {
    1243     tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
    1244     tr_announcerSubtractBytes( tor, TR_ANN_DOWN, byteCount );
    1245 }
    1246 
    1247 static void
    1248 clientGotUnwantedBlock( tr_torrent * tor, tr_block_index_t block )
    1249 {
    1250     decrementDownloadedCount( tor, tr_torBlockCountBytes( tor, block ) );
    12511237}
    12521238
     
    13561342            tr_torrentSetActivityDate( tor, now );
    13571343
    1358             /* only add this to downloadedCur if we got it from a peer --
    1359              * webseeds shouldn't count against our ratio.  As one tracker
    1360              * admin put it, "Those pieces are downloaded directly from the
    1361              * content distributor, not the peers, it is the tracker's job
    1362              * to manage the swarms, not the web server and does not fit
    1363              * into the jurisdiction of the tracker." */
    1364             if( peer && e->wasPieceData ) {
     1344            if( e->wasPieceData ) {
    13651345                tor->downloadedCur += e->length;
    1366                 tr_announcerAddBytes( tor, TR_ANN_DOWN, e->length );
    13671346                tr_torrentSetDirty( tor );
    13681347            }
     
    13991378
    14001379            requestListRemove( t, block, peer );
     1380            pieceListRemoveRequest( t, block );
    14011381
    14021382            if( tr_cpBlockIsComplete( &tor->completion, block ) )
    14031383            {
     1384                /* we already have this block... */
     1385                const uint32_t n = tr_torBlockCountBytes( tor, block );
     1386                tor->downloadedCur -= MIN( tor->downloadedCur, n );
    14041387                tordbg( t, "we have this block already..." );
    1405                 clientGotUnwantedBlock( tor, block );
    1406                 pieceListRemoveRequest( t, block );
    14071388            }
    14081389            else
    14091390            {
    14101391                tr_cpBlockAdd( &tor->completion, block );
    1411                 pieceListRemoveRequest( t, block );
    14121392                tr_torrentSetDirty( tor );
    14131393
     
    14371417                        tr_peer ** peers;
    14381418                        tr_file_index_t fileIndex;
     1419
     1420                        /* only add this to downloadedCur if we got it from a peer --
     1421                         * webseeds shouldn't count against our ratio.  As one tracker
     1422                         * admin put it, "Those pieces are downloaded directly from the
     1423                         * content distributor, not the peers, it is the tracker's job
     1424                         * to manage the swarms, not the web server and does not fit
     1425                         * into the jurisdiction of the tracker." */
     1426                        if( peer != NULL ) {
     1427                            const uint32_t n = tr_torPieceCountBytes( tor, p );
     1428                            tr_announcerAddBytes( tor, TR_ANN_DOWN, n );
     1429                        }
    14391430
    14401431                        peerCount = tr_ptrArraySize( &t->peers );
Note: See TracChangeset for help on using the changeset viewer.