Ignore:
Timestamp:
Mar 1, 2009, 1:56:22 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #1823: Ratio limit is only checked when peers are active

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r7894 r7977  
    5959    tr_torrent * tor = NULL;
    6060
    61     while( ( tor = tr_torrentNext( session, tor ) ) )
     61    while(( tor = tr_torrentNext( session, tor )))
    6262        if( tor->uniqueId == id )
    6363            return tor;
     
    7171    tr_torrent * tor = NULL;
    7272
    73     while( ( tor = tr_torrentNext( session, tor ) ) )
     73    while(( tor = tr_torrentNext( session, tor )))
    7474        if( !strcmp( str, tor->info.hashString ) )
    7575            return tor;
     
    8383    tr_torrent * tor = NULL;
    8484
    85     while( ( tor = tr_torrentNext( session, tor ) ) )
     85    while(( tor = tr_torrentNext( session, tor )))
    8686        if( *tor->info.hash == *torrentHash )
    8787            if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
     
    9797    tr_torrent * tor = NULL;
    9898
    99     while( ( tor = tr_torrentNext( session, tor ) ) )
     99    while(( tor = tr_torrentNext( session, tor )))
    100100        if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash,
    101101                     SHA_DIGEST_LENGTH ) )
     
    152152
    153153void
    154 tr_torrentSetRatioMode( tr_torrent *  tor,                   
    155                         tr_ratiolimit mode )
     154tr_torrentSetRatioMode( tr_torrent *  tor, tr_ratiolimit mode )
    156155{
    157156    assert( tr_isTorrent( tor ) );
     
    159158
    160159    tor->ratioLimitMode = mode;
     160
     161    tr_torrentCheckSeedRatio( tor );
    161162}
    162163
     
    175176    assert( tr_isTorrent( tor ) );
    176177
    177     tor->desiredRatio = desiredRatio;   
     178    tor->desiredRatio = desiredRatio;
     179
     180    tr_torrentCheckSeedRatio( tor );
    178181}
    179182
     
    904907                s->eta = s->leftUntilDone / s->pieceDownloadSpeed / 1024.0;
    905908            break;
    906        
     909
    907910        case TR_STATUS_SEED:
    908911            if( tr_torrentGetSeedRatio( tor, &seedRatio ) )
     
    916919                s->eta = TR_ETA_NOT_AVAIL;
    917920            break;
    918        
     921
    919922        default:
    920923            s->eta = TR_ETA_NOT_AVAIL;
     
    15451548
    15461549static void
    1547 setFileDND( tr_torrent *    tor,
    1548             tr_file_index_t fileIndex,
    1549             int             doDownload )
     1550setFileDND( tr_torrent * tor, tr_file_index_t fileIndex, int doDownload )
    15501551{
    15511552    tr_file *        file;
     
    16021603
    16031604void
    1604 tr_torrentInitFileDLs( tr_torrent *      tor,
     1605tr_torrentInitFileDLs( tr_torrent      * tor,
    16051606                       tr_file_index_t * files,
    16061607                       tr_file_index_t   fileCount,
     
    16131614    tr_torrentLock( tor );
    16141615
    1615     for( i = 0; i < fileCount; ++i )
     1616    for( i=0; i<fileCount; ++i )
    16161617        setFileDND( tor, files[i], doDownload );
    1617     tr_cpInvalidateDND ( &tor->completion );
     1618    tr_cpInvalidateDND( &tor->completion );
     1619    tr_torrentCheckSeedRatio( tor );
    16181620
    16191621    tr_torrentUnlock( tor );
     
    17491751
    17501752    if( isChecked )
    1751         tr_bitfieldAddRange ( &tor->checkedPieces, begin, end );
     1753        tr_bitfieldAddRange( &tor->checkedPieces, begin, end );
    17521754    else
    1753         tr_bitfieldRemRange ( &tor->checkedPieces, begin, end );
     1755        tr_bitfieldRemRange( &tor->checkedPieces, begin, end );
    17541756}
    17551757
     
    17781780    assert( tr_isTorrent( tor ) );
    17791781
    1780     tr_bitfieldRemRange ( &tor->checkedPieces, 0, tor->info.pieceCount );
     1782    tr_bitfieldRemRange( &tor->checkedPieces, 0, tor->info.pieceCount );
    17811783}
    17821784
     
    21122114    }
    21132115}
     2116
     2117/***
     2118****
     2119***/
     2120
     2121void
     2122tr_torrentCheckSeedRatio( tr_torrent * tor )
     2123{
     2124    double seedRatio;
     2125
     2126    assert( tr_isTorrent( tor ) );
     2127
     2128    /* if we're seeding and we've reached our seed ratio limit, stop the torrent */
     2129    if( tr_torrentIsSeed( tor ) && tr_torrentGetSeedRatio( tor, &seedRatio ) )
     2130    {
     2131        const double up = tor->uploadedCur + tor->uploadedPrev;
     2132        const double down = tor->downloadedCur + tor->downloadedPrev;
     2133        const double ratio = tr_getRatio( up, down );
     2134        if( ratio >= seedRatio )
     2135        {
     2136            tr_torrentStop( tor );
     2137
     2138            /* set to no ratio limit to allow easy restarting */
     2139            tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED );
     2140
     2141            /* maybe notify the client */
     2142            if( tor->ratio_limit_hit_func != NULL )
     2143                tor->ratio_limit_hit_func( tor, tor->ratio_limit_hit_func_user_data );
     2144
     2145        }
     2146    }
     2147}
Note: See TracChangeset for help on using the changeset viewer.