Changeset 10477


Ignore:
Timestamp:
Apr 14, 2010, 12:03:23 AM (13 years ago)
Author:
charles
Message:

(trunk libT) #1869 "new status for torrents that reached the seed ratio" -- maybe fix the issue reported by leena

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r10473 r10477  
    286286}
    287287
     288/* returns true if the seed ratio applies --
     289 * it applies if the torrent's a seed AND it has a seed ratio set */
     290static tr_bool
     291tr_torrentGetSeedRatioBytes( tr_torrent * tor, uint64_t * setmeLeft, uint64_t * setmeGoal )
     292{
     293    double seedRatio;
     294    tr_bool seedRatioApplies = FALSE;
     295
     296    if( tr_torrentGetSeedRatio( tor, &seedRatio ) )
     297    {
     298        const uint64_t upEver = tor->uploadedCur + tor->uploadedPrev;
     299        const uint64_t goal = seedRatio * tr_cpSizeWhenDone ( &tor->completion );
     300        if( setmeLeft ) *setmeLeft = goal > upEver ? goal - upEver : 0;
     301        if( setmeGoal ) *setmeGoal = goal;
     302        seedRatioApplies = tr_torrentIsSeed( tor );
     303    }
     304
     305    return seedRatioApplies;
     306}
     307
     308static tr_bool
     309tr_torrentIsSeedRatioDone( tr_torrent * tor )
     310{
     311    uint64_t bytesLeft;
     312    return tr_torrentGetSeedRatioBytes( tor, &bytesLeft, NULL ) && !bytesLeft;
     313}
     314
     315void
     316tr_torrentCheckSeedRatio( tr_torrent * tor )
     317{
     318    assert( tr_isTorrent( tor ) );
     319
     320    /* if we're seeding and we've reached our seed ratio limit, stop the torrent */
     321    if( tor->isRunning && tr_torrentIsSeedRatioDone( tor ) )
     322    {
     323        tr_torrentStop( tor );
     324
     325        /* maybe notify the client */
     326        if( tor->ratio_limit_hit_func != NULL )
     327            tor->ratio_limit_hit_func( tor, tor->ratio_limit_hit_func_user_data );
     328    }
     329}
     330
     331
    288332/***
    289333****
     
    919963    int                     usableSeeds;
    920964    uint64_t                now;
    921     double                  downloadedForRatio, seedRatio=0;
    922965    double                  d;
    923     tr_bool                 checkSeedRatio;
     966    uint64_t                seedRatioBytesLeft;
     967    uint64_t                seedRatioBytesGoal;
     968    tr_bool                 seedRatioApplies;
    924969
    925970    if( !tor )
     
    10011046    }
    10021047
    1003     downloadedForRatio = s->downloadedEver ? s->downloadedEver : s->haveValid;
    1004     s->ratio = tr_getRatio( s->uploadedEver, downloadedForRatio );
    1005 
    1006     checkSeedRatio = tr_torrentGetSeedRatio( tor, &seedRatio );
     1048    s->ratio = tr_getRatio( s->uploadedEver,
     1049                            s->downloadedEver ? s->downloadedEver : s->haveValid );
     1050
     1051    seedRatioApplies = tr_torrentGetSeedRatioBytes( tor, &seedRatioBytesLeft,
     1052                                                         &seedRatioBytesGoal );
    10071053
    10081054    switch( s->activity )
     
    10291075            break;
    10301076
    1031         case TR_STATUS_SEED:
    1032             if( checkSeedRatio )
    1033             {
     1077        case TR_STATUS_SEED: {
     1078            if( !seedRatioApplies )
     1079                s->eta = TR_ETA_NOT_AVAIL;
     1080            else {
    10341081                if( ( tor->etaULSpeedCalculatedAt + 800 ) < now ) {
    10351082                    tor->etaULSpeed = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now )
     
    10381085                    tor->etaULSpeedCalculatedAt = now;
    10391086                }
    1040 
    10411087                if( s->pieceUploadSpeed < 0.1 )
    10421088                    s->eta = TR_ETA_UNKNOWN;
    10431089                else
    1044                     s->eta = (downloadedForRatio * (seedRatio - s->ratio)) / tor->etaULSpeed / 1024.0;
     1090                    s->eta = seedRatioBytesLeft / tor->etaULSpeed / 1024.0;
    10451091            }
    1046             else
    1047                 s->eta = TR_ETA_NOT_AVAIL;
    10481092            break;
     1093        }
    10491094
    10501095        default:
     
    10531098    }
    10541099
    1055     s->finished = !s->leftUntilDone && checkSeedRatio && (s->ratio >= seedRatio || s->ratio == TR_RATIO_INF);
    1056 
    1057     if( !checkSeedRatio || s->ratio >= seedRatio || s->ratio == TR_RATIO_INF )
    1058         s->percentRatio = 1.0;
    1059     else if( s->ratio == TR_RATIO_NA )
    1060         s->percentRatio = 0.0;
     1100    s->finished = seedRatioApplies && !seedRatioBytesLeft;
     1101
     1102    if( !seedRatioApplies || s->finished )
     1103        s->seedRatioPercentDone = 1;
     1104    else if( !seedRatioBytesGoal ) /* impossible? safeguard for div by zero */
     1105        s->seedRatioPercentDone = 0;
    10611106    else
    1062         s->percentRatio = s->ratio / seedRatio;
     1107        s->seedRatioPercentDone = (double)(seedRatioBytesGoal - seedRatioBytesLeft) / seedRatioBytesGoal;
    10631108
    10641109    tr_torrentUnlock( tor );
     
    13791424    {
    13801425        /* allow finished torrents to be resumed */
    1381         if( tor->stats.finished )
     1426        if( tr_torrentIsSeedRatioDone( tor ) )
    13821427            tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED );
    13831428
     
    25992644
    26002645void
    2601 tr_torrentCheckSeedRatio( tr_torrent * tor )
    2602 {
    2603     double seedRatio;
    2604 
    2605     assert( tr_isTorrent( tor ) );
    2606 
    2607     /* if we're seeding and we've reached our seed ratio limit, stop the torrent */
    2608     if( tor->isRunning && tr_torrentIsSeed( tor ) && tr_torrentGetSeedRatio( tor, &seedRatio ) )
    2609     {
    2610         const uint64_t up = tor->uploadedCur + tor->uploadedPrev;
    2611         uint64_t down = tor->downloadedCur + tor->downloadedPrev;
    2612         double ratio;
    2613 
    2614         /* maybe we're the initial seeder and never downloaded anything... */
    2615         if( down == 0 )
    2616             down = tr_cpHaveValid( &tor->completion );
    2617 
    2618         ratio = tr_getRatio( up, down );
    2619 
    2620         if( ratio >= seedRatio || ratio == TR_RATIO_INF )
    2621         {
    2622             tr_torrentStop( tor );
    2623 
    2624             /* maybe notify the client */
    2625             if( tor->ratio_limit_hit_func != NULL )
    2626                 tor->ratio_limit_hit_func( tor, tor->ratio_limit_hit_func_user_data );
    2627         }
    2628     }
    2629 }
    2630 
    2631 /***
    2632 ****
    2633 ***/
    2634 
    2635 void
    26362646tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum )
    26372647{
  • trunk/libtransmission/transmission.h

    r10438 r10477  
    17191719    float    percentDone;
    17201720
    1721     /** The percentage of the actual ratio to the seed ratio.  This will be
    1722         equal to 1 if the ratio is reached or the torrent is set to seed forever.
     1721    /** How much has been uploaded to satisfy the seed ratio.
     1722        This is 1 if the ratio is reached or the torrent is set to seed forever.
    17231723        Range is [0..1] */
    1724     float    percentRatio;
     1724    float    seedRatioPercentDone;
    17251725
    17261726    /** Speed all data being sent for this torrent. (KiB/s)
Note: See TracChangeset for help on using the changeset viewer.