Changeset 5287
- Timestamp:
- Mar 18, 2008, 5:46:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r5285 r5287 79 79 MAX_FAST_ALLOWED_THRESHOLD = 10, 80 80 81 /* how long an unsent request can stay queued before it's returned 82 back to the peer-mgr's pool of requests */ 81 83 QUEUED_REQUEST_TTL_SECS = 20, 82 84 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 84 88 }; 85 89 … … 145 149 146 150 static void 151 reqListCopy( 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 159 static void 147 160 reqListRemoveOne( struct request_list * list, int i ) 148 161 { … … 203 216 204 217 return err; 205 }206 207 static void208 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 else221 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;232 218 } 233 219 … … 686 672 { 687 673 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 ); 704 696 } 705 697 … … 1432 1424 1433 1425 static void 1426 decrementDownloadedCount( tr_peermsgs * msgs, uint32_t byteCount ) 1427 { 1428 tr_torrent * tor = msgs->torrent; 1429 tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); 1430 } 1431 1432 static void 1434 1433 reassignBytesToCorrupt( tr_peermsgs * msgs, uint32_t byteCount ) 1435 1434 { 1436 1435 tr_torrent * tor = msgs->torrent; 1437 1436 1438 /* increment the `corrupt' field */1439 1437 tor->corruptCur += byteCount; 1440 1438 1441 /* decrement the `downloaded' field */ 1442 tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); 1443 } 1444 1439 decrementDownloadedCount( msgs, byteCount ); 1440 } 1445 1441 1446 1442 static void … … 1455 1451 clientGotUnwantedBlock( tr_peermsgs * msgs, const struct peer_request * req ) 1456 1452 { 1457 reassignBytesToCorrupt( msgs, req->length );1453 decrementDownloadedCount( msgs, req->length ); 1458 1454 } 1459 1455
Note: See TracChangeset
for help on using the changeset viewer.