1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

(libT) new API for webseed statistics: tr_torrentGetWebSpeeds()

This commit is contained in:
Charles Kerr 2008-06-10 01:38:12 +00:00
parent 9f23502411
commit 837f997e6c
6 changed files with 77 additions and 11 deletions

View file

@ -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; i<size; ++i )
tr_bitfieldOr( pieces, peers[i]->have );
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; i<webseedCount; ++i )
tr_webseedGetSpeed( webseeds[i], &ret[i] );
managerUnlock( manager );
return ret;
}
struct tr_peer_stat *
@ -1417,8 +1442,8 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
tr_peer ** peers;
tr_peer_stat * ret;
assert( manager != NULL );
managerLock( (tr_peerMgr*)manager );
assert( manager );
managerLock( manager );
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
peers = getConnectedPeers( (Torrent*)t, &size );
@ -1464,7 +1489,7 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
*setmeCount = size;
tr_free( peers );
managerUnlock( (tr_peerMgr*)manager );
managerUnlock( manager );
return ret;
}

View file

@ -114,6 +114,9 @@ struct tr_peer_stat * tr_peerMgrPeerStats( const tr_peerMgr * manager,
const uint8_t * torrentHash,
int * setmeCount );
float* tr_peerMgrWebSpeeds( const tr_peerMgr * manager,
const uint8_t * torrentHash );
struct tr_bitfield *
tr_peerMgrGenerateAllowedSet( const uint32_t setCount,

View file

@ -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_torrentPeers( const tr_torrent * tor, int * peerCount )
{

View file

@ -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;

View file

@ -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 );
}

View file

@ -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