Changeset 5086


Ignore:
Timestamp:
Feb 21, 2008, 7:29:39 AM (14 years ago)
Author:
charles
Message:

libT: add tracker information to tr_stat. gtk: add `tracker' tab to inspector

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/details.c

    r5074 r5086  
    10561056
    10571057/****
     1058*****  TRACKER
     1059****/
     1060
     1061#define TRACKER_PAGE "tracker-page"
     1062
     1063struct tracker_page
     1064{
     1065    TrTorrent * gtor;
     1066
     1067    GtkWidget * last_scrape_time_lb;
     1068    GtkWidget * last_scrape_response_lb;
     1069    GtkWidget * next_scrape_countdown_lb;
     1070
     1071    GtkWidget * last_announce_time_lb;
     1072    GtkWidget * last_announce_response_lb;
     1073    GtkWidget * next_announce_countdown_lb;
     1074    GtkWidget * manual_announce_countdown_lb;
     1075};
     1076
     1077GtkWidget*
     1078tracker_page_new( TrTorrent * gtor )
     1079{
     1080    GtkWidget * t;
     1081    GtkWidget * l;
     1082    int row = 0;
     1083    const char * s;
     1084    struct tracker_page * page = g_new0( struct tracker_page, 1 );
     1085
     1086    page->gtor = gtor;
     1087
     1088    t = hig_workarea_create( );
     1089    hig_workarea_add_section_title( t, &row, _( "Scrape" ) );
     1090
     1091        s = _( "Last scrape at:" );
     1092        l = gtk_label_new( NULL );
     1093        page->last_scrape_time_lb = l;
     1094        hig_workarea_add_row( t, &row, s, l, NULL );
     1095
     1096        s = _( "Tracker responded: ");
     1097        l = gtk_label_new( NULL );
     1098        page->last_scrape_response_lb = l;
     1099        hig_workarea_add_row( t, &row, s, l, NULL );
     1100
     1101        s = _( "Next scrape in:" );
     1102        l = gtk_label_new( NULL );
     1103        page->next_scrape_countdown_lb = l;
     1104        hig_workarea_add_row( t, &row, s, l, NULL );
     1105
     1106    hig_workarea_add_section_divider( t, &row );
     1107    hig_workarea_add_section_title( t, &row, _( "Announce" ) );
     1108
     1109        s = _( "Last announce at:" );
     1110        l = gtk_label_new( NULL );
     1111        page->last_announce_time_lb = l;
     1112        hig_workarea_add_row( t, &row, s, l, NULL );
     1113
     1114        s = _( "Tracker responded: ");
     1115        l = gtk_label_new( NULL );
     1116        page->last_announce_response_lb = l;
     1117        hig_workarea_add_row( t, &row, s, l, NULL );
     1118
     1119        s = _( "Next announce in:" );
     1120        l = gtk_label_new( NULL );
     1121        page->next_announce_countdown_lb = l;
     1122        hig_workarea_add_row( t, &row, s, l, NULL );
     1123
     1124        s = _( "Manual announce allowed in:" );
     1125        l = gtk_label_new( NULL );
     1126        page->manual_announce_countdown_lb = l;
     1127        hig_workarea_add_row( t, &row, s, l, NULL );
     1128
     1129    g_object_set_data_full( G_OBJECT( t ), TRACKER_PAGE, page, g_free );
     1130    hig_workarea_finish( t, &row );
     1131    return t;
     1132}
     1133
     1134static void
     1135refresh_countdown_lb( GtkWidget * l, time_t t )
     1136{
     1137    const char * n_a = _( "N/A" );
     1138    const time_t now = time( NULL );
     1139    char buf[1024];
     1140
     1141    if( !t )
     1142        gtk_label_set_text( GTK_LABEL( l ), n_a );
     1143    else if( t < now )
     1144        gtk_label_set_text( GTK_LABEL( l ), n_a );
     1145    else {
     1146        const int seconds = t - now;
     1147        tr_strltime( buf, seconds, sizeof( buf ) );
     1148        gtk_label_set_text( GTK_LABEL( l ), buf );
     1149    }
     1150}
     1151
     1152static void
     1153refresh_time_lb( GtkWidget * l, time_t t )
     1154{
     1155    const char * never = _( "Never" );
     1156    if( !t )
     1157        gtk_label_set_text( GTK_LABEL( l ), never );
     1158    else {
     1159        char * str = rfc822date( t * 1000 );
     1160        gtk_label_set_text( GTK_LABEL( l ), str );
     1161        g_free( str );
     1162    }
     1163}
     1164
     1165static void
     1166refresh_tracker( GtkWidget * w )
     1167{
     1168    GtkWidget * l;
     1169    time_t t;
     1170    struct tracker_page * page = g_object_get_data( G_OBJECT( w ), TRACKER_PAGE );
     1171    const tr_stat * torStat = tr_torrent_stat( page->gtor );
     1172
     1173    l = page->last_scrape_time_lb;
     1174    t = torStat->tracker_stat.lastScrapeTime;
     1175    refresh_time_lb( l, t );
     1176
     1177    l = page->last_scrape_response_lb;
     1178    gtk_label_set_text( GTK_LABEL( l ), torStat->tracker_stat.scrapeResponse );
     1179
     1180    l = page->next_scrape_countdown_lb;
     1181    t = torStat->tracker_stat.nextScrapeTime;
     1182    refresh_countdown_lb( l, t );
     1183
     1184    l = page->last_announce_time_lb;
     1185    t = torStat->tracker_stat.lastAnnounceTime;
     1186    refresh_time_lb( l, t );
     1187
     1188    l = page->last_announce_response_lb;
     1189    gtk_label_set_text( GTK_LABEL( l ), torStat->tracker_stat.announceResponse );
     1190
     1191    l = page->next_announce_countdown_lb;
     1192    t = torStat->tracker_stat.nextAnnounceTime;
     1193    refresh_countdown_lb( l, t );
     1194
     1195    l = page->manual_announce_countdown_lb;
     1196    t = torStat->tracker_stat.nextManualAnnounceTime;
     1197    refresh_countdown_lb( l, t );
     1198}
     1199
     1200/****
    10581201*****  DIALOG
    10591202****/
     
    10811224periodic_refresh (gpointer data)
    10821225{
     1226  refresh_tracker   (g_object_get_data (G_OBJECT(data), "tracker-top"));
    10831227  refresh_peers     (g_object_get_data (G_OBJECT(data), "peers-top"));
    10841228  refresh_activity  (g_object_get_data (G_OBJECT(data), "activity-top"));
     
    11351279                            gtk_label_new (_("Files")));
    11361280
     1281  w = tracker_page_new( gtor );
     1282  g_object_set_data( G_OBJECT( d ), "tracker-top", w );
     1283  gtk_notebook_append_page( GTK_NOTEBOOK( n ), w,
     1284                            gtk_label_new( _( "Tracker" ) ) );
     1285
    11371286  w = options_page_new (gtor);
    11381287  g_object_set_data (G_OBJECT(d), "options-top", w);
  • trunk/libtransmission/torrent.c

    r5081 r5086  
    578578    s->tracker = tr_trackerGetAddress( tor->tracker );
    579579
     580    tr_trackerStat( tor->tracker, &s->tracker_stat );
     581
    580582    tr_peerMgrTorrentStats( tor->handle->peerMgr,
    581583                            tor->info.hash,
  • trunk/libtransmission/tracker.c

    r5028 r5086  
    2929#include "torrent.h"
    3030#include "tracker.h"
     31#include "trcompat.h" /* strlcpy */
    3132#include "trevent.h"
    3233#include "utils.h"
     
    115116    time_t reannounceAt;
    116117    time_t scrapeAt;
     118
     119    time_t lastScrapeTime;
     120    char lastScrapeResponse[512];
     121
     122    time_t lastAnnounceTime;
     123    char lastAnnounceResponse[512];
    117124
    118125    int randOffset;
     
    256263    event.peerCount = count;
    257264    event.peerCompact = peers;
    258     tr_inf( "Torrent \"%s\" got %d new peers", t->name, count );
     265    tr_dbg( "Torrent \"%s\" got %d new peers", t->name, count );
    259266    if( count )
    260267        tr_publisherPublish( t->publisher, t, &event );
     
    412419                                               : "(null)" );
    413420
    414     tr_inf( "Torrent \"%s\" tracker response: %s",
     421    *t->lastAnnounceResponse = '\0';
     422    if( req && req->response_code_line )
     423        strlcpy( t->lastAnnounceResponse, req->response_code_line, sizeof( t->lastAnnounceResponse ) );
     424
     425    tr_dbg( "Torrent \"%s\" tracker response: %s",
    415426            t->name,
    416427            ( req ? req->response_code_line : "(null)") );
     
    573584        return;
    574585
    575     tr_inf( "Got scrape response for  '%s': %s",
     586    *t->lastScrapeResponse = '\0';
     587    if( req && req->response_code_line )
     588        strlcpy( t->lastScrapeResponse, req->response_code_line, sizeof( t->lastScrapeResponse ) );
     589
     590    tr_dbg( "Got scrape response for  '%s': %s",
    576591            t->name,
    577592            ( ( req && req->response_code_line ) ? req->response_code_line
     
    868883invokeRequest( tr_handle * handle, const struct tr_tracker_request * req )
    869884{
     885    const time_t now = time( NULL );
    870886    struct evhttp_connection * evcon = getConnection( handle, req->address, req->port );
    871887    tr_tracker * t = findTracker( handle, req->torrent_hash );
     
    873889    evhttp_connection_set_timeout( evcon, req->timeout );
    874890    ++handle->tracker->socketCount;
     891
     892    if( t != NULL )
     893    {
     894        if( req->reqtype == TR_REQ_SCRAPE )
     895        {
     896            t->lastScrapeTime = now;
     897            t->scrapeAt = 0;
     898        }
     899        else
     900        {
     901            t->lastAnnounceTime = now;
     902            t->reannounceAt = 0;
     903            t->manualAnnounceAllowedAt = 0;
     904        }
     905    }
     906
    875907    if( evhttp_make_request( evcon, req->req, EVHTTP_REQ_GET, req->uri ))
    876908        (*req->req->cb)(req->req, req->req->cb_arg);
     
    11881220    if( t->isRunning ) {
    11891221        t->isRunning = 0;
     1222        t->reannounceAt = t->manualAnnounceAllowedAt = 0;
    11901223        enqueueRequest( t->handle, t, TR_REQ_STOPPED );
    11911224    }
     
    11981231        tr_trackerReannounce( t );
    11991232}
     1233
     1234void
     1235tr_trackerStat( const tr_tracker * t,
     1236                struct tr_tracker_stat * setme)
     1237{
     1238    assert( t != NULL );
     1239    assert( setme != NULL );
     1240
     1241    strlcpy( setme->scrapeResponse,
     1242             t->lastScrapeResponse,
     1243             sizeof( setme->scrapeResponse ) );
     1244    setme->lastScrapeTime = t->lastScrapeTime;
     1245    setme->nextScrapeTime = t->scrapeAt;
     1246
     1247    strlcpy( setme->announceResponse,
     1248             t->lastAnnounceResponse,
     1249             sizeof( setme->announceResponse ) );
     1250    setme->lastAnnounceTime = t->lastAnnounceTime;
     1251    setme->nextAnnounceTime = t->reannounceAt;
     1252    setme->nextManualAnnounceTime = t->manualAnnounceAllowedAt;
     1253}
  • trunk/libtransmission/tracker.h

    r4996 r5086  
    7171***/
    7272
     73void tr_trackerStat                         ( const tr_tracker       * tracker,
     74                                              struct tr_tracker_stat * setme);
     75
    7376void tr_trackerStart                        ( struct tr_tracker * );
    7477
  • trunk/libtransmission/transmission.h

    r5066 r5086  
    158158int tr_getMessageLevel( void );
    159159
     160typedef struct tr_msg_list
     161{
     162    uint8_t              level;
     163    time_t               when;
     164    char               * message;
     165    const char         * file;
     166    int                  line;
     167    struct tr_msg_list * next;
     168}
     169tr_msg_list;
     170
    160171void tr_setMessageQueuing( int enable );
    161172
    162 typedef struct tr_msg_list tr_msg_list;
    163173tr_msg_list * tr_getQueuedMessages( void );
    164174void tr_freeMessageList( tr_msg_list * freeme );
     
    713723#define TR_ERROR_IS_TC(e) (TR_ERROR_TC_ERROR<=(e) && (e)<=TR_ERROR_TC_WARNING)
    714724
     725struct tr_tracker_stat
     726{
     727    char scrapeResponse[512];
     728    char announceResponse[512];
     729    time_t lastScrapeTime;
     730    time_t lastAnnounceTime;
     731    time_t nextScrapeTime;
     732    time_t nextAnnounceTime;
     733    time_t nextManualAnnounceTime;
     734};
     735
    715736struct tr_stat
    716737{
    717     tr_torrent_status   status;
    718 
    719     tr_errno            error;
    720     char                errorString[128];
    721 
     738    tr_torrent_status status;
     739
     740    struct tr_tracker_stat tracker_stat;
    722741    const tr_tracker_info * tracker;
    723742
    724     float               recheckProgress;
    725     float               percentComplete;
    726     float               percentDone;
    727     float               rateDownload;
    728     float               rateUpload;
    729     int                 eta;
    730     int                 peersKnown;
    731     int                 peersConnected;
    732     int                 peersFrom[TR_PEER_FROM__MAX];
    733     int                 peersSendingToUs;
    734     int                 peersGettingFromUs;
    735     int                 seeders;
    736     int                 leechers;
    737     int                 completedFromTracker;
     743    tr_errno error;
     744    char errorString[128];
     745
     746
     747    float recheckProgress;
     748    float percentComplete;
     749    float percentDone;
     750    float rateDownload;
     751    float rateUpload;
     752
     753    int eta;
     754    int peersKnown;
     755    int peersConnected;
     756    int peersFrom[TR_PEER_FROM__MAX];
     757    int peersSendingToUs;
     758    int peersGettingFromUs;
     759    int seeders;
     760    int leechers;
     761    int completedFromTracker;
    738762
    739763    /* if the torrent is running, this is the time at which
    740764     * the client can manually ask the torrent's tracker
    741765     * for more peers.  otherwise, the value is zero. */
    742     time_t              manualAnnounceTime;
     766    time_t manualAnnounceTime;
    743767
    744768    /* Byte count of how much data is left to be downloaded until
    745769     * we're done -- that is, until we've got all the pieces we wanted. */
    746     uint64_t            leftUntilDone;
     770    uint64_t leftUntilDone;
    747771
    748772    /* Byte count of all the corrupt data you've ever downloaded for
    749773     * this torrent.  If you're on a poisoned torrent, this number can
    750774     * grow very large. */
    751     uint64_t            corruptEver;
     775    uint64_t corruptEver;
    752776
    753777    /* Byte count of all data you've ever uploaded for this torrent. */
    754     uint64_t            uploadedEver;
     778    uint64_t uploadedEver;
    755779
    756780    /* Byte count of all the non-corrupt data you've ever downloaded
    757781     * for this torrent.  If you deleted the files and downloaded a second time,
    758782     * this will be 2*totalSize.. */
    759     uint64_t            downloadedEver;
     783    uint64_t downloadedEver;
    760784
    761785    /* Byte count of all the checksum-verified data we have for this torrent. */
    762     uint64_t            haveValid;
     786    uint64_t haveValid;
    763787
    764788    /* Byte count of all the partial piece data we have for this torrent.
    765789     * As pieces become complete, this value may decrease as portions of it are
    766790     * moved to `corrupt' or `haveValid'. */
    767     uint64_t            haveUnchecked;
     791    uint64_t haveUnchecked;
    768792
    769793    /* Byte count of all the non-DND piece data that either we already have,
    770794     * or that a peer we're connected to has. [0...desiredSize] */
    771     uint64_t            desiredAvailable;
     795    uint64_t desiredAvailable;
    772796
    773797    /* Byte count of all the piece data we want, whether we currently
    774798     * have it nor not. [0...tr_info.totalSize] */
    775     uint64_t            desiredSize;
    776 
    777     float               swarmspeed;
     799    uint64_t desiredSize;
     800
     801    float swarmspeed;
    778802
    779803#define TR_RATIO_NA  -1
    780804#define TR_RATIO_INF -2
    781805    /* TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
    782     float               ratio;
     806    float ratio;
    783807   
    784     uint64_t            startDate;
    785     uint64_t            activityDate;
     808    uint64_t startDate;
     809    uint64_t activityDate;
    786810};
    787811
     
    817841};
    818842
    819 struct tr_msg_list
    820 {
    821     uint8_t              level;
    822     time_t               when;
    823     char               * message;
    824     const char         * file;
    825     int                  line;
    826     struct tr_msg_list * next;
    827 };
    828 
    829843
    830844#ifdef __TRANSMISSION__
Note: See TracChangeset for help on using the changeset viewer.