#751: more digging to try to figure out where the problem is.

This commit is contained in:
Charles Kerr 2008-03-06 13:24:44 +00:00
parent 26561fc31f
commit 5e3dcb5f6f
4 changed files with 44 additions and 30 deletions

View File

@ -810,6 +810,7 @@ refillPulse( void * vtorrent )
const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize);
const uint32_t length = tr_torBlockCountBytes( tor, (int)block );
assert( tr_torrentReqIsValid( tor, index, begin, length ) );
assert( _tr_block( tor, index, begin ) == (int)block );
assert( begin < (uint32_t)tr_torPieceCountBytes( tor, (int)index ) );
assert( (begin + length) <= (uint32_t)tr_torPieceCountBytes( tor, (int)index ) );

View File

@ -60,9 +60,6 @@ enum
TR_LTEP_PEX = 1,
/* drop requests who want too much */
MAX_REQUEST_BYTE_COUNT = (16 * 1024),
MIN_CHOKE_PERIOD_SEC = (10),
/* idle seconds before we send a keepalive */
@ -675,31 +672,7 @@ reqIsValid( const tr_peermsgs * msgs,
uint32_t offset,
uint32_t length )
{
const tr_torrent * tor = msgs->torrent;
int err = 0;
if( index >= (uint32_t) tor->info.pieceCount )
err = 1;
else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
err = 2;
else if( length > MAX_REQUEST_BYTE_COUNT )
err = 3;
else if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
err = 4;
if( err )
{
fprintf( stderr, "(ticket #751) err is %d\n", err );
fprintf( stderr, "(ticket #751) req.index is %"PRIu32"\n", index );
fprintf( stderr, "(ticket #751) req.offset is %"PRIu32"\n", offset );
fprintf( stderr, "(ticket #751) req.length is %"PRIu32"\n", length );
fprintf( stderr, "(ticket #751) tor->info.totalSize is %"PRIu64"\n", tor->info.totalSize );
fprintf( stderr, "(ticket #751) tor->info.pieceCount is %d\n", tor->info.pieceCount );
fprintf( stderr, "(ticket #751) tr_torPieceCountBytes is %d\n", tr_torPieceCountBytes( tor, (int)index ) );
fprintf( stderr, "(ticket #751) tr_pieceOffset is %"PRIu64"\n", tr_pieceOffset( tor, index, offset, length ) );
}
return !err;
return tr_torrentReqIsValid( msgs->torrent, index, offset, length );
}
static int

View File

@ -1281,13 +1281,48 @@ tr_torrentGetMaxConnectedPeers( const tr_torrent * tor )
****
***/
int _tr_block( const tr_torrent * tor, int index, int begin )
int
_tr_block( const tr_torrent * tor, int index, int begin )
{
const tr_info * inf = &tor->info;
return index * ( inf->pieceSize / tor->blockSize ) +
begin / tor->blockSize;
}
int
tr_torrentReqIsValid( const tr_torrent * tor,
uint32_t index,
uint32_t offset,
uint32_t length )
{
static const uint32_t MAX_REQUEST_BYTE_COUNT = (16 * 1024);
int err = 0;
if( index >= (uint32_t) tor->info.pieceCount )
err = 1;
else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
err = 2;
else if( length > MAX_REQUEST_BYTE_COUNT )
err = 3;
else if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
err = 4;
if( err )
{
fprintf( stderr, "(ticket #751) err is %d\n", err );
fprintf( stderr, "(ticket #751) req.index is %"PRIu32"\n", index );
fprintf( stderr, "(ticket #751) req.offset is %"PRIu32"\n", offset );
fprintf( stderr, "(ticket #751) req.length is %"PRIu32"\n", length );
fprintf( stderr, "(ticket #751) tor->info.totalSize is %"PRIu64"\n", tor->info.totalSize );
fprintf( stderr, "(ticket #751) tor->info.pieceCount is %d\n", tor->info.pieceCount );
fprintf( stderr, "(ticket #751) tr_torPieceCountBytes is %d\n", tr_torPieceCountBytes( tor, (int)index ) );
fprintf( stderr, "(ticket #751) tr_pieceOffset is %"PRIu64"\n", tr_pieceOffset( tor, index, offset, length ) );
}
return !err;
}
uint64_t
tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length )
{

View File

@ -1,5 +1,5 @@
/******************************************************************************
* $Id:$
* $Id$
*
* Copyright (c) 2005-2008 Transmission authors and contributors
*
@ -75,6 +75,11 @@ int tr_torrentAllowsPex( const tr_torrent * );
#define tr_block(a,b) _tr_block(tor,a,b)
int _tr_block( const tr_torrent * tor, int index, int begin );
int tr_torrentReqIsValid( const tr_torrent * tor,
uint32_t index,
uint32_t offset,
uint32_t length );
uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length );
void tr_torrentInitFilePriority( tr_torrent * tor,