(trunk libT) #2548 "T's request queue can send out too many duplicate requests" -- fix off-by-one when counting how many peers we'll send a given block request to during endgame

This commit is contained in:
Charles Kerr 2009-12-15 21:33:24 +00:00
parent 22e33f784b
commit f3e8a29e0f
1 changed files with 9 additions and 1 deletions

View File

@ -657,6 +657,9 @@ requestListAdd( Torrent * t, const time_t now, tr_block_index_t block, tr_peer *
break; break;
} }
} }
/*fprintf( stderr, "added request of block %lu from peer %p... "
"there are now %d block\n",
(unsigned long)block, peer, t->requestCount );*/
} }
static struct block_request * static struct block_request *
@ -673,6 +676,7 @@ requestListLookup( Torrent * t, tr_block_index_t block, const tr_peer * peer )
compareReqByBlock ); compareReqByBlock );
} }
/* how many peers are we currently requesting this block from... */
static int static int
countBlockRequests( Torrent * t, tr_block_index_t block ) countBlockRequests( Torrent * t, tr_block_index_t block )
{ {
@ -711,6 +715,9 @@ requestListRemove( Torrent * t, tr_block_index_t block, const tr_peer * peer )
memmove( t->requests + pos, memmove( t->requests + pos,
t->requests + pos + 1, t->requests + pos + 1,
sizeof( struct block_request ) * ( --t->requestCount - pos ) ); sizeof( struct block_request ) * ( --t->requestCount - pos ) );
/*fprintf( stderr, "removing request of block %lu from peer %p... "
"there are now %d block requests left\n",
(unsigned long)block, peer, t->requestCount );*/
} }
} }
@ -806,6 +813,7 @@ pieceListSort( Torrent * t, int mode )
} }
t->isInEndgame = endgame; t->isInEndgame = endgame;
/*if( t->isInEndgame ) fprintf( stderr, "ENDGAME reached\n" );*/
} }
} }
@ -985,7 +993,7 @@ tr_peerMgrGetNextRequests( tr_torrent * tor,
continue; continue;
/* don't send the same request to any peer too many times */ /* don't send the same request to any peer too many times */
if( countBlockRequests( t, b ) > maxDuplicatesPerBlock ) if( countBlockRequests( t, b ) >= maxDuplicatesPerBlock )
continue; continue;
/* update the caller's table */ /* update the caller's table */