Changeset 2306


Ignore:
Timestamp:
Jul 9, 2007, 4:37:16 AM (14 years ago)
Author:
charles
Message:

remove the "peer is asking for too many blocks!" warning reported by Gimp_ by changing from a fixed-size array to a linked lists of incoming requests

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer.c

    r2303 r2306  
    2525#include "transmission.h"
    2626#include "peertree.h"
     27#include "list.h"
    2728
    2829/*****
     
    190191    uint64_t            inTotal;
    191192
    192     int                 outRequestCount;
    193     int                 outRequestMax;
    194     int                 outRequestAlloc;
    195     tr_request_t      * outRequests;
     193    tr_list_t         * outRequests;
    196194    uint64_t            outTotal;
    197195    uint64_t            outDate;
     
    248246    peer->upload      = tr_rcInit();
    249247
    250     peer->outRequestMax = peer->outRequestAlloc = 2;
    251     peer->outRequests = tr_new0( tr_request_t, peer->outRequestAlloc );
    252 
    253248    peer->inRequestMax = peer->inRequestAlloc = 2;
    254249    peer->inRequests = tr_new0( tr_request_t, peer->inRequestAlloc );
     
    289284    tr_bitfieldFree( peer->banfield );
    290285    tr_bitfieldFree( peer->reqfield );
     286    tr_list_foreach( peer->outRequests, tr_free );
     287    tr_list_free( peer->outRequests );
    291288    tr_free( peer->inRequests );
    292     tr_free( peer->outRequests );
    293289    tr_free( peer->buf );
    294290    tr_free( peer->outMessages );
     
    871867    {
    872868        double outboundSpeedKiBs;
    873         double inboundSpeedKiBs;
    874869        int size;
    875870        tr_peer_t * peer = tor->peers[ i ];
     
    888883            peer->inRequestAlloc = peer->inRequestMax;
    889884            peer->inRequests = tr_renew( tr_request_t, peer->inRequests, peer->inRequestAlloc );
    890         }
    891 
    892         /* decide how many blocks we'll concurrently let the peer ask us for */
    893         inboundSpeedKiBs = tr_rcRate(peer->download);
    894         size = queueTimeSec * inboundSpeedKiBs / blockSizeKiB;
    895         if( size < 4 ) /* don't let it get TOO small */
    896             size = 4;
    897         size += 4; /* and always leave room to grow */
    898         peer->outRequestMax = size;
    899         if( peer->outRequestAlloc < peer->outRequestMax ) {
    900             peer->outRequestAlloc = peer->outRequestMax;
    901             peer->outRequests = tr_renew( tr_request_t, peer->outRequests, peer->outRequestAlloc );
    902885        }
    903886    }
  • trunk/libtransmission/peermessages.h

    r2149 r2306  
    105105}
    106106
    107 static uint8_t * blockPending( tr_torrent_t * tor, tr_peer_t * peer,
    108                                int * size )
    109 {
    110     if( !peer->outBlockLoaded )
     107static uint8_t *
     108blockPending( tr_torrent_t  * tor,
     109              tr_peer_t     * peer,
     110              int           * size )
     111{
     112    if( !peer->outBlockLoaded ) /* we need to load the block for the next request */
    111113    {
    112114        uint8_t      * buf;
     
    114116        int            hdrlen;
    115117
    116         if( peer->amChoking || peer->outRequestCount < 1 )
     118        if( peer->amChoking )
     119            return NULL;
     120
     121        if( !peer->outRequests ) /* nothing to send */
     122            return NULL;
     123
     124        r = (tr_request_t*) peer->outRequests->data;
     125        assert( r != NULL );
     126        peer->outRequests = tr_list_remove( peer->outRequests, r );
     127
     128        if( !tr_cpPieceIsComplete( tor->completion, r->index ) ) /* sanity clause */
    117129        {
    118             /* No piece to send */
    119             return NULL;
    120         }
    121 
    122         /* We need to load the block for the next request */
    123         r = &peer->outRequests[0];
    124 
    125         /* Sanity check */
    126         if( !tr_cpPieceIsComplete( tor->completion, r->index ) )
    127         {
    128             /* We have been asked for something we don't have, buggy client?
    129                Let's just drop this request */
     130            /* We've been asked for something we don't have.  buggy client? */
    130131            tr_inf( "Block %d/%d/%d was requested but we don't have it",
    131132                    r->index, r->begin, r->length );
    132             (peer->outRequestCount)--;
    133             memmove( &peer->outRequests[0], &peer->outRequests[1],
    134                      peer->outRequestCount * sizeof( tr_request_t ) );
     133            tr_free( r );
    135134            return NULL;
    136135        }
     
    147146        tr_ioRead( tor->io, r->index, r->begin, r->length, buf );
    148147
    149         if( peer->outRequestCount < 1 )
    150         {
    151             /* We were choked during the read */
    152             return NULL;
    153         }
    154 
    155148        peer_dbg( "SEND piece %d/%d (%d bytes)",
    156149                  r->index, r->begin, r->length );
    157 
    158150        peer->outBlockSize   = hdrlen;
    159151        peer->outBlockLoaded = 1;
    160152
    161         (peer->outRequestCount)--;
    162         memmove( &peer->outRequests[0], &peer->outRequests[1],
    163                  peer->outRequestCount * sizeof( tr_request_t ) );
     153        tr_free( r );
    164154    }
    165155
     
    235225    if( !yes )
    236226    {
    237         /* Drop older requests from the last time it was unchoked,
    238            if any */
    239         peer->outRequestCount = 0;
     227        /* Drop older requests from the last time it was unchoked, if any */
     228        tr_list_foreach( peer->outRequests, tr_free );
     229        tr_list_free( peer->outRequests );
     230        peer->outRequests = NULL;
    240231    }
    241232
  • trunk/libtransmission/peerparse.h

    r2257 r2306  
    238238    }
    239239
    240     if( peer->outRequestCount >= peer->outRequestMax )
    241     {
    242         tr_dbg( "Peer is asking for too many blocks!");
    243         return TR_ERROR;
    244     }
    245 
    246     r         = &peer->outRequests[peer->outRequestCount];
    247     r->index  = index;
    248     r->begin  = begin;
     240    r = tr_new0( tr_request_t, 1 );
     241    r->index = index;
     242    r->begin = begin;
    249243    r->length = length;
    250 
    251     (peer->outRequestCount)++;
     244    peer->outRequests = tr_list_append( peer->outRequests, r );
    252245
    253246    return TR_OK;
     
    379372}
    380373
     374static int reqCompare( const void * va, const void * vb )
     375{
     376    const tr_request_t * a = (const tr_request_t *) va;
     377    const tr_request_t * b = (const tr_request_t *) vb;
     378    if( a->index != b->index ) return a->index - b->index;
     379    if( a->begin != b->begin ) return a->begin - b->begin;
     380    return a->length - b->length;
     381}
     382
    381383static inline int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
    382384                               uint8_t * p, int len )
     
    384386    tr_info_t * inf = &tor->info;
    385387    int index, begin, length;
    386     int i;
    387     tr_request_t * r;
     388    tr_request_t req;
     389    tr_list_t * l;
    388390
    389391    if( len != 12 )
     
    411413              index, begin, length );
    412414
    413     for( i = 0; i < peer->outRequestCount; i++ )
    414     {
    415         r = &peer->outRequests[i];
    416         if( r->index == index && r->begin == begin &&
    417             r->length == length )
    418         {
    419             (peer->outRequestCount)--;
    420             memmove( &r[0], &r[1], sizeof( tr_request_t ) *
    421                     ( peer->outRequestCount - i ) );
    422             break;
    423         }
     415    /* remove it from the outRequests list */
     416    req.index = index;
     417    req.begin = begin;
     418    req.length = length;
     419    while(( l = tr_list_find( peer->outRequests, reqCompare, &req ) )) {
     420        tr_free( l->data );
     421        peer->outRequests = tr_list_remove( peer->outRequests, l );
    424422    }
    425423
  • trunk/libtransmission/peerutils.h

    r2297 r2306  
    2222 * DEALINGS IN THE SOFTWARE.
    2323 *****************************************************************************/
    24 
    25 static void updateInterest( tr_torrent_t * tor, tr_peer_t * peer );
    26 
    2724
    2825static int peerCmp( tr_peer_t * peer1, tr_peer_t * peer2 )
  • trunk/libtransmission/ratecontrol.c

    r2303 r2306  
    2828#define GRANULARITY_MSEC 200
    2929#define SHORT_INTERVAL_MSEC 1000
    30 #define LONG_INTERVAL_MSEC 10000
     30#define LONG_INTERVAL_MSEC 20000
    3131#define HISTORY_SIZE (LONG_INTERVAL_MSEC / GRANULARITY_MSEC)
    3232
     
    5353    const uint64_t now = tr_date ();
    5454    int i = r->newest;
    55     int real_interval_msec = 0;
    5655    for( ;; )
    5756    {
     
    6059
    6160        bytes += r->transfers[i].size;
    62         real_interval_msec = now - r->transfers[i].date;
    6361
    6462        if( --i == -1 ) i = HISTORY_SIZE - 1; /* circular history */
     
    6664    }
    6765
    68     return !bytes || !real_interval_msec
    69         ? 0.0
    70         : (bytes/1024.0) * (1000.0/real_interval_msec);
     66    return (bytes/1024.0) * (1000.0/interval_msec);
    7167}
    7268
  • trunk/mk/lib.mk

    r2265 r2306  
    55
    66SRCS = bencode.c choking.c clients.c completion.c fastresume.c fdlimit.c \
    7        http.c inout.c ipcparse.c makemeta.c metainfo.c natpmp.c net.c \
    8        peer.c platform.c ratecontrol.c sha1.c shared.c strlcat.c \
     7       http.c inout.c ipcparse.c list.c makemeta.c metainfo.c natpmp.c \
     8       net.c peer.c platform.c ratecontrol.c sha1.c shared.c strlcat.c \
    99       strlcpy.c torrent.c tracker.c transmission.c upnp.c utils.c xml.c
    1010
Note: See TracChangeset for help on using the changeset viewer.