Changeset 10477
- Timestamp:
- Apr 14, 2010, 12:03:23 AM (13 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/torrent.c
r10473 r10477 286 286 } 287 287 288 /* returns true if the seed ratio applies -- 289 * it applies if the torrent's a seed AND it has a seed ratio set */ 290 static tr_bool 291 tr_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 308 static tr_bool 309 tr_torrentIsSeedRatioDone( tr_torrent * tor ) 310 { 311 uint64_t bytesLeft; 312 return tr_torrentGetSeedRatioBytes( tor, &bytesLeft, NULL ) && !bytesLeft; 313 } 314 315 void 316 tr_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 288 332 /*** 289 333 **** … … 919 963 int usableSeeds; 920 964 uint64_t now; 921 double downloadedForRatio, seedRatio=0;922 965 double d; 923 tr_bool checkSeedRatio; 966 uint64_t seedRatioBytesLeft; 967 uint64_t seedRatioBytesGoal; 968 tr_bool seedRatioApplies; 924 969 925 970 if( !tor ) … … 1001 1046 } 1002 1047 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 ); 1007 1053 1008 1054 switch( s->activity ) … … 1029 1075 break; 1030 1076 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 { 1034 1081 if( ( tor->etaULSpeedCalculatedAt + 800 ) < now ) { 1035 1082 tor->etaULSpeed = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now ) … … 1038 1085 tor->etaULSpeedCalculatedAt = now; 1039 1086 } 1040 1041 1087 if( s->pieceUploadSpeed < 0.1 ) 1042 1088 s->eta = TR_ETA_UNKNOWN; 1043 1089 else 1044 s->eta = (downloadedForRatio * (seedRatio - s->ratio))/ tor->etaULSpeed / 1024.0;1090 s->eta = seedRatioBytesLeft / tor->etaULSpeed / 1024.0; 1045 1091 } 1046 else1047 s->eta = TR_ETA_NOT_AVAIL;1048 1092 break; 1093 } 1049 1094 1050 1095 default: … … 1053 1098 } 1054 1099 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; 1061 1106 else 1062 s-> percentRatio = s->ratio / seedRatio;1107 s->seedRatioPercentDone = (double)(seedRatioBytesGoal - seedRatioBytesLeft) / seedRatioBytesGoal; 1063 1108 1064 1109 tr_torrentUnlock( tor ); … … 1379 1424 { 1380 1425 /* allow finished torrents to be resumed */ 1381 if( t or->stats.finished)1426 if( tr_torrentIsSeedRatioDone( tor ) ) 1382 1427 tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED ); 1383 1428 … … 2599 2644 2600 2645 void 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 void2636 2646 tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum ) 2637 2647 { -
trunk/libtransmission/transmission.h
r10438 r10477 1719 1719 float percentDone; 1720 1720 1721 /** The percentage of the actual ratio to the seed ratio. This will be1722 equal to1 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. 1723 1723 Range is [0..1] */ 1724 float percentRatio;1724 float seedRatioPercentDone; 1725 1725 1726 1726 /** Speed all data being sent for this torrent. (KiB/s)
Note: See TracChangeset
for help on using the changeset viewer.