corrected bug in CRC32 map cross-checking: only downloaded chunks would be checked.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4660 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-11-03 23:12:54 +00:00
parent e202a01862
commit a9cb864717

View File

@ -133,7 +133,7 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
if (offset + chunk_size > mSize) if (offset + chunk_size > mSize)
{ {
chunk_size = mSize - offset; chunk_size = mSize - offset;
std::cerr <<"Chunk Size greater than total file size, adjusting chunk " << "size " << chunk_size << std::endl; std::cerr <<"Chunk Size greater than total file size, adjusting chunk size " << chunk_size << std::endl;
} }
@ -608,7 +608,9 @@ bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
CompressedChunkMap map ; CompressedChunkMap map ;
chunkMap.getAvailabilityMap(map) ;
// Start with a full map.
ChunkMap::buildPlainMap(mSize,map) ;
uint32_t nb_chunks = ref.size() ; uint32_t nb_chunks = ref.size() ;
static const uint32_t chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ; static const uint32_t chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
@ -625,8 +627,7 @@ bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,
for(uint32_t i=0;i<nb_chunks;++i) for(uint32_t i=0;i<nb_chunks;++i)
{ {
printf(" Chunk %05d/%05d:",i,nb_chunks) ; printf(" Chunk %05d/%05d:",i,nb_chunks) ;
if(map[i])
{
if(fseeko64(fd,(uint64_t)i * (uint64_t)chunk_size,SEEK_SET)==0 && (len = fread(buff,1,chunk_size,fd)) > 0) if(fseeko64(fd,(uint64_t)i * (uint64_t)chunk_size,SEEK_SET)==0 && (len = fread(buff,1,chunk_size,fd)) > 0)
{ {
uint32_t crc = RsDirUtil::rs_CRC32(buff,len) ; uint32_t crc = RsDirUtil::rs_CRC32(buff,len) ;
@ -637,7 +638,6 @@ bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,
{ {
printf(" CRC ERROR!!\n") ; printf(" CRC ERROR!!\n") ;
++bad_chunks ; ++bad_chunks ;
++incomplete_chunks ;
map.reset(i) ; map.reset(i) ;
} }
else else
@ -647,16 +647,9 @@ bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,
{ {
printf(" cannot fseek!\n") ; printf(" cannot fseek!\n") ;
++bad_chunks ; ++bad_chunks ;
++incomplete_chunks ;
map.reset(i) ; map.reset(i) ;
} }
} }
else
{
printf(" incomplete.\n") ;
++incomplete_chunks ;
}
}
delete[] buff ; delete[] buff ;