Changeset 6112


Ignore:
Timestamp:
Jun 10, 2008, 1:38:12 AM (13 years ago)
Author:
charles
Message:

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

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r6108 r6112  
    12911291    const tr_peer ** peers;
    12921292
    1293     managerLock( (tr_peerMgr*)manager );
     1293    managerLock( manager );
    12941294
    12951295    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     
    13151315    }
    13161316
    1317     managerUnlock( (tr_peerMgr*)manager );
     1317    managerUnlock( manager );
    13181318}
    13191319
     
    13271327    tr_peer ** peers;
    13281328    tr_bitfield * pieces;
    1329     managerLock( (tr_peerMgr*)manager );
     1329    managerLock( manager );
    13301330
    13311331    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     
    13351335        tr_bitfieldOr( pieces, peers[i]->have );
    13361336
    1337     managerUnlock( (tr_peerMgr*)manager );
     1337    managerUnlock( manager );
    13381338    tr_free( peers );
    13391339    return pieces;
     
    13461346    int ret;
    13471347    const Torrent * t;
    1348     managerLock( (tr_peerMgr*)manager );
     1348    managerLock( manager );
    13491349
    13501350    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
    13511351    ret = t && tr_ptrArraySize( t->peers );
    13521352
    1353     managerUnlock( (tr_peerMgr*)manager );
     1353    managerUnlock( manager );
    13541354    return ret;
    13551355}
     
    13691369    const tr_peer ** peers;
    13701370
    1371     managerLock( (tr_peerMgr*)manager );
     1371    managerLock( manager );
    13721372
    13731373    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     
    14051405    }
    14061406
    1407     managerUnlock( (tr_peerMgr*)manager );
     1407    managerUnlock( manager );
     1408}
     1409
     1410float*
     1411tr_peerMgrWebSpeeds( const tr_peerMgr * manager,
     1412                     const uint8_t    * torrentHash )
     1413{
     1414    const Torrent * t;
     1415    const tr_webseed ** webseeds;
     1416    int i;
     1417    int webseedCount;
     1418    float * ret;
     1419
     1420    assert( manager );
     1421    managerLock( manager );
     1422
     1423    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     1424    webseeds = (const tr_webseed**) tr_ptrArrayPeek( t->webseeds, &webseedCount );
     1425    assert( webseedCount == t->tor->info.webseedCount );
     1426    ret = tr_new0( float, webseedCount );
     1427
     1428    for( i=0; i<webseedCount; ++i )
     1429        tr_webseedGetSpeed( webseeds[i], &ret[i] );
     1430
     1431    managerUnlock( manager );
     1432    return ret;
    14081433}
    14091434
     
    14181443    tr_peer_stat * ret;
    14191444
    1420     assert( manager != NULL );
    1421     managerLock( (tr_peerMgr*)manager );
     1445    assert( manager );
     1446    managerLock( manager );
    14221447
    14231448    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     
    14651490    tr_free( peers );
    14661491
    1467     managerUnlock( (tr_peerMgr*)manager );
     1492    managerUnlock( manager );
    14681493    return ret;
    14691494}
  • trunk/libtransmission/peer-mgr.h

    r5985 r6112  
    115115                                           int               * setmeCount );
    116116
     117float* tr_peerMgrWebSpeeds( const tr_peerMgr * manager,
     118                            const uint8_t    * torrentHash );
     119
    117120                             
    118121struct tr_bitfield *
  • trunk/libtransmission/torrent.c

    r6101 r6112  
    865865***/
    866866
     867float*
     868tr_torrentWebSpeeds( const tr_torrent * tor )
     869{
     870    return tor ? tr_peerMgrWebSpeeds( tor->handle->peerMgr, tor->info.hash )
     871               : NULL;
     872}
     873   
     874
    867875tr_peer_stat *
    868876tr_torrentPeers( const tr_torrent * tor, int * peerCount )
  • trunk/libtransmission/transmission.h

    r6073 r6112  
    967967                          int             peerCount );
    968968
     969/**
     970 * @brief get the download speeds for each of this torrent's webseed sources.
     971 *
     972 * @return an array of tor->info.webseedCount floats giving download speeds.
     973 *         Each speed in the array corresponds to the webseed at the same
     974 *         array index in tor->info.webseeds.
     975 *         NOTE: always free this array with tr_free() when you're done with it.
     976 */
     977float* tr_torrentWebSpeeds( const tr_torrent * tor );
     978
    969979typedef struct tr_file_stat
    970980{
  • trunk/libtransmission/webseed.c

    r6101 r6112  
    1919#include "inout.h"
    2020#include "list.h"
     21#include "ratecontrol.h"
    2122#include "torrent.h"
    2223#include "utils.h"
     
    4041    tr_piece_index_t    queue[MAX_QUEUE_SIZE];
    4142    int                 queueSize;
     43
     44    tr_ratecontrol    * rateDown;
    4245
    4346    struct evbuffer   * content;
     
    177180                        EVBUFFER_DATA(w->content) );
    178181            evbuffer_drain( w->content, len );
     182            tr_rcTransferred( w->rateDown, len );
    179183            fireClientGotBlock( w, piece, w->bytesSaved, len );
    180184            w->bytesSaved += len;
     
    249253}
    250254
     255int
     256tr_webseedGetSpeed( const tr_webseed * w ,
     257                    float            * setme_KiBs )
     258{
     259    const int isBusy = w->queueSize > 0;
     260    *setme_KiBs = isBusy ? tr_rcRate( w->rateDown ) : 0.0f;
     261    return isBusy;
     262}
     263
    251264/***
    252265****
     
    261274    tr_webseed * w = tr_new0( tr_webseed, 1 );
    262275    w->content = evbuffer_new( );
     276    w->rateDown = tr_rcInit( );
    263277    w->torrent = torrent;
    264278    w->url = tr_strdup( url );
     
    281295        {
    282296            evbuffer_free( w->content );
     297            tr_rcClose( w->rateDown );
    283298            tr_free( w->url );
    284299            tr_free( w );
  • trunk/libtransmission/webseed.h

    r6101 r6112  
    2828                          tr_piece_index_t      piece );
    2929
     30/** @return true if a request is being processed, or false if idle */
     31int tr_webseedGetSpeed( const tr_webseed * w ,
     32                        float            * setme_KiBs );
     33             
     34
    3035#endif
Note: See TracChangeset for help on using the changeset viewer.