Changeset 3861


Ignore:
Timestamp:
Nov 17, 2007, 11:43:33 PM (15 years ago)
Author:
charles
Message:

Add "Status" column to tr_peer_stat.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-inspector.c

    r3848 r3861  
    240240  PEER_COL_IS_UPLOADING,
    241241  PEER_COL_UPLOAD_RATE,
     242  PEER_COL_STATUS,
    242243  N_PEER_COLS
    243244};
     
    253254  N_("DL Rate"),
    254255  N_("Uploading"),
    255   N_("UL Rate")
     256  N_("UL Rate"),
     257  N_("Status")
    256258};
    257259
     
    289291                      PEER_COL_IS_UPLOADING, peer->isUploading,
    290292                      PEER_COL_UPLOAD_RATE, peer->uploadToRate,
     293                      PEER_COL_STATUS, peer->status,
    291294                      -1);
    292295}
     
    317320                                         G_TYPE_FLOAT,   /* downloadFromRate */
    318321                                         G_TYPE_BOOLEAN, /* isUploading */
    319                                          G_TYPE_FLOAT);  /* uploadToRate */
     322                                         G_TYPE_FLOAT,   /* uploadToRate */
     323                                         G_TYPE_INT );   /* tr_peer_status */
    320324
    321325  int n_peers = 0;
     
    341345                          "stock-id", (is_encrypted ? "transmission-lock" : NULL),
    342346                          NULL);
     347}
     348
     349static void
     350render_status( GtkTreeViewColumn  * column UNUSED,
     351               GtkCellRenderer    * renderer,
     352               GtkTreeModel       * tree_model,
     353               GtkTreeIter        * iter,
     354               gpointer             data UNUSED )
     355{
     356    int status;
     357    const char * text;
     358    gtk_tree_model_get( tree_model, iter, PEER_COL_STATUS, &status, -1 );
     359    switch( status )
     360    {
     361        case TR_PEER_STATUS_HANDSHAKE:            text = _( "Handshaking" ); break;
     362        case TR_PEER_STATUS_PEER_IS_CHOKED:       text = _( "Peer is Choked" ); break;
     363        case TR_PEER_STATUS_CLIENT_IS_CHOKED:     text = _( "Choked" ); break;
     364        case TR_PEER_STATUS_CLIENT_IS_INTERESTED: text = _( "Choked and Interested" ); break;
     365        case TR_PEER_STATUS_READY:                text = _( "Ready" ); break;
     366        case TR_PEER_STATUS_REQUEST_SENT:         text = _( "Request Sent" ); break;
     367        case TR_PEER_STATUS_ACTIVE           :    text = _( "Active" ); break;
     368        default:                                  text = "BUG"; break;
     369    }
     370    g_object_set (renderer, "text", text, NULL);
    343371}
    344372
     
    496524                         PEER_COL_IS_ENCRYPTED,
    497525                         PEER_COL_UPLOAD_RATE,
    498                          PEER_COL_DOWNLOAD_RATE };
     526                         PEER_COL_DOWNLOAD_RATE,
     527                         PEER_COL_STATUS };
    499528
    500529  m  = peer_model_new (tor);
     
    569598                                                 NULL, NULL);
    570599        break;
     600
     601      case PEER_COL_STATUS:
     602        r = gtk_cell_renderer_text_new( );
     603        c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL);
     604        gtk_tree_view_column_set_cell_data_func (c, r, render_status, NULL, NULL);
     605        break;
     606       
    571607
    572608      default:
  • trunk/libtransmission/peer-mgr-private.h

    r3552 r3861  
    3737    unsigned int  doPurge : 1;
    3838
     39    tr_peer_status status;
    3940
    4041    /* number of bad pieces they've contributed to */
  • trunk/libtransmission/peer-mgr.c

    r3825 r3861  
    3636#include "ratecontrol.h"
    3737#include "shared.h"
     38#include "trcompat.h" /* strlcpy */
    3839#include "trevent.h"
    3940#include "utils.h"
     
    14141415
    14151416        tr_netNtop( &peer->in_addr, stat->addr, sizeof(stat->addr) );
     1417        strlcpy( stat->client, (peer->client ? peer->client : ""), sizeof(stat->client) );
    14161418        stat->port             = peer->port;
    14171419        stat->from             = atom->from;
    1418         stat->client           = tr_strdup( peer->client ? peer->client : "" );
    14191420        stat->progress         = peer->progress;
    14201421        stat->isEncrypted      = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
     
    14231424        stat->isDownloading    = stat->uploadToRate > 0.01;
    14241425        stat->isUploading      = stat->downloadFromRate > 0.01;
     1426        stat->status           = peer->status;
    14251427    }
    14261428
     
    14831485rechoke( Torrent * t )
    14841486{
    1485     int i, peerCount, size=0, unchoked=0;
     1487    int i, peerCount, size=0;
    14861488    const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
    14871489    tr_peer ** peers = getConnectedPeers( t, &peerCount );
     
    15061508    qsort( choke, size, sizeof(struct ChokeData), compareChoke );
    15071509
    1508     for( i=0; i<size && i<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i ) {
     1510    for( i=0; i<size && i<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i )
    15091511        choke[i].doUnchoke = 1;
    1510         ++unchoked;
    1511     }
    15121512
    15131513    for( ; i<size; ++i ) {
    15141514        choke[i].doUnchoke = 1;
    1515         ++unchoked;
    15161515        if( choke[i].peer->peerIsInterested )
    15171516            break;
  • trunk/libtransmission/peer-msgs.c

    r3859 r3861  
    141141    time_t clientSentAnythingAt;
    142142
     143    unsigned int peerSentBitfield         : 1;
    143144    unsigned int peerSupportsPex          : 1;
    144145    unsigned int clientSentLtepHandshake  : 1;
     
    10271028clientGotBlock( tr_peermsgs * msgs, const uint8_t * block, const struct peer_request * req );
    10281029
     1030static void
     1031clientGotBytes( tr_peermsgs * msgs, uint32_t byteCount )
     1032{
     1033    tr_torrent * tor = msgs->torrent;
     1034    tor->activityDate = tr_date( );
     1035    tor->downloadedCur += byteCount;
     1036    msgs->info->pieceDataActivityDate = time( NULL );
     1037    tr_rcTransferred( msgs->info->rcToClient, byteCount );
     1038    tr_rcTransferred( tor->download, byteCount );
     1039    tr_rcTransferred( tor->handle->download, byteCount );
     1040}
     1041
     1042
    10291043static int
    10301044readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
     
    10541068        tr_peerIoReadBytes( msgs->io, inbuf, buf, n );
    10551069        evbuffer_add( msgs->incoming.block, buf, n );
     1070        clientGotBytes( msgs, n );
    10561071        tr_free( buf );
    10571072        dbgmsg( msgs, "got %d bytes for block %u:%u->%u ... %d remain",
     
    11391154            const int clientIsSeed = tr_torrentIsSeed( msgs->torrent );
    11401155            dbgmsg( msgs, "got a bitfield" );
     1156            msgs->peerSentBitfield = 1;
    11411157            tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen );
    11421158            updatePeerProgress( msgs );
     
    12341250
    12351251static void
    1236 clientGotBytes( tr_peermsgs * msgs, uint32_t byteCount )
    1237 {
    1238     tr_torrent * tor = msgs->torrent;
    1239     tor->activityDate = tr_date( );
    1240     tor->downloadedCur += byteCount;
    1241     msgs->info->pieceDataActivityDate = time( NULL );
    1242     tr_rcTransferred( msgs->info->rcToClient, byteCount );
    1243     tr_rcTransferred( tor->download, byteCount );
    1244     tr_rcTransferred( tor->handle->download, byteCount );
    1245 }
    1246 
    1247 static void
    12481252peerGotBytes( tr_peermsgs * msgs, uint32_t byteCount )
    12491253{
     
    13691373
    13701374    msgs->info->peerSentPieceDataAt = time( NULL );
    1371     clientGotBytes( msgs, req->length );
    13721375    i = tr_ioWrite( tor, req->index, req->offset, req->length, data );
    13731376    if( i )
     
    14811484}
    14821485
     1486static void
     1487updatePeerStatus( tr_peermsgs * msgs )
     1488{
     1489    tr_peer * peer = msgs->info;
     1490
     1491    if( !msgs->peerSentBitfield )
     1492        peer->status = TR_PEER_STATUS_HANDSHAKE;
     1493
     1494    else if( ( time(NULL) - peer->pieceDataActivityDate ) < 3 )
     1495        peer->status = TR_PEER_STATUS_ACTIVE;
     1496
     1497    else if( peer->clientIsChoked )
     1498        peer->status = TR_PEER_STATUS_CLIENT_IS_CHOKED;
     1499
     1500    else if( peer->peerIsChoked )
     1501        peer->status = TR_PEER_STATUS_PEER_IS_CHOKED;
     1502
     1503    else if( msgs->clientAskedFor != NULL )
     1504        peer->status = TR_PEER_STATUS_REQUEST_SENT;
     1505
     1506    else if( peer->clientIsInterested )
     1507        peer->status = TR_PEER_STATUS_CLIENT_IS_INTERESTED;
     1508
     1509    else
     1510        peer->status = TR_PEER_STATUS_READY;
     1511}
     1512
    14831513static int
    14841514pulse( void * vmsgs )
     
    14901520
    14911521    tr_peerIoTryRead( msgs->io );
    1492 
    14931522    pumpRequestQueue( msgs );
     1523    updatePeerStatus( msgs );
    14941524
    14951525    if( !canWrite( msgs ) )
     
    17411771    m->torrent = torrent;
    17421772    m->io = info->io;
     1773    m->info->status = TR_PEER_STATUS_HANDSHAKE;
    17431774    m->info->clientIsChoked = 1;
    17441775    m->info->peerIsChoked = 1;
  • trunk/libtransmission/torrent.c

    r3840 r3861  
    881881
    882882void
    883 tr_torrentPeersFree( tr_peer_stat * peers, int peerCount )
    884 {
    885     int i;
    886     for( i=0; i<peerCount; ++i )
    887         tr_free( (char*) peers[i].client );
     883tr_torrentPeersFree( tr_peer_stat * peers, int peerCount UNUSED )
     884{
    888885    tr_free( peers );
    889886}
  • trunk/libtransmission/transmission.h

    r3810 r3861  
    684684};
    685685
     686typedef enum
     687{
     688    TR_PEER_STATUS_HANDSHAKE,
     689    TR_PEER_STATUS_PEER_IS_CHOKED,
     690    TR_PEER_STATUS_CLIENT_IS_CHOKED,
     691    TR_PEER_STATUS_CLIENT_IS_INTERESTED,
     692    TR_PEER_STATUS_READY,
     693    TR_PEER_STATUS_REQUEST_SENT,
     694    TR_PEER_STATUS_ACTIVE
     695}
     696tr_peer_status;
     697
    686698struct tr_peer_stat
    687699{
    688     char    addr[INET_ADDRSTRLEN];
    689     const char * client;
     700    char addr[INET_ADDRSTRLEN];
     701    char client[80];
    690702   
    691703    unsigned int isEncrypted   : 1;
    692704    unsigned int isDownloading : 1;
    693705    unsigned int isUploading   : 1;
     706
     707    tr_peer_status status;
    694708
    695709    uint8_t  from;
Note: See TracChangeset for help on using the changeset viewer.