Changeset 3921


Ignore:
Timestamp:
Nov 21, 2007, 8:03:53 PM (14 years ago)
Author:
charles
Message:

some progress on the overall statistics, though probably not visible to end users yet

Location:
trunk/libtransmission
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r3755 r3921  
    2727    ratecontrol.c \
    2828    shared.c \
     29    stats.c \
    2930    torrent.c \
    3031    tracker.c \
  • trunk/libtransmission/bencode.c

    r3834 r3921  
    3535#include "utils.h"
    3636
     37/**
     38***
     39**/
     40
     41static int
     42tr_bencIsInt ( const benc_val_t * val ) {
     43    return val!=NULL && val->type==TYPE_INT;
     44}
     45
     46static int
     47tr_bencIsList( const benc_val_t * val ) {
     48    return val!=NULL && val->type==TYPE_LIST;
     49}
     50
     51static int
     52tr_bencIsDict( const benc_val_t * val ) {
     53    return val!=NULL && val->type==TYPE_DICT;
     54}
     55
     56/**
     57***
     58**/
     59
    3760/* setting to 1 to help expose bugs with tr_bencListAdd and tr_bencDictAdd */
    3861#define LIST_SIZE   20 /* number of items to increment list/dict buffer by */
     
    195218    {
    196219        case TYPE_INT:
    197             fprintf( stderr, "int:  %"PRId64"\n", val->val.i );
     220            fprintf( stderr, "int:  %"PRId64"\n", tr_bencGetInt(val) );
    198221            break;
    199222
     
    414437    {
    415438        case TYPE_INT:
    416             evbuffer_add_printf( out, "i%"PRId64"e", val->val.i );
     439            evbuffer_add_printf( out, "i%"PRId64"e", tr_bencGetInt(val) );
    417440            break;
    418441
     
    471494**/
    472495
    473 int
    474 tr_bencIsStr ( const benc_val_t * val )
    475 {
    476     return val!=NULL && val->type==TYPE_STR;
    477 }
    478 
    479 int
    480 tr_bencIsInt ( const benc_val_t * val )
    481 {
    482     return val!=NULL && val->type==TYPE_INT;
    483 }
    484 
    485 int
    486 tr_bencIsList( const benc_val_t * val )
    487 {
    488     return val!=NULL && val->type==TYPE_LIST;
    489 }
    490 
    491 int
    492 tr_bencIsDict( const benc_val_t * val )
    493 {
    494     return val!=NULL && val->type==TYPE_DICT;
    495 }
     496benc_val_t*
     497tr_bencDictFindType( benc_val_t * val, const char * key, int type )
     498{
     499    benc_val_t * ret = tr_bencDictFind( val, key );
     500    return ret && ret->type == type ? ret : NULL;
     501}
     502
     503int64_t
     504tr_bencGetInt ( const benc_val_t * val )
     505{
     506    assert( tr_bencIsInt( val ) );
     507    return val->val.i;
     508}
  • trunk/libtransmission/bencode.h

    r3735 r3921  
    6262void         tr_bencFree( benc_val_t * val );
    6363benc_val_t * tr_bencDictFind( benc_val_t * val, const char * key );
     64benc_val_t * tr_bencDictFindType( benc_val_t * val, const char * key, int type );
    6465benc_val_t * tr_bencDictFindFirst( benc_val_t * val, ... );
    6566
     
    8990char*  tr_bencSave( const benc_val_t * val, int * len );
    9091
    91 int    tr_bencIsStr   ( const benc_val_t * val );
    92 int    tr_bencIsInt   ( const benc_val_t * val );
    93 int    tr_bencIsList  ( const benc_val_t * val );
    94 int    tr_bencIsDict  ( const benc_val_t * val );
     92int64_t  tr_bencGetInt ( const benc_val_t * val );
    9593
    9694#endif
  • trunk/libtransmission/internal.h

    r3744 r3921  
    4444#endif
    4545
    46 
    4746void tr_torrentRecheckCompleteness( tr_torrent * );
    4847
     
    193192
    194193    uint8_t                    isClosed;
     194
     195    tr_session_stats           sessionStats;
     196    tr_session_stats           cumulativeStats;
    195197};
    196198
  • trunk/libtransmission/peer-msgs.c

    r3906 r3921  
    3333#include "peer-msgs.h"
    3434#include "ratecontrol.h"
     35#include "stats.h"
    3536#include "trevent.h"
    3637#include "utils.h"
     
    784785
    785786    /* does the peer prefer encrypted connections? */
    786     sub = tr_bencDictFind( &val, "e" );
    787     if( tr_bencIsInt( sub ) )
     787    if(( sub = tr_bencDictFindType( &val, "e", TYPE_INT )))
    788788        msgs->info->encryption_preference = sub->val.i
    789789                                      ? ENCRYPTION_PREFERENCE_YES
     
    791791
    792792    /* check supported messages for utorrent pex */
    793     sub = tr_bencDictFind( &val, "m" );
    794     if( tr_bencIsDict( sub ) ) {
    795         sub = tr_bencDictFind( sub, "ut_pex" );
    796         if( tr_bencIsInt( sub ) ) {
     793    if(( sub = tr_bencDictFindType( &val, "m", TYPE_DICT ))) {
     794        if(( sub = tr_bencDictFindType( sub, "ut_pex", TYPE_INT ))) {
    797795            msgs->peerSupportsPex = 1;
    798796            msgs->ut_pex_id = (uint8_t) sub->val.i;
     
    802800
    803801    /* get peer's listening port */
    804     sub = tr_bencDictFind( &val, "p" );
    805     if( tr_bencIsInt( sub ) ) {
     802    if(( sub = tr_bencDictFindType( &val, "p", TYPE_INT ))) {
    806803        msgs->info->port = htons( (uint16_t)sub->val.i );
    807804        dbgmsg( msgs, "msgs->port is now %hu", msgs->info->port );
     
    824821    tr_peerIoReadBytes( msgs->io, inbuf, tmp, msglen );
    825822
    826     if( tr_bencLoad( tmp, msglen, &val, NULL ) || !tr_bencIsDict( &val ) ) {
     823    if( tr_bencLoad( tmp, msglen, &val, NULL ) || ( val.type != TYPE_DICT ) ) {
    827824        dbgmsg( msgs, "GET can't read extended-pex dictionary" );
    828825        tr_free( tmp );
     
    830827    }
    831828
    832     sub = tr_bencDictFind( &val, "added" );
    833     if( tr_bencIsStr(sub) && ((sub->val.s.i % 6) == 0)) {
     829    if(( sub = tr_bencDictFindType( &val, "added", TYPE_STR ))) {
    834830        const int n = sub->val.s.i / 6 ;
    835831        dbgmsg( msgs, "got %d peers from uT pex", n );
     
    10431039    tr_rcTransferred( tor->download, byteCount );
    10441040    tr_rcTransferred( tor->handle->download, byteCount );
    1045 }
    1046 
     1041    tr_statsAddDownloaded( msgs->handle, byteCount );
     1042}
    10471043
    10481044static int
     
    12671263    tr_rcTransferred( tor->upload, byteCount );
    12681264    tr_rcTransferred( tor->handle->upload, byteCount );
     1265    tr_statsAddUploaded( msgs->handle, byteCount );
    12691266}
    12701267
  • trunk/libtransmission/transmission.c

    r3894 r3921  
    4242#include "ratecontrol.h"
    4343#include "shared.h"
     44#include "stats.h"
    4445#include "trevent.h"
    4546#include "utils.h"
     
    149150
    150151    tr_inf( TR_NAME " " LONG_VERSION_STRING " started" );
     152
     153    tr_statsInit( h );
    151154
    152155    return h;
     
    336339        tr_wait( 100 );
    337340
     341    tr_statsClose( h );
    338342    tr_lockFree( h->lock );
    339343    free( h->tag );
    340344    free( h );
    341 }
    342 
    343 void
    344 tr_getSessionStats( const tr_handle   * handle,
    345                     tr_session_stats  * setme )
    346 {
    347     assert( handle != NULL );
    348     assert( setme != NULL );
    349 
    350     /* FIXME */
    351     setme->downloadedGigs   = 4;
    352     setme->downloadedBytes  = 8;
    353     setme->uploadedGigs     = 15;
    354     setme->uploadedBytes    = 16;
    355     setme->ratio            = 23;
    356     setme->filesAdded       = 42;
    357     setme->sessionCount     = 666;
    358     setme->secondsActive    = 2112;
    359 }
    360 
    361 void
    362 tr_getCumulativeSessionStats( const tr_handle   * handle,
    363                               tr_session_stats  * setme )
    364 {
    365     tr_getSessionStats( handle, setme );
    366345}
    367346
Note: See TracChangeset for help on using the changeset viewer.