Changeset 9793


Ignore:
Timestamp:
Dec 16, 2009, 6:20:01 PM (12 years ago)
Author:
charles
Message:

(trunk) #2548 "T's request queue can send out too many duplicate requests" -- (1) fix r9465 implementation bug that caused some peers to get starved of requests if they rejected a request or choked, then unchoked us. (2) increase a block request's TTL by 15 seconds to reduce cancel/req cycles between two or more blocks (3) add a debug mode to the GTK+ client's peer tab to watch the pending requests counts both up & down

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.am

    r9773 r9793  
    2424  $(GTK_DIR) \
    2525  $(MAC_DIR) \
     26  utils \
    2627  web
    2728
  • trunk/configure.ac

    r9773 r9793  
    447447                 gtk/Makefile
    448448                 gtk/icons/Makefile
     449                 utils/Makefile
    449450                 web/Makefile
    450451                 web/images/Makefile
  • trunk/gtk/conf.c

    r9765 r9793  
    178178    tr_bencDictAddBool( d, PREF_KEY_SHOW_DESKTOP_NOTIFICATION, TRUE );
    179179    tr_bencDictAddBool( d, PREF_KEY_SHOW_MORE_TRACKER_INFO, FALSE );
     180    tr_bencDictAddBool( d, PREF_KEY_SHOW_MORE_PEER_INFO, FALSE );
    180181    tr_bencDictAddBool( d, PREF_KEY_SHOW_BACKUP_TRACKERS, FALSE );
    181182    tr_bencDictAddStr( d, PREF_KEY_STATUSBAR_STATS, "total-ratio" );
  • trunk/gtk/details.c

    r9747 r9793  
    8787    GtkListStore * webseed_store;
    8888    GtkWidget * webseed_view;
     89    GtkWidget * peer_view;
     90    GtkWidget * more_peer_details_check;
    8991
    9092    GtkListStore * trackers;
     
    10871089    PEER_COL_CLIENT,
    10881090    PEER_COL_PROGRESS,
     1091    PEER_COL_UPLOAD_REQUEST_COUNT_INT,
     1092    PEER_COL_UPLOAD_REQUEST_COUNT_STRING,
     1093    PEER_COL_DOWNLOAD_REQUEST_COUNT_INT,
     1094    PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING,
    10891095    PEER_COL_ENCRYPTION_STOCK_ID,
    10901096    PEER_COL_STATUS,
     
    11041110        case PEER_COL_CLIENT: return _( "Client" );
    11051111        case PEER_COL_PROGRESS: return _( "%" );
     1112        case PEER_COL_UPLOAD_REQUEST_COUNT_INT:
     1113        case PEER_COL_UPLOAD_REQUEST_COUNT_STRING: return _( "Up Reqs" );
     1114        case PEER_COL_DOWNLOAD_REQUEST_COUNT_INT:
     1115        case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING: return _( "Dn Reqs" );
    11061116        case PEER_COL_STATUS: return _( "Status" );
    11071117        default: return "";
     
    11231133                               G_TYPE_STRING,   /* client */
    11241134                               G_TYPE_INT,      /* progress [0..100] */
     1135                               G_TYPE_INT,      /* upload request count int */
     1136                               G_TYPE_STRING,   /* upload request count string */
     1137                               G_TYPE_INT,      /* download request count int */
     1138                               G_TYPE_STRING,   /* download request count string */
    11251139                               G_TYPE_STRING,   /* encryption stock id */
    11261140                               G_TYPE_STRING);  /* flagString */
     
    11661180    char up_speed[128];
    11671181    char down_speed[128];
     1182    char up_count[128];
     1183    char down_count[128];
    11681184
    11691185    if( peer->rateToPeer > 0.01 )
     
    11771193        *down_speed = '\0';
    11781194
     1195    if( peer->pendingReqsToPeer > 0 )
     1196        g_snprintf( down_count, sizeof( down_count ), "%d", peer->pendingReqsToPeer );
     1197    else
     1198        *down_count = '\0';
     1199
     1200    if( peer->pendingReqsToClient > 0 )
     1201        g_snprintf( up_count, sizeof( down_count ), "%d", peer->pendingReqsToClient );
     1202    else
     1203        *up_count = '\0';
     1204
    11791205    gtk_list_store_set( store, iter,
    11801206                        PEER_COL_PROGRESS, (int)( 100.0 * peer->progress ),
     1207                        PEER_COL_UPLOAD_REQUEST_COUNT_INT, peer->pendingReqsToClient,
     1208                        PEER_COL_UPLOAD_REQUEST_COUNT_STRING, up_count,
     1209                        PEER_COL_DOWNLOAD_REQUEST_COUNT_INT, peer->pendingReqsToPeer,
     1210                        PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING, down_count,
    11811211                        PEER_COL_DOWNLOAD_RATE_DOUBLE, peer->rateToClient,
    11821212                        PEER_COL_DOWNLOAD_RATE_STRING, down_speed,
     
    14301460#endif
    14311461
     1462static void
     1463setPeerViewColumns( GtkTreeView * peer_view )
     1464{
     1465    int i;
     1466    int n = 0;
     1467    const tr_bool more = pref_flag_get( PREF_KEY_SHOW_MORE_PEER_INFO );
     1468    int view_columns[32];
     1469    GtkTreeViewColumn * c;
     1470    GtkCellRenderer *   r;
     1471
     1472    view_columns[n++] = PEER_COL_ENCRYPTION_STOCK_ID;
     1473    view_columns[n++] = PEER_COL_UPLOAD_RATE_STRING;
     1474    if( more ) view_columns[n++] = PEER_COL_UPLOAD_REQUEST_COUNT_STRING;
     1475    view_columns[n++] = PEER_COL_DOWNLOAD_RATE_STRING;
     1476    if( more ) view_columns[n++] = PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING;
     1477    view_columns[n++] = PEER_COL_PROGRESS;
     1478    view_columns[n++] = PEER_COL_STATUS;
     1479    view_columns[n++] = PEER_COL_ADDRESS;
     1480    view_columns[n++] = PEER_COL_CLIENT;
     1481
     1482    /* remove any existing columns */
     1483    {
     1484        GList * l;
     1485        GList * columns = gtk_tree_view_get_columns( peer_view );
     1486        for( l=columns; l!=NULL; l=l->next )
     1487            gtk_tree_view_remove_column( peer_view, l->data );
     1488        g_list_free( columns );
     1489    }
     1490
     1491    for( i=0; i<n; ++i )
     1492    {
     1493        const int col = view_columns[i];
     1494        const char * t = getPeerColumnName( col );
     1495        int sort_col = col;
     1496
     1497        switch( col )
     1498        {
     1499            case PEER_COL_ADDRESS:
     1500                r = gtk_cell_renderer_text_new( );
     1501                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1502                sort_col = PEER_COL_ADDRESS_COLLATED;
     1503                break;
     1504
     1505            case PEER_COL_CLIENT:
     1506                r = gtk_cell_renderer_text_new( );
     1507                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1508                break;
     1509
     1510            case PEER_COL_PROGRESS:
     1511                r = gtk_cell_renderer_progress_new( );
     1512                c = gtk_tree_view_column_new_with_attributes( t, r, "value", PEER_COL_PROGRESS, NULL );
     1513                break;
     1514
     1515            case PEER_COL_ENCRYPTION_STOCK_ID:
     1516                r = gtk_cell_renderer_pixbuf_new( );
     1517                g_object_set( r, "xalign", (gfloat)0.0,
     1518                                 "yalign", (gfloat)0.5,
     1519                                 NULL );
     1520                c = gtk_tree_view_column_new_with_attributes( t, r, "stock-id", PEER_COL_ENCRYPTION_STOCK_ID, NULL );
     1521                gtk_tree_view_column_set_sizing( c, GTK_TREE_VIEW_COLUMN_FIXED );
     1522                gtk_tree_view_column_set_fixed_width( c, 20 );
     1523                break;
     1524
     1525            case PEER_COL_UPLOAD_REQUEST_COUNT_STRING:
     1526                r = gtk_cell_renderer_text_new( );
     1527                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1528                sort_col = PEER_COL_UPLOAD_REQUEST_COUNT_INT;
     1529                break;
     1530
     1531            case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING:
     1532                r = gtk_cell_renderer_text_new( );
     1533                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1534                sort_col = PEER_COL_DOWNLOAD_REQUEST_COUNT_INT;
     1535                break;
     1536
     1537            case PEER_COL_DOWNLOAD_RATE_STRING:
     1538                r = gtk_cell_renderer_text_new( );
     1539                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1540                sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE;
     1541                break;
     1542
     1543            case PEER_COL_UPLOAD_RATE_STRING:
     1544                r = gtk_cell_renderer_text_new( );
     1545                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1546                sort_col = PEER_COL_UPLOAD_RATE_DOUBLE;
     1547                break;
     1548
     1549            case PEER_COL_STATUS:
     1550                r = gtk_cell_renderer_text_new( );
     1551                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1552                break;
     1553
     1554            default:
     1555                abort( );
     1556        }
     1557
     1558        gtk_tree_view_column_set_resizable( c, FALSE );
     1559        gtk_tree_view_column_set_sort_column_id( c, sort_col );
     1560        gtk_tree_view_append_column( GTK_TREE_VIEW( peer_view ), c );
     1561    }
     1562
     1563    /* the 'expander' column has a 10-pixel margin on the left
     1564       that doesn't look quite correct in any of these columns...
     1565       so create a non-visible column and assign it as the
     1566       'expander column. */
     1567    {
     1568        GtkTreeViewColumn *c = gtk_tree_view_column_new( );
     1569        gtk_tree_view_column_set_visible( c, FALSE );
     1570        gtk_tree_view_append_column( GTK_TREE_VIEW( peer_view ), c );
     1571        gtk_tree_view_set_expander_column( GTK_TREE_VIEW( peer_view ), c );
     1572    }
     1573}
     1574
     1575static void
     1576onMorePeerInfoToggled( GtkToggleButton * button, struct DetailsImpl * di )
     1577{
     1578    const char * key = PREF_KEY_SHOW_MORE_PEER_INFO;
     1579    const gboolean value = gtk_toggle_button_get_active( button );
     1580    tr_core_set_pref_bool( di->core, key, value );
     1581    setPeerViewColumns( GTK_TREE_VIEW( di->peer_view ) );
     1582}
     1583
    14321584static GtkWidget*
    14331585peer_page_new( struct DetailsImpl * di )
    14341586{
    1435     guint i;
     1587    gboolean b;
    14361588    const char * str;
    14371589    GtkListStore *store;
     
    14411593    GtkTreeViewColumn * c;
    14421594    GtkCellRenderer *   r;
    1443     int view_columns[] = { PEER_COL_ENCRYPTION_STOCK_ID,
    1444                            PEER_COL_UPLOAD_RATE_STRING,
    1445                            PEER_COL_DOWNLOAD_RATE_STRING,
    1446                            PEER_COL_PROGRESS,
    1447                            PEER_COL_STATUS,
    1448                            PEER_COL_ADDRESS,
    1449                            PEER_COL_CLIENT };
    1450 
    14511595
    14521596    /* webseeds */
     
    15021646                                  NULL ) );
    15031647#endif
     1648    di->peer_view = v;
    15041649
    15051650#if GTK_CHECK_VERSION( 2,12,0 )
     
    15111656                      G_CALLBACK( on_tree_view_button_released ), NULL );
    15121657
    1513     for( i=0; i<G_N_ELEMENTS( view_columns ); ++i )
    1514     {
    1515         const int col = view_columns[i];
    1516         const char * t = getPeerColumnName( col );
    1517         int sort_col = col;
    1518 
    1519         switch( col )
    1520         {
    1521             case PEER_COL_ADDRESS:
    1522                 r = gtk_cell_renderer_text_new( );
    1523                 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
    1524                 sort_col = PEER_COL_ADDRESS_COLLATED;
    1525                 break;
    1526 
    1527             case PEER_COL_CLIENT:
    1528                 r = gtk_cell_renderer_text_new( );
    1529                 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
    1530                 break;
    1531 
    1532             case PEER_COL_PROGRESS:
    1533                 r = gtk_cell_renderer_progress_new( );
    1534                 c = gtk_tree_view_column_new_with_attributes( t, r, "value", PEER_COL_PROGRESS, NULL );
    1535                 break;
    1536 
    1537             case PEER_COL_ENCRYPTION_STOCK_ID:
    1538                 r = gtk_cell_renderer_pixbuf_new( );
    1539                 g_object_set( r, "xalign", (gfloat)0.0,
    1540                                  "yalign", (gfloat)0.5,
    1541                                  NULL );
    1542                 c = gtk_tree_view_column_new_with_attributes( t, r, "stock-id", PEER_COL_ENCRYPTION_STOCK_ID, NULL );
    1543                 gtk_tree_view_column_set_sizing( c, GTK_TREE_VIEW_COLUMN_FIXED );
    1544                 gtk_tree_view_column_set_fixed_width( c, 20 );
    1545                 break;
    1546 
    1547             case PEER_COL_DOWNLOAD_RATE_STRING:
    1548                 r = gtk_cell_renderer_text_new( );
    1549                 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
    1550                 sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE;
    1551                 break;
    1552 
    1553             case PEER_COL_UPLOAD_RATE_STRING:
    1554                 r = gtk_cell_renderer_text_new( );
    1555                 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
    1556                 sort_col = PEER_COL_UPLOAD_RATE_DOUBLE;
    1557                 break;
    1558 
    1559             case PEER_COL_STATUS:
    1560                 r = gtk_cell_renderer_text_new( );
    1561                 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
    1562                 break;
    1563 
    1564             default:
    1565                 abort( );
    1566         }
    1567 
    1568         gtk_tree_view_column_set_resizable( c, FALSE );
    1569         gtk_tree_view_column_set_sort_column_id( c, sort_col );
    1570         gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c );
    1571     }
    1572 
    1573     /* the 'expander' column has a 10-pixel margin on the left
    1574        that doesn't look quite correct in any of these columns...
    1575        so create a non-visible column and assign it as the
    1576        'expander column. */
    1577     {
    1578         GtkTreeViewColumn *c = gtk_tree_view_column_new( );
    1579         gtk_tree_view_column_set_visible( c, FALSE );
    1580         gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c );
    1581         gtk_tree_view_set_expander_column( GTK_TREE_VIEW( v ), c );
    1582     }
     1658    setPeerViewColumns( GTK_TREE_VIEW( v ) );
    15831659
    15841660    w = sw = gtk_scrolled_window_new( NULL, NULL );
     
    15901666    gtk_container_add( GTK_CONTAINER( w ), v );
    15911667
    1592 
    15931668    vbox = gtk_vbox_new( FALSE, GUI_PAD );
    15941669    gtk_container_set_border_width( GTK_CONTAINER( vbox ), GUI_PAD_BIG );
     
    15981673    gtk_paned_pack2( GTK_PANED( v ), sw, TRUE, TRUE );
    15991674    gtk_box_pack_start( GTK_BOX( vbox ), v, TRUE, TRUE, 0 );
     1675
     1676    w = gtk_check_button_new_with_mnemonic( _( "Show _more details" ) );
     1677    di->more_peer_details_check = w;
     1678    b = pref_flag_get( PREF_KEY_SHOW_MORE_PEER_INFO );
     1679    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), b );
     1680    g_signal_connect( w, "toggled", G_CALLBACK( onMorePeerInfoToggled ), di );
     1681    gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
     1682
    16001683
    16011684    /* ip-to-GtkTreeRowReference */
  • trunk/gtk/tr-prefs.h

    r9671 r9793  
    3232#define PREF_KEY_PLAY_DOWNLOAD_COMPLETE_SOUND      "play-download-complete-sound"
    3333#define PREF_KEY_SHOW_MORE_TRACKER_INFO            "show-tracker-scrapes"
     34#define PREF_KEY_SHOW_MORE_PEER_INFO               "show-extra-peer-details"
    3435#define PREF_KEY_SHOW_BACKUP_TRACKERS              "show-backup-trackers"
    3536#define PREF_KEY_START                             "start-added-torrents"
  • trunk/libtransmission/peer-common.h

    r9671 r9793  
    3434        batch them together to send enough requests to
    3535        meet our bandwidth goals for the next N seconds */
    36     REQUEST_BUF_SECS = 10,
    37 
    38     /** how long we'll let requests we've made stay pending
    39         before we cancel them */
    40     REQUEST_TTL_SECS = 30
     36    REQUEST_BUF_SECS = 10
    4137};
    4238
  • trunk/libtransmission/peer-mgr.c

    r9783 r9793  
    8686
    8787    /* the minimum we'll wait before attempting to reconnect to a peer */
    88     MINIMUM_RECONNECT_INTERVAL_SECS = 5
     88    MINIMUM_RECONNECT_INTERVAL_SECS = 5,
     89
     90    /** how long we'll let requests we've made linger before we cancel them */
     91    REQUEST_TTL_SECS = 45
    8992};
    9093
     
    619622
    620623static void
    621 requestListAdd( Torrent * t, const time_t now, tr_block_index_t block, tr_peer * peer )
     624requestListAdd( Torrent * t, tr_block_index_t block, tr_peer * peer )
    622625{
    623626    struct block_request key;
     
    635638    key.block = block;
    636639    key.peer = peer;
    637     key.sentAt = now;
     640    key.sentAt = tr_time( );
    638641
    639642    /* insert the request to our array... */
     
    658661        }
    659662    }
    660     /*fprintf( stderr, "added request of block %lu from peer %p... "
     663
     664    if( peer != NULL )
     665    {
     666        ++peer->pendingReqsToPeer;
     667        assert( peer->pendingReqsToPeer >= 0 );
     668    }
     669
     670    /*fprintf( stderr, "added request of block %lu from peer %s... "
    661671                       "there are now %d block\n",
    662                        (unsigned long)block, peer, t->requestCount );*/
     672                       (unsigned long)block, tr_atomAddrStr( peer->atom ), t->requestCount );*/
    663673}
    664674
     
    713723        const int pos = b - t->requests;
    714724        assert( pos < t->requestCount );
     725
     726        if( b->peer != NULL )
     727        {
     728            --b->peer->pendingReqsToPeer;
     729            assert( b->peer->pendingReqsToPeer >= 0 );
     730        }
     731
    715732        memmove( t->requests + pos,
    716733                 t->requests + pos + 1,
    717734                 sizeof( struct block_request ) * ( --t->requestCount - pos ) );
    718         /*fprintf( stderr, "removing request of block %lu from peer %p... "
     735        /*fprintf( stderr, "removing request of block %lu from peer %s... "
    719736                           "there are now %d block requests left\n",
    720                            (unsigned long)block, peer, t->requestCount );*/
     737                           (unsigned long)block, tr_atomAddrStr( peer->atom ), t->requestCount );*/
    721738    }
    722739}
     
    952969    struct weighted_piece * pieces;
    953970    const tr_bitset * have = &peer->have;
    954     const time_t now = tr_time( );
    955971
    956972    /* sanity clause */
     
    10011017
    10021018                /* update our own tables */
    1003                 requestListAdd( t, now, b, peer );
     1019                requestListAdd( t, b, peer );
    10041020                ++p->requestCount;
    10051021            }
     
    21952211        tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
    21962212                   sizeof( stat->client ) );
    2197         stat->port               = ntohs( peer->atom->port );
    2198         stat->from               = atom->from;
    2199         stat->progress           = peer->progress;
    2200         stat->isEncrypted        = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
    2201         stat->rateToPeer         = tr_peerGetPieceSpeed( peer, now, TR_CLIENT_TO_PEER );
    2202         stat->rateToClient       = tr_peerGetPieceSpeed( peer, now, TR_PEER_TO_CLIENT );
    2203         stat->peerIsChoked       = peer->peerIsChoked;
    2204         stat->peerIsInterested   = peer->peerIsInterested;
    2205         stat->clientIsChoked     = peer->clientIsChoked;
    2206         stat->clientIsInterested = peer->clientIsInterested;
    2207         stat->isIncoming         = tr_peerIoIsIncoming( peer->io );
    2208         stat->isDownloadingFrom  = clientIsDownloadingFrom( tor, peer );
    2209         stat->isUploadingTo      = clientIsUploadingTo( peer );
    2210         stat->isSeed             = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 );
     2213        stat->port                = ntohs( peer->atom->port );
     2214        stat->from                = atom->from;
     2215        stat->progress            = peer->progress;
     2216        stat->isEncrypted         = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
     2217        stat->rateToPeer          = tr_peerGetPieceSpeed( peer, now, TR_CLIENT_TO_PEER );
     2218        stat->rateToClient        = tr_peerGetPieceSpeed( peer, now, TR_PEER_TO_CLIENT );
     2219        stat->peerIsChoked        = peer->peerIsChoked;
     2220        stat->peerIsInterested    = peer->peerIsInterested;
     2221        stat->clientIsChoked      = peer->clientIsChoked;
     2222        stat->clientIsInterested  = peer->clientIsInterested;
     2223        stat->isIncoming          = tr_peerIoIsIncoming( peer->io );
     2224        stat->isDownloadingFrom   = clientIsDownloadingFrom( tor, peer );
     2225        stat->isUploadingTo       = clientIsUploadingTo( peer );
     2226        stat->isSeed              = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 );
     2227        stat->pendingReqsToPeer   = peer->pendingReqsToPeer;
     2228        stat->pendingReqsToClient = peer->pendingReqsToClient;
    22112229
    22122230        pch = stat->flagStr;
     
    30863104}
    30873105
    3088 static time_t tr_now = 0;
    3089 
    30903106/* best come first, worst go last */
    30913107static int
     
    30973113    const struct peer_atom * b = * (const struct peer_atom**) vb;
    30983114    const int data_time_cutoff_secs = 60 * 60;
     3115    const time_t tr_now = tr_time( );
    30993116
    31003117    assert( tr_isAtom( a ) );
     
    31603177            i = 0;
    31613178            if( keepCount < maxAtomCount ) {
    3162                 tr_now = tr_time( );
    31633179                qsort( test, testCount, sizeof( struct peer_atom * ), compareAtomPtrsByShelfDate );
    31643180                while( i<testCount && keepCount<maxAtomCount )
  • trunk/libtransmission/peer-mgr.h

    r9784 r9793  
    9191    uint8_t                  encryption_preference;
    9292    tr_port                  dht_port;
     93
     94    /* how many requests the peer has made that we haven't responded to yet */
     95    int                      pendingReqsToClient;
     96
     97    /* how many requests we've made and are currently awaiting a response for */
     98    int                      pendingReqsToPeer;
     99
    93100    struct tr_peerIo       * io;
    94101    struct peer_atom       * atom;
  • trunk/libtransmission/peer-msgs.c

    r9786 r9793  
    180180    /*tr_bool         haveFastSet;*/
    181181
    182     int             activeRequestCount;
    183182    int             desiredRequestCount;
    184183
     
    210209
    211210    struct peer_request    peerAskedFor[REQQ];
    212     int                    peerAskedForCount;
    213211
    214212    int                    peerAskedForMetadata[METADATA_REQQ];
     
    757755popNextRequest( tr_peermsgs * msgs, struct peer_request * setme )
    758756{
    759     if( msgs->peerAskedForCount == 0 )
     757    if( msgs->peer->pendingReqsToClient == 0 )
    760758        return FALSE;
    761759
     
    763761
    764762    tr_removeElementFromArray( msgs->peerAskedFor, 0, sizeof( struct peer_request ),
    765                                msgs->peerAskedForCount-- );
     763                               msgs->peer->pendingReqsToClient-- );
    766764
    767765    return TRUE;
     
    836834    return reqIsValid( msgs, req->index, req->offset, req->length );
    837835}
    838 
    839836
    840837void
     
    12581255    else if( peerIsChoked )
    12591256        dbgmsg( msgs, "rejecting request from choked peer" );
    1260     else if( msgs->peerAskedForCount + 1 >= REQQ )
     1257    else if( msgs->peer->pendingReqsToClient + 1 >= REQQ )
    12611258        dbgmsg( msgs, "rejecting request ... reqq is full" );
    12621259    else
     
    12641261
    12651262    if( allow )
    1266         msgs->peerAskedFor[msgs->peerAskedForCount++] = *req;
     1263        msgs->peerAskedFor[msgs->peer->pendingReqsToClient++] = *req;
    12671264    else if( fext )
    12681265        protocolSendReject( msgs, req );
     
    13741371
    13751372static void updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now );
    1376 
    1377 static void
    1378 decrementActiveRequestCount( tr_peermsgs * msgs )
    1379 {
    1380     if( msgs->activeRequestCount > 0 )
    1381         msgs->activeRequestCount--;
    1382 }
    13831373
    13841374static int
     
    14721462            dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length );
    14731463
    1474             for( i=0; i<msgs->peerAskedForCount; ++i ) {
     1464            for( i=0; i<msgs->peer->pendingReqsToClient; ++i ) {
    14751465                const struct peer_request * req = msgs->peerAskedFor + i;
    14761466                if( ( req->index == r.index ) && ( req->offset == r.offset ) && ( req->length == r.length ) )
     
    14781468            }
    14791469
    1480             if( i < msgs->peerAskedForCount )
     1470            if( i < msgs->peer->pendingReqsToClient )
    14811471                tr_removeElementFromArray( msgs->peerAskedFor, i, sizeof( struct peer_request ),
    1482                                            msgs->peerAskedForCount-- );
     1472                                           msgs->peer->pendingReqsToClient-- );
    14831473            break;
    14841474        }
     
    15481538            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset );
    15491539            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length );
    1550             if( fext ) {
    1551                 decrementActiveRequestCount( msgs );
     1540            if( fext )
    15521541                fireGotRej( msgs, &r );
    1553             } else {
     1542            else {
    15541543                fireError( msgs, EMSGSIZE );
    15551544                return READ_ERR;
     
    16331622
    16341623    addPeerToBlamefield( msgs, req->index );
    1635     decrementActiveRequestCount( msgs );
    16361624    fireGotBlock( msgs, req );
    16371625    return 0;
     
    17151703        int estimatedBlocksInPeriod;
    17161704        double rate;
    1717         const int floor = 4;
     1705        const int floor = 2;
    17181706        const int seconds = REQUEST_BUF_SECS;
    17191707
     
    17791767updateBlockRequests( tr_peermsgs * msgs )
    17801768{
    1781     const int MIN_BATCH_SIZE = 4;
    1782     const int numwant = msgs->desiredRequestCount - msgs->activeRequestCount;
    1783 
    1784     /* make sure we have enough block requests queued up */
    1785     if( numwant >= MIN_BATCH_SIZE )
     1769    if( ( msgs->desiredRequestCount > 0 ) &&
     1770        ( msgs->peer->pendingReqsToPeer <= ( msgs->desiredRequestCount * 0.66 ) ) )
    17861771    {
    17871772        int i;
    17881773        int n;
     1774        const int numwant = msgs->desiredRequestCount - msgs->peer->pendingReqsToPeer;
    17891775        tr_block_index_t * blocks = tr_new( tr_block_index_t, numwant );
    17901776
     
    17981784        }
    17991785
    1800         msgs->activeRequestCount += n;
    1801 
    18021786        tr_free( blocks );
    18031787    }
     
    18101794
    18111795    /* Maintain 12 prefetched blocks per unchoked peer */
    1812     for( i=msgs->prefetchCount; i<msgs->peerAskedForCount && i<12; ++i )
     1796    for( i=msgs->prefetchCount; i<msgs->peer->pendingReqsToClient && i<12; ++i )
    18131797    {
    18141798        const struct peer_request * req = msgs->peerAskedFor + i;
     
    23692353    m->outMessagesBatchPeriod = LOW_PRIORITY_INTERVAL_SECS;
    23702354    m->incoming.block = evbuffer_new( );
    2371     m->peerAskedForCount = 0;
    23722355    evtimer_set( &m->pexTimer, pexPulse, m );
    23732356    tr_timerAdd( &m->pexTimer, PEX_INTERVAL_SECS, 0 );
  • trunk/libtransmission/transmission.h

    r9725 r9793  
    13171317typedef struct tr_peer_stat
    13181318{
    1319     tr_bool      isEncrypted;
    1320     tr_bool      isDownloadingFrom;
    1321     tr_bool      isUploadingTo;
    1322     tr_bool      isSeed;
    1323 
    1324     tr_bool      peerIsChoked;
    1325     tr_bool      peerIsInterested;
    1326     tr_bool      clientIsChoked;
    1327     tr_bool      clientIsInterested;
    1328     tr_bool      isIncoming;
    1329 
    1330     uint8_t      from;
    1331     tr_port      port;
    1332 
    1333     char         addr[TR_INET6_ADDRSTRLEN];
    1334     char         client[80];
    1335     char         flagStr[32];
    1336 
    1337     float        progress;
    1338     float        rateToPeer;
    1339     float        rateToClient;
     1319    tr_bool  isEncrypted;
     1320    tr_bool  isDownloadingFrom;
     1321    tr_bool  isUploadingTo;
     1322    tr_bool  isSeed;
     1323
     1324    tr_bool  peerIsChoked;
     1325    tr_bool  peerIsInterested;
     1326    tr_bool  clientIsChoked;
     1327    tr_bool  clientIsInterested;
     1328    tr_bool  isIncoming;
     1329
     1330    uint8_t  from;
     1331    tr_port  port;
     1332
     1333    char     addr[TR_INET6_ADDRSTRLEN];
     1334    char     client[80];
     1335    char     flagStr[32];
     1336
     1337    float    progress;
     1338    float    rateToPeer;
     1339    float    rateToClient;
     1340
     1341    /* how many requests the peer has made that we haven't responded to yet */
     1342    int      pendingReqsToClient;
     1343
     1344    /* how many requests we've made and are currently awaiting a response for */
     1345    int      pendingReqsToPeer;
    13401346}
    13411347tr_peer_stat;
Note: See TracChangeset for help on using the changeset viewer.