diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ef5faa951..5abf512e5 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1290,7 +1290,7 @@ tr_peerMgrTorrentAvailability( const tr_peerMgr * manager, int peerCount; const tr_peer ** peers; - managerLock( (tr_peerMgr*)manager ); + managerLock( manager ); t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); tor = t->tor; @@ -1314,7 +1314,7 @@ tr_peerMgrTorrentAvailability( const tr_peerMgr * manager, } } - managerUnlock( (tr_peerMgr*)manager ); + managerUnlock( manager ); } /* Returns the pieces that are available from peers */ @@ -1326,7 +1326,7 @@ tr_peerMgrGetAvailable( const tr_peerMgr * manager, Torrent * t; tr_peer ** peers; tr_bitfield * pieces; - managerLock( (tr_peerMgr*)manager ); + managerLock( manager ); t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); pieces = tr_bitfieldNew( t->tor->info.pieceCount ); @@ -1334,7 +1334,7 @@ tr_peerMgrGetAvailable( const tr_peerMgr * manager, for( i=0; ihave ); - managerUnlock( (tr_peerMgr*)manager ); + managerUnlock( manager ); tr_free( peers ); return pieces; } @@ -1345,12 +1345,12 @@ tr_peerMgrHasConnections( const tr_peerMgr * manager, { int ret; const Torrent * t; - managerLock( (tr_peerMgr*)manager ); + managerLock( manager ); t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); ret = t && tr_ptrArraySize( t->peers ); - managerUnlock( (tr_peerMgr*)manager ); + managerUnlock( manager ); return ret; } @@ -1368,7 +1368,7 @@ tr_peerMgrTorrentStats( const tr_peerMgr * manager, const Torrent * t; const tr_peer ** peers; - managerLock( (tr_peerMgr*)manager ); + managerLock( manager ); t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &size ); @@ -1404,7 +1404,32 @@ tr_peerMgrTorrentStats( const tr_peerMgr * manager, ++*setmeSeedsConnected; } - managerUnlock( (tr_peerMgr*)manager ); + managerUnlock( manager ); +} + +float* +tr_peerMgrWebSpeeds( const tr_peerMgr * manager, + const uint8_t * torrentHash ) +{ + const Torrent * t; + const tr_webseed ** webseeds; + int i; + int webseedCount; + float * ret; + + assert( manager ); + managerLock( manager ); + + t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); + webseeds = (const tr_webseed**) tr_ptrArrayPeek( t->webseeds, &webseedCount ); + assert( webseedCount == t->tor->info.webseedCount ); + ret = tr_new0( float, webseedCount ); + + for( i=0; ihandle->peerMgr, tor->info.hash ) + : NULL; +} + + tr_peer_stat * tr_torrentPeers( const tr_torrent * tor, int * peerCount ) { diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 775982e31..15320970c 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -966,6 +966,16 @@ tr_peer_stat * tr_torrentPeers( const tr_torrent * torrent, void tr_torrentPeersFree( tr_peer_stat * peerStats, int peerCount ); +/** + * @brief get the download speeds for each of this torrent's webseed sources. + * + * @return an array of tor->info.webseedCount floats giving download speeds. + * Each speed in the array corresponds to the webseed at the same + * array index in tor->info.webseeds. + * NOTE: always free this array with tr_free() when you're done with it. + */ +float* tr_torrentWebSpeeds( const tr_torrent * tor ); + typedef struct tr_file_stat { uint64_t bytesCompleted; diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index 9c620ecb4..307f596e1 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -18,6 +18,7 @@ #include "transmission.h" #include "inout.h" #include "list.h" +#include "ratecontrol.h" #include "torrent.h" #include "utils.h" #include "web.h" @@ -40,6 +41,8 @@ struct tr_webseed tr_piece_index_t queue[MAX_QUEUE_SIZE]; int queueSize; + tr_ratecontrol * rateDown; + struct evbuffer * content; }; @@ -176,6 +179,7 @@ webResponseFunc( tr_handle * session UNUSED, tr_ioWrite( w->torrent, piece, w->bytesSaved, len, EVBUFFER_DATA(w->content) ); evbuffer_drain( w->content, len ); + tr_rcTransferred( w->rateDown, len ); fireClientGotBlock( w, piece, w->bytesSaved, len ); w->bytesSaved += len; @@ -248,6 +252,15 @@ tr_webseedAddRequest( tr_webseed * w, return ret; } +int +tr_webseedGetSpeed( const tr_webseed * w , + float * setme_KiBs ) +{ + const int isBusy = w->queueSize > 0; + *setme_KiBs = isBusy ? tr_rcRate( w->rateDown ) : 0.0f; + return isBusy; +} + /*** **** ***/ @@ -260,6 +273,7 @@ tr_webseedNew( struct tr_torrent * torrent, { tr_webseed * w = tr_new0( tr_webseed, 1 ); w->content = evbuffer_new( ); + w->rateDown = tr_rcInit( ); w->torrent = torrent; w->url = tr_strdup( url ); w->callback = callback; @@ -280,6 +294,7 @@ tr_webseedFree( tr_webseed * w ) else { evbuffer_free( w->content ); + tr_rcClose( w->rateDown ); tr_free( w->url ); tr_free( w ); } diff --git a/libtransmission/webseed.h b/libtransmission/webseed.h index 4bec546c9..7ef33aca2 100644 --- a/libtransmission/webseed.h +++ b/libtransmission/webseed.h @@ -27,4 +27,9 @@ void tr_webseedFree( tr_webseed * ); int tr_webseedAddRequest( tr_webseed * w, tr_piece_index_t piece ); +/** @return true if a request is being processed, or false if idle */ +int tr_webseedGetSpeed( const tr_webseed * w , + float * setme_KiBs ); + + #endif