(trunk libT) #4402 "Transmission Bandwidth allocation getting overflows" -- use gvdl's patch '4402-uint-bpsoverflow.patch'
This commit is contained in:
parent
99b615b3b8
commit
3398a48e57
|
@ -211,7 +211,7 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
|
||||
/* down_limit_spin */
|
||||
if( n ) {
|
||||
const int baseline = tr_torrentGetSpeedLimit_KBps( torrents[0], TR_DOWN );
|
||||
const unsigned int baseline = tr_torrentGetSpeedLimit_KBps( torrents[0], TR_DOWN );
|
||||
int i;
|
||||
for( i=1; i<n; ++i )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_KBps( torrents[i], TR_DOWN ) ) )
|
||||
|
@ -235,7 +235,7 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
|
||||
/* up_limit_sping */
|
||||
if( n ) {
|
||||
const int baseline = tr_torrentGetSpeedLimit_KBps( torrents[0], TR_UP );
|
||||
const unsigned int baseline = tr_torrentGetSpeedLimit_KBps( torrents[0], TR_UP );
|
||||
int i;
|
||||
for( i=1; i<n; ++i )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_KBps( torrents[i], TR_UP ) ) )
|
||||
|
|
|
@ -174,8 +174,8 @@ allocateBandwidth( tr_bandwidth * b,
|
|||
/* set the available bandwidth */
|
||||
if( b->band[dir].isLimited )
|
||||
{
|
||||
const unsigned int nextPulseSpeed = b->band[dir].desiredSpeed_Bps;
|
||||
b->band[dir].bytesLeft = ( nextPulseSpeed * period_msec ) / 1000u;
|
||||
const uint64_t nextPulseSpeed = b->band[dir].desiredSpeed_Bps;
|
||||
b->band[dir].bytesLeft = (unsigned int)( nextPulseSpeed * period_msec ) / 1000u;
|
||||
}
|
||||
|
||||
/* add this bandwidth's peer, if any, to the peer pool */
|
||||
|
|
|
@ -2676,7 +2676,7 @@ tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor )
|
|||
assert( webseedCount == tor->info.webseedCount );
|
||||
|
||||
for( i=0; i<webseedCount; ++i ) {
|
||||
int Bps;
|
||||
unsigned int Bps;
|
||||
if( tr_webseedGetSpeed_Bps( webseeds[i], now, &Bps ) )
|
||||
ret[i] = Bps / (double)tr_speed_K;
|
||||
else
|
||||
|
@ -2686,7 +2686,7 @@ tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor )
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
unsigned int
|
||||
tr_peerGetPieceSpeed_Bps( const tr_peer * peer, uint64_t now, tr_direction direction )
|
||||
{
|
||||
return peer->io ? tr_peerIoGetPieceSpeed_Bps( peer->io, now, direction ) : 0.0;
|
||||
|
@ -3023,7 +3023,7 @@ isNew( const tr_peer * peer )
|
|||
static int
|
||||
getRate( const tr_torrent * tor, struct peer_atom * atom, uint64_t now )
|
||||
{
|
||||
int Bps;
|
||||
unsigned int Bps;
|
||||
|
||||
if( tr_torrentIsSeed( tor ) )
|
||||
Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_CLIENT_TO_PEER );
|
||||
|
@ -3049,8 +3049,8 @@ isBandwidthMaxedOut( const tr_bandwidth * b,
|
|||
if( !tr_bandwidthIsLimited( b, dir ) )
|
||||
return false;
|
||||
else {
|
||||
const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir );
|
||||
const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir );
|
||||
const unsigned int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir );
|
||||
const unsigned int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir );
|
||||
return got >= want;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,9 +248,9 @@ struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
|
|||
double* tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor );
|
||||
|
||||
|
||||
int tr_peerGetPieceSpeed_Bps( const tr_peer * peer,
|
||||
uint64_t now,
|
||||
tr_direction direction );
|
||||
unsigned int tr_peerGetPieceSpeed_Bps( const tr_peer * peer,
|
||||
uint64_t now,
|
||||
tr_direction direction );
|
||||
|
||||
void tr_peerMgrClearInterest( tr_torrent * tor );
|
||||
|
||||
|
|
|
@ -1676,8 +1676,8 @@ updateDesiredRequestCount( tr_peermsgs * msgs )
|
|||
else
|
||||
{
|
||||
int estimatedBlocksInPeriod;
|
||||
int rate_Bps;
|
||||
int irate_Bps;
|
||||
unsigned int rate_Bps;
|
||||
unsigned int irate_Bps;
|
||||
const int floor = 4;
|
||||
const int seconds = REQUEST_BUF_SECS;
|
||||
const uint64_t now = tr_time_msec( );
|
||||
|
@ -1689,8 +1689,8 @@ updateDesiredRequestCount( tr_peermsgs * msgs )
|
|||
rate_Bps = MIN( rate_Bps, tr_torrentGetSpeedLimit_Bps( torrent, TR_PEER_TO_CLIENT ) );
|
||||
|
||||
/* honor the session limits, if enabled */
|
||||
if( tr_torrentUsesSessionLimits( torrent ) )
|
||||
if( tr_sessionGetActiveSpeedLimit_Bps( torrent->session, TR_PEER_TO_CLIENT, &irate_Bps ) )
|
||||
if( tr_torrentUsesSessionLimits( torrent )
|
||||
&& tr_sessionGetActiveSpeedLimit_Bps( torrent->session, TR_PEER_TO_CLIENT, &irate_Bps ) )
|
||||
rate_Bps = MIN( rate_Bps, irate_Bps );
|
||||
|
||||
/* use this desired rate to figure out how
|
||||
|
|
|
@ -1217,7 +1217,7 @@ tr_sessionGetIdleLimit( const tr_session * session )
|
|||
***/
|
||||
|
||||
bool
|
||||
tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme_Bps )
|
||||
tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, unsigned int * setme_Bps )
|
||||
{
|
||||
int isLimited = true;
|
||||
|
||||
|
@ -1238,7 +1238,7 @@ tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
|
|||
tr_direction dir,
|
||||
double * setme_KBps )
|
||||
{
|
||||
int Bps = 0;
|
||||
unsigned int Bps = 0;
|
||||
const bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps );
|
||||
*setme_KBps = toSpeedKBps( Bps );
|
||||
return is_active;
|
||||
|
@ -1247,7 +1247,7 @@ tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
|
|||
static void
|
||||
updateBandwidth( tr_session * session, tr_direction dir )
|
||||
{
|
||||
int limit_Bps = 0;
|
||||
unsigned int limit_Bps = 0;
|
||||
const bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps );
|
||||
const bool zeroCase = isLimited && !limit_Bps;
|
||||
|
||||
|
@ -1394,23 +1394,22 @@ turtleBootstrap( tr_session * session, struct tr_turtle_info * turtle )
|
|||
***/
|
||||
|
||||
void
|
||||
tr_sessionSetSpeedLimit_Bps( tr_session * s, tr_direction d, int Bps )
|
||||
tr_sessionSetSpeedLimit_Bps( tr_session * s, tr_direction d, unsigned int Bps )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
assert( tr_isDirection( d ) );
|
||||
assert( Bps >= 0 );
|
||||
|
||||
s->speedLimit_Bps[d] = Bps;
|
||||
|
||||
updateBandwidth( s, d );
|
||||
}
|
||||
void
|
||||
tr_sessionSetSpeedLimit_KBps( tr_session * s, tr_direction d, int KBps )
|
||||
tr_sessionSetSpeedLimit_KBps( tr_session * s, tr_direction d, unsigned int KBps )
|
||||
{
|
||||
tr_sessionSetSpeedLimit_Bps( s, d, toSpeedBytes( KBps ) );
|
||||
}
|
||||
|
||||
int
|
||||
unsigned int
|
||||
tr_sessionGetSpeedLimit_Bps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
|
@ -1418,7 +1417,7 @@ tr_sessionGetSpeedLimit_Bps( const tr_session * s, tr_direction d )
|
|||
|
||||
return s->speedLimit_Bps[d];
|
||||
}
|
||||
int
|
||||
unsigned int
|
||||
tr_sessionGetSpeedLimit_KBps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
return toSpeedKBps( tr_sessionGetSpeedLimit_Bps( s, d ) );
|
||||
|
@ -1450,11 +1449,10 @@ tr_sessionIsSpeedLimited( const tr_session * s, tr_direction d )
|
|||
***/
|
||||
|
||||
void
|
||||
tr_sessionSetAltSpeed_Bps( tr_session * s, tr_direction d, int Bps )
|
||||
tr_sessionSetAltSpeed_Bps( tr_session * s, tr_direction d, unsigned int Bps )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
assert( tr_isDirection( d ) );
|
||||
assert( Bps >= 0 );
|
||||
|
||||
s->turtle.speedLimit_Bps[d] = Bps;
|
||||
|
||||
|
@ -1462,12 +1460,12 @@ tr_sessionSetAltSpeed_Bps( tr_session * s, tr_direction d, int Bps )
|
|||
}
|
||||
|
||||
void
|
||||
tr_sessionSetAltSpeed_KBps( tr_session * s, tr_direction d, int KBps )
|
||||
tr_sessionSetAltSpeed_KBps( tr_session * s, tr_direction d, unsigned int KBps )
|
||||
{
|
||||
tr_sessionSetAltSpeed_Bps( s, d, toSpeedBytes( KBps ) );
|
||||
}
|
||||
|
||||
int
|
||||
unsigned int
|
||||
tr_sessionGetAltSpeed_Bps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
|
@ -1475,7 +1473,7 @@ tr_sessionGetAltSpeed_Bps( const tr_session * s, tr_direction d )
|
|||
|
||||
return s->turtle.speedLimit_Bps[d];
|
||||
}
|
||||
int
|
||||
unsigned int
|
||||
tr_sessionGetAltSpeed_KBps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
return toSpeedKBps( tr_sessionGetAltSpeed_Bps( s, d ) );
|
||||
|
@ -1684,13 +1682,13 @@ tr_sessionGetDeleteSource( const tr_session * session )
|
|||
****
|
||||
***/
|
||||
|
||||
int
|
||||
unsigned int
|
||||
tr_sessionGetPieceSpeed_Bps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( &session->bandwidth, 0, dir ) : 0;
|
||||
}
|
||||
|
||||
int
|
||||
unsigned int
|
||||
tr_sessionGetRawSpeed_Bps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( &session->bandwidth, 0, dir ) : 0;
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef void ( tr_web_config_func )( tr_session * session, void * curl_pointer,
|
|||
struct tr_turtle_info
|
||||
{
|
||||
/* TR_UP and TR_DOWN speed limits */
|
||||
int speedLimit_Bps[2];
|
||||
unsigned int speedLimit_Bps[2];
|
||||
|
||||
/* is turtle mode on right now? */
|
||||
bool isEnabled;
|
||||
|
@ -118,7 +118,7 @@ struct tr_session
|
|||
|
||||
int umask;
|
||||
|
||||
int speedLimit_Bps[2];
|
||||
unsigned int speedLimit_Bps[2];
|
||||
bool speedLimitEnabled[2];
|
||||
|
||||
struct tr_turtle_info turtle;
|
||||
|
@ -292,26 +292,30 @@ static inline bool tr_isPriority( tr_priority_t p )
|
|||
****
|
||||
***/
|
||||
|
||||
static inline unsigned int toSpeedBytes ( unsigned int KBps ) { return KBps * tr_speed_K; }
|
||||
static inline double toSpeedKBps ( unsigned int Bps ) { return Bps / (double)tr_speed_K; }
|
||||
static inline unsigned int
|
||||
toSpeedBytes ( unsigned int KBps ) { return KBps * tr_speed_K; }
|
||||
static inline double
|
||||
toSpeedKBps ( unsigned int Bps ) { return Bps / (double)tr_speed_K; }
|
||||
|
||||
static inline uint64_t toMemBytes ( unsigned int MB ) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; }
|
||||
static inline int toMemMB ( uint64_t B ) { return B / ( tr_mem_K * tr_mem_K ); }
|
||||
static inline uint64_t
|
||||
toMemBytes ( unsigned int MB ) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; }
|
||||
static inline int
|
||||
toMemMB ( uint64_t B ) { return B / ( tr_mem_K * tr_mem_K ); }
|
||||
|
||||
/**
|
||||
**/
|
||||
|
||||
int tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction );
|
||||
int tr_sessionGetAltSpeed_Bps ( const tr_session *, tr_direction );
|
||||
int tr_sessionGetRawSpeed_Bps ( const tr_session *, tr_direction );
|
||||
int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction );
|
||||
unsigned int tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction );
|
||||
unsigned int tr_sessionGetAltSpeed_Bps ( const tr_session *, tr_direction );
|
||||
unsigned int tr_sessionGetRawSpeed_Bps ( const tr_session *, tr_direction );
|
||||
unsigned int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
|
||||
void tr_sessionSetAltSpeed_Bps ( tr_session *, tr_direction, int Bps );
|
||||
void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, unsigned int Bps );
|
||||
void tr_sessionSetAltSpeed_Bps ( tr_session *, tr_direction, unsigned int Bps );
|
||||
|
||||
bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
|
||||
tr_direction dir,
|
||||
int * setme );
|
||||
unsigned int * setme );
|
||||
|
||||
tr_torrent * tr_sessionGetNextQueuedSeed( tr_session * session );
|
||||
tr_torrent * tr_sessionGetNextQueuedTorrent( tr_session * session, tr_direction );
|
||||
|
|
|
@ -153,7 +153,7 @@ bool
|
|||
tr_torrentIsPieceTransferAllowed( const tr_torrent * tor,
|
||||
tr_direction direction )
|
||||
{
|
||||
int limit;
|
||||
unsigned int limit;
|
||||
bool allowed = true;
|
||||
|
||||
if( tr_torrentUsesSpeedLimit( tor, direction ) )
|
||||
|
@ -173,22 +173,21 @@ tr_torrentIsPieceTransferAllowed( const tr_torrent * tor,
|
|||
***/
|
||||
|
||||
void
|
||||
tr_torrentSetSpeedLimit_Bps( tr_torrent * tor, tr_direction dir, int Bps )
|
||||
tr_torrentSetSpeedLimit_Bps( tr_torrent * tor, tr_direction dir, unsigned int Bps )
|
||||
{
|
||||
assert( tr_isTorrent( tor ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
assert( Bps >= 0 );
|
||||
|
||||
if( tr_bandwidthSetDesiredSpeed_Bps( &tor->bandwidth, dir, Bps ) )
|
||||
tr_torrentSetDirty( tor );
|
||||
}
|
||||
void
|
||||
tr_torrentSetSpeedLimit_KBps( tr_torrent * tor, tr_direction dir, int KBps )
|
||||
tr_torrentSetSpeedLimit_KBps( tr_torrent * tor, tr_direction dir, unsigned int KBps )
|
||||
{
|
||||
tr_torrentSetSpeedLimit_Bps( tor, dir, toSpeedBytes( KBps ) );
|
||||
}
|
||||
|
||||
int
|
||||
unsigned int
|
||||
tr_torrentGetSpeedLimit_Bps( const tr_torrent * tor, tr_direction dir )
|
||||
{
|
||||
assert( tr_isTorrent( tor ) );
|
||||
|
@ -196,7 +195,7 @@ tr_torrentGetSpeedLimit_Bps( const tr_torrent * tor, tr_direction dir )
|
|||
|
||||
return tr_bandwidthGetDesiredSpeed_Bps( &tor->bandwidth, dir );
|
||||
}
|
||||
int
|
||||
unsigned int
|
||||
tr_torrentGetSpeedLimit_KBps( const tr_torrent * tor, tr_direction dir )
|
||||
{
|
||||
return toSpeedKBps( tr_torrentGetSpeedLimit_Bps( tor, dir ) );
|
||||
|
|
|
@ -414,8 +414,8 @@ char* tr_torrentBuildPartial( const tr_torrent *, tr_file_index_t fileNo );
|
|||
* piece size, etc. such as in BEP 9 where peers exchange metadata */
|
||||
void tr_torrentGotNewInfoDict( tr_torrent * tor );
|
||||
|
||||
void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, int Bps );
|
||||
int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction );
|
||||
void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, unsigned int Bps );
|
||||
unsigned int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction );
|
||||
|
||||
/**
|
||||
* @return true if this piece needs to be tested
|
||||
|
|
|
@ -652,8 +652,8 @@ tr_direction;
|
|||
**** Primary session speed limits
|
||||
***/
|
||||
|
||||
void tr_sessionSetSpeedLimit_KBps ( tr_session *, tr_direction, int KBps );
|
||||
int tr_sessionGetSpeedLimit_KBps ( const tr_session *, tr_direction );
|
||||
void tr_sessionSetSpeedLimit_KBps ( tr_session *, tr_direction, unsigned int KBps );
|
||||
unsigned int tr_sessionGetSpeedLimit_KBps ( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionLimitSpeed ( tr_session *, tr_direction, bool );
|
||||
bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction );
|
||||
|
@ -663,8 +663,8 @@ bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction );
|
|||
**** Alternative speed limits that are used during scheduled times
|
||||
***/
|
||||
|
||||
void tr_sessionSetAltSpeed_KBps ( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetAltSpeed_KBps ( const tr_session *, tr_direction );
|
||||
void tr_sessionSetAltSpeed_KBps ( tr_session *, tr_direction, unsigned int Bps );
|
||||
unsigned int tr_sessionGetAltSpeed_KBps ( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionUseAltSpeed ( tr_session *, bool );
|
||||
bool tr_sessionUsesAltSpeed ( const tr_session * );
|
||||
|
@ -1227,8 +1227,8 @@ char* tr_torrentFindFile( const tr_torrent * tor, tr_file_index_t fileNo );
|
|||
****
|
||||
***/
|
||||
|
||||
void tr_torrentSetSpeedLimit_KBps ( tr_torrent *, tr_direction, int KBps );
|
||||
int tr_torrentGetSpeedLimit_KBps ( const tr_torrent *, tr_direction );
|
||||
void tr_torrentSetSpeedLimit_KBps ( tr_torrent *, tr_direction, unsigned int KBps );
|
||||
unsigned int tr_torrentGetSpeedLimit_KBps ( const tr_torrent *, tr_direction );
|
||||
|
||||
void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, bool );
|
||||
bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction );
|
||||
|
|
|
@ -512,7 +512,9 @@ task_request_next_chunk( struct tr_webseed_task * t )
|
|||
}
|
||||
|
||||
bool
|
||||
tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps )
|
||||
tr_webseedGetSpeed_Bps( const tr_webseed * w,
|
||||
uint64_t now,
|
||||
unsigned int * setme_Bps )
|
||||
{
|
||||
const bool is_active = webseed_has_tasks( w );
|
||||
*setme_Bps = is_active ? tr_bandwidthGetPieceSpeed_Bps( &w->bandwidth, now, TR_DOWN ) : 0;
|
||||
|
@ -522,7 +524,7 @@ tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps )
|
|||
bool
|
||||
tr_webseedIsActive( const tr_webseed * w )
|
||||
{
|
||||
int Bps = 0;
|
||||
unsigned int Bps = 0;
|
||||
return tr_webseedGetSpeed_Bps( w, tr_time_msec(), &Bps ) && ( Bps > 0 );
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ void tr_webseedFree( tr_webseed * );
|
|||
/** @return true if a request is being processed, or false if idle */
|
||||
bool tr_webseedGetSpeed_Bps( const tr_webseed * w,
|
||||
uint64_t now,
|
||||
int * setme_Bps );
|
||||
unsigned int * setme_Bps );
|
||||
|
||||
/** @return true if a request is being processed, or false if idle */
|
||||
bool tr_webseedIsActive( const tr_webseed * w );
|
||||
|
|
Loading…
Reference in New Issue