mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
(libT) new API for webseed statistics: tr_torrentGetWebSpeeds()
This commit is contained in:
parent
9f23502411
commit
837f997e6c
6 changed files with 77 additions and 11 deletions
|
@ -1290,7 +1290,7 @@ tr_peerMgrTorrentAvailability( const tr_peerMgr * manager,
|
||||||
int peerCount;
|
int peerCount;
|
||||||
const tr_peer ** peers;
|
const tr_peer ** peers;
|
||||||
|
|
||||||
managerLock( (tr_peerMgr*)manager );
|
managerLock( manager );
|
||||||
|
|
||||||
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
||||||
tor = t->tor;
|
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 */
|
/* Returns the pieces that are available from peers */
|
||||||
|
@ -1326,7 +1326,7 @@ tr_peerMgrGetAvailable( const tr_peerMgr * manager,
|
||||||
Torrent * t;
|
Torrent * t;
|
||||||
tr_peer ** peers;
|
tr_peer ** peers;
|
||||||
tr_bitfield * pieces;
|
tr_bitfield * pieces;
|
||||||
managerLock( (tr_peerMgr*)manager );
|
managerLock( manager );
|
||||||
|
|
||||||
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
||||||
pieces = tr_bitfieldNew( t->tor->info.pieceCount );
|
pieces = tr_bitfieldNew( t->tor->info.pieceCount );
|
||||||
|
@ -1334,7 +1334,7 @@ tr_peerMgrGetAvailable( const tr_peerMgr * manager,
|
||||||
for( i=0; i<size; ++i )
|
for( i=0; i<size; ++i )
|
||||||
tr_bitfieldOr( pieces, peers[i]->have );
|
tr_bitfieldOr( pieces, peers[i]->have );
|
||||||
|
|
||||||
managerUnlock( (tr_peerMgr*)manager );
|
managerUnlock( manager );
|
||||||
tr_free( peers );
|
tr_free( peers );
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
@ -1345,12 +1345,12 @@ tr_peerMgrHasConnections( const tr_peerMgr * manager,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
const Torrent * t;
|
const Torrent * t;
|
||||||
managerLock( (tr_peerMgr*)manager );
|
managerLock( manager );
|
||||||
|
|
||||||
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
||||||
ret = t && tr_ptrArraySize( t->peers );
|
ret = t && tr_ptrArraySize( t->peers );
|
||||||
|
|
||||||
managerUnlock( (tr_peerMgr*)manager );
|
managerUnlock( manager );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1368,7 +1368,7 @@ tr_peerMgrTorrentStats( const tr_peerMgr * manager,
|
||||||
const Torrent * t;
|
const Torrent * t;
|
||||||
const tr_peer ** peers;
|
const tr_peer ** peers;
|
||||||
|
|
||||||
managerLock( (tr_peerMgr*)manager );
|
managerLock( manager );
|
||||||
|
|
||||||
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
||||||
peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &size );
|
peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &size );
|
||||||
|
@ -1404,7 +1404,32 @@ tr_peerMgrTorrentStats( const tr_peerMgr * manager,
|
||||||
++*setmeSeedsConnected;
|
++*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; i<webseedCount; ++i )
|
||||||
|
tr_webseedGetSpeed( webseeds[i], &ret[i] );
|
||||||
|
|
||||||
|
managerUnlock( manager );
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tr_peer_stat *
|
struct tr_peer_stat *
|
||||||
|
@ -1417,8 +1442,8 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
|
||||||
tr_peer ** peers;
|
tr_peer ** peers;
|
||||||
tr_peer_stat * ret;
|
tr_peer_stat * ret;
|
||||||
|
|
||||||
assert( manager != NULL );
|
assert( manager );
|
||||||
managerLock( (tr_peerMgr*)manager );
|
managerLock( manager );
|
||||||
|
|
||||||
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
||||||
peers = getConnectedPeers( (Torrent*)t, &size );
|
peers = getConnectedPeers( (Torrent*)t, &size );
|
||||||
|
@ -1464,7 +1489,7 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
|
||||||
*setmeCount = size;
|
*setmeCount = size;
|
||||||
tr_free( peers );
|
tr_free( peers );
|
||||||
|
|
||||||
managerUnlock( (tr_peerMgr*)manager );
|
managerUnlock( manager );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,9 @@ struct tr_peer_stat * tr_peerMgrPeerStats( const tr_peerMgr * manager,
|
||||||
const uint8_t * torrentHash,
|
const uint8_t * torrentHash,
|
||||||
int * setmeCount );
|
int * setmeCount );
|
||||||
|
|
||||||
|
float* tr_peerMgrWebSpeeds( const tr_peerMgr * manager,
|
||||||
|
const uint8_t * torrentHash );
|
||||||
|
|
||||||
|
|
||||||
struct tr_bitfield *
|
struct tr_bitfield *
|
||||||
tr_peerMgrGenerateAllowedSet( const uint32_t setCount,
|
tr_peerMgrGenerateAllowedSet( const uint32_t setCount,
|
||||||
|
|
|
@ -864,6 +864,14 @@ tr_torrentFilesFree( tr_file_stat * files, tr_file_index_t fileCount UNUSED )
|
||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
|
|
||||||
|
float*
|
||||||
|
tr_torrentWebSpeeds( const tr_torrent * tor )
|
||||||
|
{
|
||||||
|
return tor ? tr_peerMgrWebSpeeds( tor->handle->peerMgr, tor->info.hash )
|
||||||
|
: NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tr_peer_stat *
|
tr_peer_stat *
|
||||||
tr_torrentPeers( const tr_torrent * tor, int * peerCount )
|
tr_torrentPeers( const tr_torrent * tor, int * peerCount )
|
||||||
{
|
{
|
||||||
|
|
|
@ -966,6 +966,16 @@ tr_peer_stat * tr_torrentPeers( const tr_torrent * torrent,
|
||||||
void tr_torrentPeersFree( tr_peer_stat * peerStats,
|
void tr_torrentPeersFree( tr_peer_stat * peerStats,
|
||||||
int peerCount );
|
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
|
typedef struct tr_file_stat
|
||||||
{
|
{
|
||||||
uint64_t bytesCompleted;
|
uint64_t bytesCompleted;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "inout.h"
|
#include "inout.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "ratecontrol.h"
|
||||||
#include "torrent.h"
|
#include "torrent.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "web.h"
|
#include "web.h"
|
||||||
|
@ -40,6 +41,8 @@ struct tr_webseed
|
||||||
tr_piece_index_t queue[MAX_QUEUE_SIZE];
|
tr_piece_index_t queue[MAX_QUEUE_SIZE];
|
||||||
int queueSize;
|
int queueSize;
|
||||||
|
|
||||||
|
tr_ratecontrol * rateDown;
|
||||||
|
|
||||||
struct evbuffer * content;
|
struct evbuffer * content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -176,6 +179,7 @@ webResponseFunc( tr_handle * session UNUSED,
|
||||||
tr_ioWrite( w->torrent, piece, w->bytesSaved, len,
|
tr_ioWrite( w->torrent, piece, w->bytesSaved, len,
|
||||||
EVBUFFER_DATA(w->content) );
|
EVBUFFER_DATA(w->content) );
|
||||||
evbuffer_drain( w->content, len );
|
evbuffer_drain( w->content, len );
|
||||||
|
tr_rcTransferred( w->rateDown, len );
|
||||||
fireClientGotBlock( w, piece, w->bytesSaved, len );
|
fireClientGotBlock( w, piece, w->bytesSaved, len );
|
||||||
w->bytesSaved += len;
|
w->bytesSaved += len;
|
||||||
|
|
||||||
|
@ -248,6 +252,15 @@ tr_webseedAddRequest( tr_webseed * w,
|
||||||
return ret;
|
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 );
|
tr_webseed * w = tr_new0( tr_webseed, 1 );
|
||||||
w->content = evbuffer_new( );
|
w->content = evbuffer_new( );
|
||||||
|
w->rateDown = tr_rcInit( );
|
||||||
w->torrent = torrent;
|
w->torrent = torrent;
|
||||||
w->url = tr_strdup( url );
|
w->url = tr_strdup( url );
|
||||||
w->callback = callback;
|
w->callback = callback;
|
||||||
|
@ -280,6 +294,7 @@ tr_webseedFree( tr_webseed * w )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
evbuffer_free( w->content );
|
evbuffer_free( w->content );
|
||||||
|
tr_rcClose( w->rateDown );
|
||||||
tr_free( w->url );
|
tr_free( w->url );
|
||||||
tr_free( w );
|
tr_free( w );
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,9 @@ void tr_webseedFree( tr_webseed * );
|
||||||
int tr_webseedAddRequest( tr_webseed * w,
|
int tr_webseedAddRequest( tr_webseed * w,
|
||||||
tr_piece_index_t piece );
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue