Changeset 10332


Ignore:
Timestamp:
Mar 8, 2010, 4:29:58 AM (11 years ago)
Author:
charles
Message:

(trunk) #2993 "'Downloaded' much greater than 'Have' or 'verified'" -- add new congestion-based throttle for 2.0

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/details.c

    r10231 r10332  
    10661066    PEER_COL_DOWNLOAD_REQUEST_COUNT_INT,
    10671067    PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING,
     1068    PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT,
     1069    PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING,
     1070    PEER_COL_BLOCKS_UPLOADED_COUNT_INT,
     1071    PEER_COL_BLOCKS_UPLOADED_COUNT_STRING,
     1072    PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT,
     1073    PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING,
     1074    PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT,
     1075    PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING,
    10681076    PEER_COL_ENCRYPTION_STOCK_ID,
    10691077    PEER_COL_STATUS,
     
    10871095        case PEER_COL_DOWNLOAD_REQUEST_COUNT_INT:
    10881096        case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING: return _( "Dn Reqs" );
     1097        case PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT:
     1098        case PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING: return _( "Dn Blocks" );
     1099        case PEER_COL_BLOCKS_UPLOADED_COUNT_INT:
     1100        case PEER_COL_BLOCKS_UPLOADED_COUNT_STRING: return _( "Up Blocks" );
     1101        case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT:
     1102        case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING: return _( "We Cancelled" );
     1103        case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT:
     1104        case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING: return _( "They Cancelled" );
    10891105        case PEER_COL_STATUS: return _( "Status" );
    10901106        default: return "";
     
    11101126                               G_TYPE_INT,      /* download request count int */
    11111127                               G_TYPE_STRING,   /* download request count string */
     1128                               G_TYPE_INT,      /* # blocks downloaded int */
     1129                               G_TYPE_STRING,   /* # blocks downloaded string */
     1130                               G_TYPE_INT,      /* # blocks uploaded int */
     1131                               G_TYPE_STRING,   /* # blocks uploaded string */
     1132                               G_TYPE_INT,      /* # blocks cancelled by client int */
     1133                               G_TYPE_STRING,   /* # blocks cancelled by client string */
     1134                               G_TYPE_INT,      /* # blocks cancelled by peer int */
     1135                               G_TYPE_STRING,   /* # blocks cancelled by peer string */
    11121136                               G_TYPE_STRING,   /* encryption stock id */
    11131137                               G_TYPE_STRING);  /* flagString */
     
    11511175                const tr_peer_stat  * peer )
    11521176{
    1153     char up_speed[128];
    1154     char down_speed[128];
    1155     char up_count[128];
    1156     char down_count[128];
     1177    char up_speed[64];
     1178    char down_speed[64];
     1179    char up_count[64];
     1180    char down_count[64];
     1181    char blocks_to_peer[64];
     1182    char blocks_to_client[64];
     1183    char cancelled_by_peer[64];
     1184    char cancelled_by_client[64];
    11571185
    11581186    if( peer->rateToPeer > 0.01 )
     
    11751203    else
    11761204        *up_count = '\0';
     1205
     1206    if( peer->blocksToPeer > 0 )
     1207        g_snprintf( blocks_to_peer, sizeof( blocks_to_peer ), "%"PRIu32, peer->blocksToPeer );
     1208    else
     1209        *blocks_to_peer = '\0';
     1210
     1211    if( peer->blocksToClient > 0 )
     1212        g_snprintf( blocks_to_client, sizeof( blocks_to_client ), "%"PRIu32, peer->blocksToClient );
     1213    else
     1214        *blocks_to_client = '\0';
     1215
     1216    if( peer->cancelsToPeer > 0 )
     1217        g_snprintf( cancelled_by_client, sizeof( cancelled_by_client ), "%"PRIu32, peer->cancelsToPeer );
     1218    else
     1219        *cancelled_by_client = '\0';
     1220
     1221    if( peer->cancelsToClient > 0 )
     1222        g_snprintf( cancelled_by_peer, sizeof( cancelled_by_peer ), "%"PRIu32, peer->cancelsToClient );
     1223    else
     1224        *cancelled_by_peer = '\0';
    11771225
    11781226    gtk_list_store_set( store, iter,
     
    11881236                        PEER_COL_STATUS, peer->flagStr,
    11891237                        PEER_COL_WAS_UPDATED, TRUE,
     1238                        PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT, (int)peer->blocksToClient,
     1239                        PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING, blocks_to_client,
     1240                        PEER_COL_BLOCKS_UPLOADED_COUNT_INT, (int)peer->blocksToPeer,
     1241                        PEER_COL_BLOCKS_UPLOADED_COUNT_STRING, blocks_to_peer,
     1242                        PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT, (int)peer->cancelsToPeer,
     1243                        PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING, cancelled_by_client,
     1244                        PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT, (int)peer->cancelsToClient,
     1245                        PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING, cancelled_by_peer,
    11901246                        -1 );
    11911247}
     
    14481504    view_columns[n++] = PEER_COL_DOWNLOAD_RATE_STRING;
    14491505    if( more ) view_columns[n++] = PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING;
     1506    if( more ) view_columns[n++] = PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING;
     1507    if( more ) view_columns[n++] = PEER_COL_BLOCKS_UPLOADED_COUNT_STRING;
     1508    if( more ) view_columns[n++] = PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING;
     1509    if( more ) view_columns[n++] = PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING;
    14501510    view_columns[n++] = PEER_COL_PROGRESS;
    14511511    view_columns[n++] = PEER_COL_STATUS;
     
    14961556                break;
    14971557
     1558            case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING:
     1559                r = gtk_cell_renderer_text_new( );
     1560                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1561                sort_col = PEER_COL_DOWNLOAD_REQUEST_COUNT_INT;
     1562                break;
    14981563            case PEER_COL_UPLOAD_REQUEST_COUNT_STRING:
    14991564                r = gtk_cell_renderer_text_new( );
     
    15021567                break;
    15031568
    1504             case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING:
     1569            case PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING:
    15051570                r = gtk_cell_renderer_text_new( );
    15061571                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
    1507                 sort_col = PEER_COL_DOWNLOAD_REQUEST_COUNT_INT;
     1572                sort_col = PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT;
     1573                break;
     1574            case PEER_COL_BLOCKS_UPLOADED_COUNT_STRING:
     1575                r = gtk_cell_renderer_text_new( );
     1576                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1577                sort_col = PEER_COL_BLOCKS_UPLOADED_COUNT_INT;
     1578                break;
     1579           
     1580            case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING:
     1581                r = gtk_cell_renderer_text_new( );
     1582                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1583                sort_col = PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT;
     1584                break;
     1585            case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING:
     1586                r = gtk_cell_renderer_text_new( );
     1587                c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
     1588                sort_col = PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT;
    15081589                break;
    15091590
     
    15131594                sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE;
    15141595                break;
    1515 
    15161596            case PEER_COL_UPLOAD_RATE_STRING:
    15171597                r = gtk_cell_renderer_text_new( );
  • trunk/gtk/my-valgrind.sh

    r9916 r10332  
    33export G_DEBUG=gc-friendly
    44export GLIBCXX_FORCE_NEW=1
    5 valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=yes ./transmission
     5valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=yes ./transmission -p 2>&1 | tee runlog
  • trunk/libtransmission/Makefile.am

    r9795 r10332  
    2929    ggets.c \
    3030    handshake.c \
     31    history.c \
    3132    inout.c \
    3233    json.c \
     
    7879    ggets.h \
    7980    handshake.h \
     81    history.h \
    8082    inout.h \
    8183    json.h \
     
    118120    bencode-test \
    119121    clients-test \
     122    history-test \
    120123    json-test \
    121124    magnet-test \
     
    154157clients_test_LDFLAGS = ${apps_ldflags}
    155158
     159history_test_SOURCES = history-test.c
     160history_test_LDADD = ${apps_ldadd}
     161history_test_LDFLAGS = ${apps_ldflags}
     162
    156163json_test_SOURCES = json-test.c
    157164json_test_LDADD = ${apps_ldadd}
  • trunk/libtransmission/fdlimit.c

    r10321 r10332  
    324324    errno = err;
    325325#endif
    326     fsync( fd );
    327326    close( fd );
    328327}
  • trunk/libtransmission/peer-mgr.c

    r10329 r10332  
    8484
    8585    /** how long we'll let requests we've made linger before we cancel them */
    86     REQUEST_TTL_SECS = 60
     86    REQUEST_TTL_SECS = 60,
     87
     88    HISTORY_SEC = TORRENT_DOWNLOAD_CONGESTION_HISTORY_SEC
    8789};
    8890
     
    179181    struct weighted_piece    * pieces;
    180182    int                        pieceCount;
     183
     184    int                        interestedCount;
     185
     186    /* An arbitrary metric of how congested the downloads are.
     187     * Based on how many of requests are cancelled and how many are completed.
     188     * Lower values indicate less congestion. */
     189    double                     downloadCongestion;
    181190}
    182191Torrent;
     
    332341{
    333342    tr_peer * peer = tr_new0( tr_peer, 1 );
     343
    334344    tr_bitsetConstructor( &peer->have, 0 );
     345
    335346    peer->atom = atom;
    336347    atom->peer = peer;
     348
     349    peer->blocksSentToClient  = tr_historyNew( HISTORY_SEC, 1 );
     350    peer->blocksSentToPeer    = tr_historyNew( HISTORY_SEC, 1 );
     351    peer->cancelsSentToClient = tr_historyNew( HISTORY_SEC, 1 );
     352    peer->cancelsSentToPeer   = tr_historyNew( HISTORY_SEC, 1 );
     353
    337354    return peer;
    338355}
     
    373390    tr_peerIoClear( peer->io );
    374391    tr_peerIoUnref( peer->io ); /* balanced by the ref in handshakeDoneCB() */
     392
     393    tr_historyFree( peer->blocksSentToClient  );
     394    tr_historyFree( peer->blocksSentToPeer    );
     395    tr_historyFree( peer->cancelsSentToClient );
     396    tr_historyFree( peer->cancelsSentToPeer   );
    375397
    376398    tr_bitsetDestructor( &peer->have );
     
    10861108{
    10871109    time_t now;
     1110    uint64_t now_msec;
    10881111    time_t too_old;
    10891112    tr_torrent * tor;
     
    10921115
    10931116    now = tr_time( );
     1117    now_msec = tr_date( );
    10941118    too_old = now - REQUEST_TTL_SECS;
    10951119
     
    11251149            for( it=cancel, end=it+cancelCount; it!=end; ++it ) {
    11261150                if( ( it->peer != NULL ) && ( it->peer->msgs != NULL ) ) {
     1151                    tr_historyAdd( it->peer->cancelsSentToPeer, now_msec, 1 );
     1152                    tr_historyAdd( tor->cancelsSentToPeer, now_msec, 1 );
    11271153                    tr_peerMsgsCancel( it->peer->msgs, it->block );
    11281154                    decrementPendingReqCount( it );
     
    13561382        {
    13571383            tr_torrent * tor = t->tor;
     1384            uint64_t now_msec;
    13581385            tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset );
    13591386
    13601387            requestListRemove( t, block, peer );
    13611388            pieceListRemoveRequest( t, block );
     1389
     1390            now_msec = tr_date( );
     1391            tr_historyAdd( tor->blocksSentToClient, now_msec, 1 );
     1392            if( peer != NULL )
     1393                tr_historyAdd( peer->blocksSentToClient, now_msec, 1 );
    13621394
    13631395            if( tr_cpBlockIsComplete( &tor->completion, block ) )
     
    22362268        stat->isUploadingTo       = clientIsUploadingTo( peer );
    22372269        stat->isSeed              = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 );
     2270
     2271        stat->blocksToPeer        = tr_historyGet( peer->blocksSentToPeer,    now, HISTORY_SEC*1000 );
     2272        stat->blocksToClient      = tr_historyGet( peer->blocksSentToClient,  now, HISTORY_SEC*1000 );
     2273        stat->cancelsToPeer       = tr_historyGet( peer->cancelsSentToPeer,   now, HISTORY_SEC*1000 );
     2274        stat->cancelsToClient     = tr_historyGet( peer->cancelsSentToClient, now, HISTORY_SEC*1000 );
     2275
    22382276        stat->pendingReqsToPeer   = peer->pendingReqsToPeer;
    22392277        stat->pendingReqsToClient = peer->pendingReqsToClient;
     
    22642302**/
    22652303
     2304/* do we still want this piece and does the peer have it? */
     2305static tr_bool
     2306isPieceInteresting( const tr_torrent * tor, const tr_peer * peer, tr_piece_index_t index )
     2307{
     2308    return ( !tor->info.pieces[index].dnd ) /* we want it */
     2309        && ( !tr_cpPieceIsComplete( &tor->completion, index ) )  /* we don't have it */
     2310        && ( tr_bitsetHas( &peer->have, index ) ); /* peer has it */
     2311}
     2312
     2313/* does this peer have any pieces that we want? */
     2314static tr_bool
     2315isPeerInteresting( const tr_torrent * tor, const tr_peer * peer )
     2316{
     2317    tr_piece_index_t i, n;
     2318
     2319    if ( tr_torrentIsSeed( tor ) )
     2320        return FALSE;
     2321
     2322    if( !tr_torrentIsPieceTransferAllowed( tor, TR_PEER_TO_CLIENT ) )
     2323        return FALSE;
     2324
     2325    for( i=0, n=tor->info.pieceCount; i<n; ++i )
     2326        if( isPieceInteresting( tor, peer, i ) )
     2327            return TRUE;
     2328
     2329    return FALSE;
     2330}
     2331
     2332/* determines who we send "interested" messages to */
     2333static void
     2334rechokeDownloads( Torrent * t )
     2335{
     2336    int i;
     2337    const uint64_t now = tr_date( );
     2338    const int msec = 60 * 1000;
     2339    const int MIN_INTERESTING_PEERS = 5;
     2340    const int peerCount = tr_ptrArraySize( &t->peers );
     2341    int maxPeers;
     2342
     2343    int badCount         = 0;
     2344    int goodCount        = 0;
     2345    int untestedCount    = 0;
     2346    tr_peer ** bad       = tr_new( tr_peer*, peerCount );
     2347    tr_peer ** good      = tr_new( tr_peer*, peerCount );
     2348    tr_peer ** untested  = tr_new( tr_peer*, peerCount );
     2349
     2350    /* decide how many peers to be interested in */
     2351    {
     2352        const int blocks = tr_historyGet( t->tor->blocksSentToClient, now, msec );
     2353        const int cancels = tr_historyGet( t->tor->cancelsSentToPeer, now, msec );
     2354
     2355        if( !cancels && !t->interestedCount )
     2356        {
     2357            /* this is the torrent's first time to call this function...
     2358             * start off optimistically by allowing interest in many peers */
     2359            maxPeers = t->tor->maxConnectedPeers;
     2360        }
     2361        else if( !blocks )
     2362        {
     2363            /* we've gotten cancels but zero blocks...
     2364             * something is seriously wrong.  throttle back sharply */
     2365            maxPeers = t->interestedCount * 0.5;
     2366        }
     2367        else
     2368        {
     2369            const double c = ( cancels * 30.0 ) / blocks;
     2370                 if( c > 5   ) maxPeers = t->interestedCount * 0.7;
     2371            else if( c > 3   ) maxPeers = t->interestedCount * 0.8;
     2372            else if( c > 1   ) maxPeers = t->interestedCount * 0.9;
     2373            else if( c > 0.5 ) maxPeers = t->interestedCount;
     2374            else               maxPeers = t->interestedCount + 1;
     2375
     2376            /* if things are getting worse, don't add more peers */
     2377            if( ( t->downloadCongestion > 0.1 ) && ( c > t->downloadCongestion ) )
     2378                maxPeers = MIN( maxPeers, t->interestedCount );
     2379
     2380            t->downloadCongestion = c;
     2381/*fprintf( stderr, "OVERALL TORRENT DOWNLOAD CONGESTION: %.3f... num allowed goes from %d to %d\n", c, t->interestedCount, maxPeers );*/
     2382        }
     2383    }
     2384
     2385    /* don't let the previous paragraph's number tweaking go too far... */
     2386    maxPeers = MAX( maxPeers, MIN_INTERESTING_PEERS );
     2387    maxPeers = MIN( maxPeers, t->tor->maxConnectedPeers );
     2388
     2389    /* separate the peers into "good" (ones with a low cancel-to-block ratio),
     2390     * untested peers, and "bad" (ones with a high cancel-to-block ratio).
     2391     * That's the order in which we'll choose who to show interest in */
     2392    for( i=0; i<peerCount; ++i )
     2393    {
     2394        tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
     2395
     2396        if( !isPeerInteresting( t->tor, peer ) )
     2397        {
     2398            tr_peerMsgsSetInterested( peer->msgs, FALSE );
     2399        }
     2400        else
     2401        {
     2402            const int blocks = tr_historyGet( peer->blocksSentToClient, now, msec );
     2403            const int cancels = tr_historyGet( peer->cancelsSentToPeer, now, msec );
     2404
     2405            if( !blocks && !cancels )
     2406                untested[untestedCount++] = peer;
     2407            else if( !cancels )
     2408                good[goodCount++] = peer;
     2409            else if( !blocks )
     2410                bad[badCount++] = peer;
     2411            else if( ( ( cancels * 10.0 ) / blocks ) < 1.0 )
     2412                good[goodCount++] = peer;
     2413            else
     2414                bad[badCount++] = peer;
     2415        }
     2416    }
     2417   
     2418    t->interestedCount = 0;
     2419
     2420    /* We've decided (1) how many peers to be interested in,
     2421     * and (2) which peers are the best candidates,
     2422     * Now it's time to update our `interest' flags. */
     2423    for( i=0; i<goodCount; ++i ) {
     2424        const tr_bool b = t->interestedCount < maxPeers;
     2425        tr_peerMsgsSetInterested( good[i]->msgs, b );
     2426        if( b )
     2427            ++t->interestedCount;
     2428    }
     2429    for( i=0; i<untestedCount; ++i ) {
     2430        const tr_bool b = t->interestedCount < maxPeers;
     2431        tr_peerMsgsSetInterested( untested[i]->msgs, b );
     2432        if( b )
     2433            ++t->interestedCount;
     2434    }
     2435    for( i=0; i<badCount; ++i ) {
     2436        const tr_bool b = t->interestedCount < maxPeers;
     2437        tr_peerMsgsSetInterested( bad[i]->msgs, b );
     2438        if( b )
     2439            ++t->interestedCount;
     2440    }
     2441
     2442/*fprintf( stderr, "num interested: %d\n", t->interestedCount );*/
     2443       
     2444    /* cleanup */
     2445    tr_free( untested );
     2446    tr_free( good );
     2447    tr_free( bad );
     2448}
     2449
     2450/**
     2451***
     2452**/
     2453
    22662454struct ChokeData
    22672455{
     
    22972485
    22982486static void
    2299 rechokeTorrent( Torrent * t, const uint64_t now )
     2487rechokeUploads( Torrent * t, const uint64_t now )
    23002488{
    23012489    int i, size, unchokedInterested;
     
    24052593    while(( tor = tr_torrentNext( mgr->session, tor ))) {
    24062594        if( tor->isRunning ) {
    2407             rechokeTorrent( tor->torrentPeers, now );
     2595            rechokeUploads( tor->torrentPeers, now );
     2596            if( !tr_torrentIsSeed( tor ) )
     2597                rechokeDownloads( tor->torrentPeers );
    24082598        }
    24092599    }
  • trunk/libtransmission/peer-mgr.h

    r10031 r10332  
    2626#include "bitfield.h"
    2727#include "bitset.h"
     28#include "history.h"
    2829#include "net.h"
    2930#include "peer-common.h" /* struct peer_request */
     
    110111
    111112    time_t                   chokeChangedAt;
     113
     114    time_t                   lastBlocksAtTime;
     115    int                      blocksAt[60];
     116
     117    time_t                   lastCancelTime;
     118    int                      cancelAt[60];
     119
     120    tr_recentHistory       * blocksSentToClient;
     121    tr_recentHistory       * blocksSentToPeer;
     122
     123    tr_recentHistory       * cancelsSentToClient;
     124    tr_recentHistory       * cancelsSentToPeer;
    112125
    113126    struct tr_peermsgs     * msgs;
  • trunk/libtransmission/peer-msgs.c

    r10325 r10332  
    675675**/
    676676
    677 static tr_bool
    678 isPieceInteresting( const tr_peermsgs * msgs,
    679                     tr_piece_index_t    piece )
    680 {
    681     const tr_torrent * torrent = msgs->torrent;
    682 
    683     return ( !torrent->info.pieces[piece].dnd )                  /* we want it */
    684           && ( !tr_cpPieceIsComplete( &torrent->completion, piece ) ) /* !have */
    685           && ( tr_bitsetHas( &msgs->peer->have, piece ) );      /* peer has it */
    686 }
    687 
    688 /* "interested" means we'll ask for piece data if they unchoke us */
    689 static tr_bool
    690 isPeerInteresting( const tr_peermsgs * msgs )
    691 {
    692     tr_piece_index_t    i;
    693     const tr_torrent *  torrent;
    694     const tr_bitfield * bitfield;
    695     const int           clientIsSeed = tr_torrentIsSeed( msgs->torrent );
    696 
    697     if( clientIsSeed )
    698         return FALSE;
    699 
    700     if( !tr_torrentIsPieceTransferAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )
    701         return FALSE;
    702 
    703     torrent = msgs->torrent;
    704     bitfield = tr_cpPieceBitfield( &torrent->completion );
    705 
    706     for( i = 0; i < torrent->info.pieceCount; ++i )
    707         if( isPieceInteresting( msgs, i ) )
    708             return TRUE;
    709 
    710     return FALSE;
    711 }
    712 
    713677static void
    714678sendInterest( tr_peermsgs * msgs, tr_bool clientIsInterested )
     
    729693
    730694static void
    731 updateInterest( tr_peermsgs * msgs )
    732 {
    733     const int i = isPeerInteresting( msgs );
    734 
    735     if( i != msgs->peer->clientIsInterested )
    736         sendInterest( msgs, i );
     695updateInterest( tr_peermsgs * msgs UNUSED )
     696{
     697    /* FIXME -- might need to poke the mgr on startup */
     698}
     699
     700void
     701tr_peerMsgsSetInterested( tr_peermsgs * msgs, int isInterested )
     702{
     703    assert( tr_isBool( isInterested ) );
     704
     705    if( isInterested != msgs->peer->clientIsInterested )
     706        sendInterest( msgs, isInterested );
    737707}
    738708
     
    838808{
    839809    struct peer_request req;
     810/*fprintf( stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n", (size_t)block, msgs->peer );*/
    840811    blockToReq( msgs->torrent, block, &req );
    841812    protocolSendCancel( msgs, &req );
     
    14691440            int i;
    14701441            struct peer_request r;
     1442            const uint64_t now_msec = tr_date( );
    14711443            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.index );
    14721444            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset );
    14731445            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length );
     1446            tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 );
     1447            tr_historyAdd( msgs->peer->cancelsSentToClient, now_msec, 1 );
    14741448            dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length );
    14751449
     
    19531927            else
    19541928            {
     1929                const uint64_t now_msec = tr_date( );
    19551930                dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length );
    19561931                EVBUFFER_LENGTH(out) += req.length;
     
    19591934                bytesWritten += EVBUFFER_LENGTH( out );
    19601935                msgs->clientSentAnythingAt = now;
     1936                tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 );
     1937                tr_historyAdd( msgs->peer->blocksSentToPeer, now_msec, 1 );
    19611938            }
    19621939
  • trunk/libtransmission/peer-msgs.h

    r10302 r10332  
    4444int          tr_peerMsgsIsReadingBlock( const tr_peermsgs * msgs, tr_block_index_t block );
    4545
     46void         tr_peerMsgsSetInterested( tr_peermsgs *, int isInterested );
     47
    4648void         tr_peerMsgsHave( tr_peermsgs * msgs,
    4749                              uint32_t      pieceIndex );
  • trunk/libtransmission/torrent.c

    r10308 r10332  
    611611    static int nextUniqueId = 1;
    612612    tr_session * session = tr_ctorGetSession( ctor );
     613    const int sec = TORRENT_DOWNLOAD_CONGESTION_HISTORY_SEC;
    613614
    614615    assert( session != NULL );
     
    619620    tor->uniqueId = nextUniqueId++;
    620621    tor->magicNumber = TORRENT_MAGIC_NUMBER;
     622
     623    tor->blocksSentToClient  = tr_historyNew( sec, 1 );
     624    tor->blocksSentToPeer    = tr_historyNew( sec, 1 );
     625    tor->cancelsSentToClient = tr_historyNew( sec, 1 );
     626    tor->cancelsSentToPeer   = tr_historyNew( sec, 1 );
    621627
    622628    tr_sha1( tor->obfuscatedHash, "req2", 4,
     
    12911297
    12921298    tr_bitfieldDestruct( &tor->checkedPieces );
     1299
     1300    tr_historyFree( tor->blocksSentToClient  );
     1301    tr_historyFree( tor->blocksSentToPeer    );
     1302    tr_historyFree( tor->cancelsSentToClient );
     1303    tr_historyFree( tor->cancelsSentToPeer   );
    12931304
    12941305    tr_free( tor->downloadDir );
  • trunk/libtransmission/torrent.h

    r10084 r10332  
    1919
    2020#include "completion.h" /* tr_completion */
     21#include "history.h" /* tr_recentHistory */
    2122#include "session.h" /* tr_sessionLock(), tr_sessionUnlock() */
    2223#include "utils.h" /* TR_GNUC_PRINTF */
     
    176177    const char * currentDir;
    177178
     179    tr_recentHistory       * blocksSentToClient;
     180    tr_recentHistory       * blocksSentToPeer;
     181
     182    tr_recentHistory       * cancelsSentToClient;
     183    tr_recentHistory       * cancelsSentToPeer;
     184
    178185    /* How many bytes we ask for per request */
    179186    uint32_t                   blockSize;
     
    344351enum
    345352{
     353    TORRENT_DOWNLOAD_CONGESTION_HISTORY_SEC = 120,
     354
    346355    TORRENT_MAGIC_NUMBER = 95549
    347356};
  • trunk/libtransmission/transmission.h

    r10308 r10332  
    13551355    float    rateToClient;
    13561356
     1357
     1358/***
     1359****  THESE NEXT FOUR FIELDS ARE EXPERIMENTAL.
     1360****  They're currently being used in the GTK+ client to help tune the new download congestion code
     1361****  and probably won't make the cut for 2.0.
     1362***/
     1363    /* how many blocks we've sent to this peer in the last 120 seconds */
     1364    uint32_t  blocksToPeer;
     1365    /* how many blocks this client's sent to us in the last 120 seconds */
     1366    uint32_t  blocksToClient;
     1367    /* how many requests to this peer that we've cancelled in the last 120 seconds */
     1368    uint32_t  cancelsToPeer;
     1369    /* how many requests this peer made of us, then cancelled, in the last 120 seconds */
     1370    uint32_t  cancelsToClient;
     1371
    13571372    /* how many requests the peer has made that we haven't responded to yet */
    13581373    int      pendingReqsToClient;
Note: See TracChangeset for help on using the changeset viewer.