Changeset 5287


Ignore:
Timestamp:
Mar 18, 2008, 5:46:29 PM (15 years ago)
Author:
charles
Message:

#781: (1) fix overreporting corrupt data, and (2) fix bug added in r5172 that didn't handle sent request TTL correctly, causing too many dupliate block requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r5285 r5287  
    7979    MAX_FAST_ALLOWED_THRESHOLD = 10,
    8080
     81    /* how long an unsent request can stay queued before it's returned
     82       back to the peer-mgr's pool of requests */
    8183    QUEUED_REQUEST_TTL_SECS = 20,
    8284
    83     SENT_REQUEST_TTL_SECS = 90
     85    /* how long a sent request can stay queued before it's returned
     86       back to the peer-mgr's pool of requests */
     87    SENT_REQUEST_TTL_SECS = 120
    8488};
    8589
     
    145149
    146150static void
     151reqListCopy( struct request_list * dest, const struct request_list * src )
     152{
     153    dest->count = src->count;
     154    dest->max = src->max;
     155    dest->requests = tr_new( struct peer_request, dest->max );
     156    memcpy( dest->requests, src->requests, sizeof( struct peer_request ) * dest->count );
     157}
     158
     159static void
    147160reqListRemoveOne( struct request_list * list, int i )
    148161{
     
    203216
    204217    return err;
    205 }
    206 
    207 static void
    208 reqListPrune( struct request_list * list,
    209               struct request_list * pruned,
    210               time_t                cutoff )
    211 {
    212     int i, k=0, p=0;
    213     struct peer_request keep[MAX_QUEUE_SIZE];
    214     struct peer_request prune[MAX_QUEUE_SIZE];
    215 
    216     for( i=0; i<list->count; ++i ) {
    217         const struct peer_request * req = list->requests + i;
    218         if( req->time_requested > cutoff )
    219             keep[k++] = *req;
    220         else
    221             prune[p++] = *req;
    222     }
    223 
    224     memcpy( list->requests, keep, sizeof(struct peer_request) * k );
    225     list->count = k;
    226 
    227     reqListReserve( pruned, pruned->count + p );
    228     memcpy( pruned->requests + pruned->count,
    229             prune,
    230             sizeof(struct peer_request) * p );
    231     pruned->count += p;
    232218}
    233219
     
    686672{
    687673    int i;
    688     const time_t now = time( NULL );
    689     const time_t queued_cutoff = now - QUEUED_REQUEST_TTL_SECS;
    690     const time_t sent_cutoff   = now - SENT_REQUEST_TTL_SECS;
    691     struct request_list pruned = REQUEST_LIST_INIT;
    692 
    693     reqListPrune( &msgs->clientWillAskFor, &pruned, queued_cutoff );
    694     reqListPrune( &msgs->clientAskedFor, &pruned, sent_cutoff );
    695 
    696     /* expire the old requests */
    697     for( i=0; i<pruned.count; ++i ) {
    698         const struct peer_request * req = &pruned.requests[i];
    699         tr_peerMsgsCancel( msgs, req->index, req->offset, req->length );
    700     }
    701 
    702     /* cleanup */
    703     reqListClear( &pruned );
     674    time_t oldestAllowed;
     675    struct request_list tmp = REQUEST_LIST_INIT;
     676
     677    /* cancel requests that have been queued for too long */
     678    oldestAllowed = time( NULL ) - QUEUED_REQUEST_TTL_SECS;
     679    reqListCopy( &tmp, &msgs->clientWillAskFor );
     680    for( i=0; i<tmp.count; ++i ) {
     681        const struct peer_request * req = &tmp.requests[i];
     682        if( req->time_requested < oldestAllowed )
     683            tr_peerMsgsCancel( msgs, req->index, req->offset, req->length );
     684    }
     685    reqListClear( &tmp );
     686
     687    /* cancel requests that were sent too long ago */
     688    oldestAllowed = time( NULL ) - SENT_REQUEST_TTL_SECS;
     689    reqListCopy( &tmp, &msgs->clientAskedFor );
     690    for( i=0; i<tmp.count; ++i ) {
     691        const struct peer_request * req = &tmp.requests[i];
     692        if( req->time_requested < oldestAllowed )
     693            tr_peerMsgsCancel( msgs, req->index, req->offset, req->length );
     694    }
     695    reqListClear( &tmp );
    704696}
    705697
     
    14321424
    14331425static void
     1426decrementDownloadedCount( tr_peermsgs * msgs, uint32_t byteCount )
     1427{
     1428    tr_torrent * tor = msgs->torrent;
     1429    tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
     1430}
     1431
     1432static void
    14341433reassignBytesToCorrupt( tr_peermsgs * msgs, uint32_t byteCount )
    14351434{
    14361435    tr_torrent * tor = msgs->torrent;
    14371436
    1438     /* increment the `corrupt' field */
    14391437    tor->corruptCur += byteCount;
    14401438
    1441     /* decrement the `downloaded' field */
    1442     tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
    1443 }
    1444 
     1439    decrementDownloadedCount( msgs, byteCount );
     1440}
    14451441
    14461442static void
     
    14551451clientGotUnwantedBlock( tr_peermsgs * msgs, const struct peer_request * req )
    14561452{
    1457     reassignBytesToCorrupt( msgs, req->length );
     1453    decrementDownloadedCount( msgs, req->length );
    14581454}
    14591455
Note: See TracChangeset for help on using the changeset viewer.