mirror of
https://github.com/transmission/transmission
synced 2025-03-12 23:23:54 +00:00
#781: experimental commit on the "failed data" issue.
This commit is contained in:
parent
b6f2796e40
commit
e3c1d221fb
2 changed files with 29 additions and 22 deletions
|
@ -12,17 +12,18 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdlib.h> /* realloc */
|
||||||
#include <string.h> /* memcmp */
|
#include <string.h> /* memcmp */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <openssl/sha.h>
|
|
||||||
|
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
|
#include "crypto.h"
|
||||||
#include "fdlimit.h"
|
#include "fdlimit.h"
|
||||||
#include "inout.h"
|
#include "inout.h"
|
||||||
|
#include "platform.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "torrent.h"
|
#include "torrent.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -220,33 +221,38 @@ tr_ioRecalculateHash( const tr_torrent * tor,
|
||||||
int pieceIndex,
|
int pieceIndex,
|
||||||
uint8_t * setme )
|
uint8_t * setme )
|
||||||
{
|
{
|
||||||
int offset;
|
static uint8_t * buf = NULL;
|
||||||
int bytesLeft;
|
static int buflen = 0;
|
||||||
uint8_t buf[4096];
|
static tr_lock * lock = NULL;
|
||||||
|
|
||||||
|
int n;
|
||||||
|
tr_errno err;
|
||||||
const tr_info * info;
|
const tr_info * info;
|
||||||
SHA_CTX sha;
|
|
||||||
|
/* only check one block at a time to prevent disk thrashing.
|
||||||
|
* this also lets us reuse the same buffer each time. */
|
||||||
|
if( lock == NULL )
|
||||||
|
lock = tr_lockNew( );
|
||||||
|
|
||||||
|
tr_lockLock( lock );
|
||||||
|
|
||||||
assert( tor != NULL );
|
assert( tor != NULL );
|
||||||
assert( setme != NULL );
|
assert( setme != NULL );
|
||||||
assert( 0<=pieceIndex && pieceIndex<tor->info.pieceCount );
|
assert( 0<=pieceIndex && pieceIndex<tor->info.pieceCount );
|
||||||
|
|
||||||
info = &tor->info;
|
info = &tor->info;
|
||||||
offset = 0;
|
n = tr_torPieceCountBytes( tor, pieceIndex );
|
||||||
bytesLeft = tr_torPieceCountBytes( tor, pieceIndex );
|
|
||||||
SHA1_Init( &sha );
|
|
||||||
|
|
||||||
while( bytesLeft > 0 )
|
if( buflen < n ) {
|
||||||
{
|
buflen = n;
|
||||||
const int bytesThisPass = MIN( bytesLeft, (int)sizeof(buf) );
|
buf = tr_renew( uint8_t, buf, buflen );
|
||||||
tr_errno err = tr_ioRead( tor, pieceIndex, offset, bytesThisPass, buf );
|
|
||||||
if( err )
|
|
||||||
return err;
|
|
||||||
SHA1_Update( &sha, buf, bytesThisPass );
|
|
||||||
bytesLeft -= bytesThisPass;
|
|
||||||
offset += bytesThisPass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SHA1_Final( setme, &sha );
|
err = tr_ioRead( tor, pieceIndex, 0, n, buf );
|
||||||
|
if( !err )
|
||||||
|
tr_sha1( setme, buf, n, NULL );
|
||||||
|
|
||||||
|
tr_lockUnlock( lock );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "verify.h"
|
#include "verify.h"
|
||||||
|
|
||||||
|
#define MAX_BLOCK_SIZE (1024*16)
|
||||||
|
|
||||||
/***
|
/***
|
||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
|
@ -289,7 +291,7 @@ torrentRealInit( tr_handle * h,
|
||||||
* (2) pieceSize must be a multiple of block size
|
* (2) pieceSize must be a multiple of block size
|
||||||
*/
|
*/
|
||||||
tor->blockSize = info->pieceSize;
|
tor->blockSize = info->pieceSize;
|
||||||
while( tor->blockSize > (1024*16) )
|
while( tor->blockSize > MAX_BLOCK_SIZE )
|
||||||
tor->blockSize /= 2;
|
tor->blockSize /= 2;
|
||||||
|
|
||||||
tor->lastPieceSize = info->totalSize % info->pieceSize;
|
tor->lastPieceSize = info->totalSize % info->pieceSize;
|
||||||
|
@ -1295,14 +1297,13 @@ tr_torrentReqIsValid( const tr_torrent * tor,
|
||||||
uint32_t offset,
|
uint32_t offset,
|
||||||
uint32_t length )
|
uint32_t length )
|
||||||
{
|
{
|
||||||
static const uint32_t MAX_REQUEST_BYTE_COUNT = (16 * 1024);
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if( index >= (uint32_t) tor->info.pieceCount )
|
if( index >= (uint32_t) tor->info.pieceCount )
|
||||||
err = 1;
|
err = 1;
|
||||||
else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
|
else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
|
||||||
err = 2;
|
err = 2;
|
||||||
else if( length > MAX_REQUEST_BYTE_COUNT )
|
else if( length > MAX_BLOCK_SIZE )
|
||||||
err = 3;
|
err = 3;
|
||||||
else if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
|
else if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
|
||||||
err = 4;
|
err = 4;
|
||||||
|
|
Loading…
Add table
Reference in a new issue