Changeset 7977


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

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r7948 r7977  
    997997
    998998static void
    999 fireRatioLimitHit( tr_torrent * tor )
    1000 {
    1001     assert( tr_isTorrent( tor ) );
    1002 
    1003     if( tor->ratio_limit_hit_func )
    1004         tor->ratio_limit_hit_func( tor, tor->ratio_limit_hit_func_user_data );
    1005 }
    1006 
    1007 static void
    1008999peerCallbackFunc( void * vpeer, void * vevent, void * vt )
    10091000{
     
    10361027            const time_t now = time( NULL );
    10371028            tr_torrent * tor = t->tor;
    1038             double seedRatio;
    10391029
    10401030            tor->activityDate = now;
     
    10541044            }
    10551045
    1056             /* if we're seeding and we've reached our seed ratio limit, stop the torrent */
    1057             if( tr_torrentIsSeed( tor ) && tr_torrentGetSeedRatio( tor, &seedRatio ) ) {
    1058                 const double up = tor->uploadedCur + tor->uploadedPrev;
    1059                 const double down = tor->downloadedCur + tor->downloadedPrev;
    1060                 const double ratio = tr_getRatio( up, down );
    1061                 if( ratio >= seedRatio ) {
    1062                     tr_torrentStop( tor );
    1063                    
    1064                     /* set to no ratio limit to allow easy restarting */
    1065                     tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED );
    1066                    
    1067                     fireRatioLimitHit( tor );
    1068                 }
    1069             }
     1046            tr_torrentCheckSeedRatio( tor );
    10701047
    10711048            break;
  • trunk/libtransmission/session.c

    r7888 r7977  
    344344
    345345    assert( tr_bencIsDict( settings ) );
    346  
     346
    347347    filename = tr_buildPath( configDir, "settings.json", NULL );
    348348
     
    724724
    725725static void
     726updateSeedRatio( tr_session * session )
     727{
     728    tr_torrent * tor = NULL;
     729
     730    while(( tor = tr_torrentNext( session, tor )))
     731        tr_torrentCheckSeedRatio( tor );
     732}
     733
     734void
     735tr_sessionSetRatioLimited( tr_session * session, tr_bool isLimited )
     736{
     737    assert( tr_isSession( session ) );
     738
     739    session->isRatioLimited = isLimited;
     740    updateSeedRatio( session );
     741}
     742
     743void
     744tr_sessionSetRatioLimit( tr_session * session, double desiredRatio )
     745{
     746    assert( tr_isSession( session ) );
     747
     748    session->desiredRatio = desiredRatio;
     749    updateSeedRatio( session );
     750}
     751
     752tr_bool
     753tr_sessionIsRatioLimited( const tr_session  * session )
     754{
     755    assert( tr_isSession( session ) );
     756
     757    return session->isRatioLimited;
     758}
     759
     760double
     761tr_sessionGetRatioLimit( const tr_session * session )
     762{
     763    assert( tr_isSession( session ) );
     764
     765    return session->desiredRatio;
     766}
     767
     768/***
     769****
     770***/
     771
     772static void
    726773updateBandwidth( tr_session * session, tr_direction dir )
    727774{
     
    750797
    751798void
    752 tr_sessionSetRatioLimited( tr_session      * session,
    753                            tr_bool           isLimited )
    754 {
    755     assert( tr_isSession( session ) );
    756    
    757     session->isRatioLimited = isLimited;
    758 }
    759 
    760 void
    761799tr_sessionSetSpeedLimit( tr_session    * session,
    762800                         tr_direction    dir,
     
    770808}
    771809
    772 void
    773 tr_sessionSetRatioLimit( tr_session    * session,
    774                          double          desiredRatio )
    775 {
    776     assert( tr_isSession( session ) );
    777 
    778     session->desiredRatio = desiredRatio;
    779 }
    780 
    781810tr_bool
    782 tr_sessionIsSpeedLimitEnabled( const tr_session  * session,
    783                                tr_direction        dir )
     811tr_sessionIsSpeedLimitEnabled( const tr_session * session, tr_direction dir )
    784812{
    785813    assert( tr_isSession( session ) );
     
    789817}
    790818
    791 tr_bool
    792 tr_sessionIsRatioLimited( const tr_session  * session )
    793 {
    794     assert( tr_isSession( session ) );
    795 
    796     return session->isRatioLimited;
    797 }
    798 
    799819int
    800 tr_sessionGetSpeedLimit( const tr_session  * session,
    801                          tr_direction        dir )
     820tr_sessionGetSpeedLimit( const tr_session * session, tr_direction dir )
    802821{
    803822    assert( tr_isSession( session ) );
     
    805824
    806825    return session->speedLimit[dir];
    807 }
    808 
    809 double
    810 tr_sessionGetRatioLimit( const tr_session  * session )
    811 {
    812     assert( tr_isSession( session ) );
    813 
    814     return session->desiredRatio;
    815826}
    816827
     
    820831
    821832void
    822 tr_sessionSetPeerLimit( tr_session * session,
    823                         uint16_t     maxGlobalPeers )
     833tr_sessionSetPeerLimit( tr_session * session, uint16_t maxGlobalPeers )
    824834{
    825835    assert( tr_isSession( session ) );
  • 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}
  • trunk/libtransmission/torrent.h

    r7892 r7977  
    9292                                             tr_priority_t      priority );
    9393
    94 
    9594int              tr_torrentCountUncheckedPieces( const tr_torrent * );
    9695
     
    116115tr_torrent*      tr_torrentNext( tr_session  * session,
    117116                                 tr_torrent  * current );
     117
     118void             tr_torrentCheckSeedRatio( tr_torrent * tor );
     119
    118120
    119121
Note: See TracChangeset for help on using the changeset viewer.