diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index 80a4905e1..a9472ca12 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -17,6 +17,8 @@ #ifndef TR_BANDWIDTH_H #define TR_BANDWIDTH_H +#include + #include "transmission.h" #include "ptrarray.h" #include "utils.h" /* tr_new(), tr_free() */ @@ -34,7 +36,7 @@ enum { HISTORY_MSEC = 2000, INTERVAL_MSEC = HISTORY_MSEC, - GRANULARITY_MSEC = 50, + GRANULARITY_MSEC = 200, HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ), MAGIC_NUMBER = 43143 }; @@ -152,8 +154,8 @@ static TR_INLINE tr_bool tr_isBandwidth( const tr_bandwidth * b ) * @see tr_bandwidthGetDesiredSpeed */ static TR_INLINE void tr_bandwidthSetDesiredSpeed( tr_bandwidth * bandwidth, - tr_direction dir, - double desiredSpeed ) + tr_direction dir, + double desiredSpeed ) { bandwidth->band[dir].desiredSpeed = desiredSpeed; } @@ -238,9 +240,10 @@ void tr_bandwidthSetParent ( tr_bandwidth * bandwidth, * But when we set a torrent's speed mode to TR_SPEEDLIMIT_UNLIMITED, then * in that particular case we want to ignore the global speed limit... */ -static TR_INLINE void tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth, - tr_direction direction, - tr_bool isEnabled ) +static TR_INLINE void +tr_bandwidthHonorParentLimits( tr_bandwidth * bandwidth, + tr_direction direction, + tr_bool isEnabled ) { assert( tr_isBandwidth( bandwidth ) ); assert( tr_isDirection( direction ) ); @@ -248,8 +251,9 @@ static TR_INLINE void tr_bandwidthHonorParentLimits ( tr_bandwidth * band bandwidth->band[direction].honorParentLimits = isEnabled; } -static TR_INLINE tr_bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth * bandwidth, - tr_direction direction ) +static TR_INLINE tr_bool +tr_bandwidthAreParentLimitsHonored( const tr_bandwidth * bandwidth, + tr_direction direction ) { assert( tr_isBandwidth( bandwidth ) ); assert( tr_isDirection( direction ) ); diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 1e3ee622e..65cc54ea2 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1314,7 +1314,7 @@ myHandshakeDoneCB( tr_handshake * handshake, peer->atom = atom; peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is balanced by our unref in peerDestructor() */ - tr_peerIoSetParent( peer->io, t->tor->bandwidth ); + tr_peerIoSetParent( peer->io, &t->tor->bandwidth ); tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag ); success = TRUE; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 3b60dbd61..51010e5cc 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -114,7 +114,7 @@ tr_torrentSetSpeedLimit( tr_torrent * tor, tr_direction dir, int KiB_sec ) assert( tr_isTorrent( tor ) ); assert( tr_isDirection( dir ) ); - tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, KiB_sec ); + tr_bandwidthSetDesiredSpeed( &tor->bandwidth, dir, KiB_sec ); } int @@ -123,7 +123,7 @@ tr_torrentGetSpeedLimit( const tr_torrent * tor, tr_direction dir ) assert( tr_isTorrent( tor ) ); assert( tr_isDirection( dir ) ); - return tr_bandwidthGetDesiredSpeed( tor->bandwidth, dir ); + return tr_bandwidthGetDesiredSpeed( &tor->bandwidth, dir ); } void @@ -132,7 +132,7 @@ tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use ) assert( tr_isTorrent( tor ) ); assert( tr_isDirection( dir ) ); - tr_bandwidthSetLimited( tor->bandwidth, dir, do_use ); + tr_bandwidthSetLimited( &tor->bandwidth, dir, do_use ); } tr_bool @@ -141,7 +141,7 @@ tr_torrentUsesSpeedLimit( const tr_torrent * tor, tr_direction dir ) assert( tr_isTorrent( tor ) ); assert( tr_isDirection( dir ) ); - return tr_bandwidthIsLimited( tor->bandwidth, dir ); + return tr_bandwidthIsLimited( &tor->bandwidth, dir ); } void @@ -149,8 +149,8 @@ tr_torrentUseSessionLimits( tr_torrent * tor, tr_bool doUse ) { assert( tr_isTorrent( tor ) ); - tr_bandwidthHonorParentLimits( tor->bandwidth, TR_UP, doUse ); - tr_bandwidthHonorParentLimits( tor->bandwidth, TR_DOWN, doUse ); + tr_bandwidthHonorParentLimits( &tor->bandwidth, TR_UP, doUse ); + tr_bandwidthHonorParentLimits( &tor->bandwidth, TR_DOWN, doUse ); } tr_bool @@ -158,7 +158,7 @@ tr_torrentUsesSessionLimits( const tr_torrent * tor ) { assert( tr_isTorrent( tor ) ); - return tr_bandwidthAreParentLimitsHonored( tor->bandwidth, TR_UP ); + return tr_bandwidthAreParentLimitsHonored( &tor->bandwidth, TR_UP ); } /*** @@ -542,7 +542,7 @@ torrentRealInit( tr_torrent * tor, const tr_ctor * ctor ) randomizeTiers( info ); - tor->bandwidth = tr_bandwidthNew( session, session->bandwidth ); + tr_bandwidthConstruct( &tor->bandwidth, session, session->bandwidth ); tor->blockSize = getBlockSize( info->pieceSize ); @@ -885,10 +885,10 @@ tr_torrentStat( tr_torrent * tor ) now = tr_date( ); d = tr_peerMgrGetWebseedSpeed( tor, now ); s->swarmSpeed = tr_rcRate( &tor->swarmSpeed, now ); - s->rawUploadSpeed = tr_bandwidthGetRawSpeed ( tor->bandwidth, now, TR_UP ); - s->pieceUploadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_UP ); - s->rawDownloadSpeed = d + tr_bandwidthGetRawSpeed ( tor->bandwidth, now, TR_DOWN ); - s->pieceDownloadSpeed = d + tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_DOWN ); + s->rawUploadSpeed = tr_bandwidthGetRawSpeed ( &tor->bandwidth, now, TR_UP ); + s->pieceUploadSpeed = tr_bandwidthGetPieceSpeed( &tor->bandwidth, now, TR_UP ); + s->rawDownloadSpeed = d + tr_bandwidthGetRawSpeed ( &tor->bandwidth, now, TR_DOWN ); + s->pieceDownloadSpeed = d + tr_bandwidthGetPieceSpeed( &tor->bandwidth, now, TR_DOWN ); usableSeeds += tor->info.webseedCount; @@ -1210,7 +1210,7 @@ freeTorrent( tr_torrent * tor ) assert( session->torrentCount >= 1 ); session->torrentCount--; - tr_bandwidthFree( tor->bandwidth ); + tr_bandwidthDestruct( &tor->bandwidth ); tr_metainfoFree( inf ); tr_free( tor ); @@ -1739,7 +1739,7 @@ tr_torrentGetPriority( const tr_torrent * tor ) { assert( tr_isTorrent( tor ) ); - return tor->bandwidth->priority; + return tor->bandwidth.priority; } void @@ -1748,7 +1748,7 @@ tr_torrentSetPriority( tr_torrent * tor, tr_priority_t priority ) assert( tr_isTorrent( tor ) ); assert( tr_isPriority( priority ) ); - tor->bandwidth->priority = priority; + tor->bandwidth.priority = priority; } /*** diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 3c32caad3..726a468b6 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -17,6 +17,7 @@ #ifndef TR_TORRENT_H #define TR_TORRENT_H 1 +#include "bandwidth.h" /* tr_bandwidth */ #include "completion.h" /* tr_completion */ #include "ratecontrol.h" /* tr_ratecontrol */ #include "session.h" /* tr_globalLock(), tr_globalUnlock() */ @@ -172,6 +173,8 @@ struct tr_torrent struct tr_bitfield checkedPieces; tr_completeness completeness; + struct tr_bandwidth bandwidth; + struct tr_tracker * tracker; struct tr_publisher_tag * trackerSubscription; @@ -213,8 +216,6 @@ struct tr_torrent int uniqueId; - struct tr_bandwidth * bandwidth; - struct tr_torrent_peers * torrentPeers; double desiredRatio;