- corrected 1 bug in serialisation of CRC32Maps for peer transfer

- corrected 1 bug (missing hashing thread deletion on failure)


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3321 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-07-30 21:01:51 +00:00
parent 38be555332
commit 1069ed0c58
3 changed files with 30 additions and 18 deletions

View File

@ -499,20 +499,38 @@ bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,
uint32_t len = 0 ;
for(uint32_t i=0;i<nb_chunks;++i)
{
printf(" Chunk %05d/%05d:",i,nb_chunks) ;
if(map[i])
{
if(fseek(fd,(uint64_t)i * (uint64_t)chunk_size,SEEK_SET)==0 && (len = fread(buff,1,chunk_size,fd)) > 0)
{
if( RsDirUtil::rs_CRC32(buff,len) != ref[i])
uint32_t crc = RsDirUtil::rs_CRC32(buff,len) ;
printf(" crc: %08x, ref: %08x : ",crc,ref[i]) ;
if(crc != ref[i])
{
printf(" CRC ERROR!!\n") ;
++bad_chunks ;
++incomplete_chunks ;
map.reset(i) ;
}
else
printf(" matched\n") ;
}
else
{
printf(" cannot fseek!\n") ;
return false ;
}
}
else
{
printf(" incomplete.\n") ;
++incomplete_chunks ;
}
}
delete[] buff ;

View File

@ -522,9 +522,8 @@ class HashThread: public RsThread
virtual void run()
{
_m->hashReceivedData(_hash) ;
RsStackMutex stack(_hashThreadMtx) ;
_m->hashReceivedData(_hash) ;
_finished = true ;
}
std::string hash()
@ -586,15 +585,10 @@ bool ftTransferModule::checkFile()
}
delete _hash_thread ;
_hash_thread = NULL ;
}
forceCheck() ;
return true ;
cancelFileTransferUpward() ;
std::cerr << "(EE) ftTransferModule::checkFile(): File verification failed for hash " << mHash << "! Asking for CRC map. mFlag=4. For now: cancelling file transfer." << std::endl ;
//askForCRCMap() ;
return false ;
}
@ -604,7 +598,7 @@ void ftTransferModule::forceCheck()
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::forceCheck(): setting flags to force check." << std::endl ;
#endif
mFlag = FT_TM_FLAG_CHUNK_CRC ; // Ask for CRC map. But for now, cancel file transfer.
mFlag = FT_TM_FLAG_CHUNK_CRC ; // Ask for CRC map.
// setup flags for CRC state machine to work properly
_crcmap_state = FT_TM_CRC_MAP_STATE_DONT_HAVE ;
@ -718,13 +712,13 @@ bool ftTransferModule::checkCRC()
if(bad_chunks > 0)
{
mFlag = FT_TM_FLAG_DOWNLOADING ;
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::checkCRC(): Done. " << bad_chunks << " bad chunks found. Restarting download for these chunks only." << std::endl ;
#endif
mFileStatus.stat = ftFileStatus::PQIFILE_DOWNLOADING;
std::cerr << "ftTransferModule::checkCRC(): Done. File has errors: " << bad_chunks << " bad chunks found. Restarting download for these chunks only." << std::endl ;
}
else if(incomplete_chunks > 0)
{
mFlag = FT_TM_FLAG_DOWNLOADING ;
mFileStatus.stat = ftFileStatus::PQIFILE_DOWNLOADING;
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::checkCRC(): Done. all chunks ok. Continuing download for remaining chunks." << std::endl ;
#endif

View File

@ -527,16 +527,16 @@ bool RsFileItemSerialiser::serialiseCRC32Map(RsFileCRC32Map *item, void *dat
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->hash);
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._crcs.size());
for(uint32_t i=0;i<item->crc_map._crcs.size();++i)
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._crcs[i]);
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._ccmap._map.size());
for(uint32_t i=0;i<item->crc_map._ccmap._map.size();++i)
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._ccmap._map[i]);
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._crcs.size());
for(uint32_t i=0;i<item->crc_map._crcs.size();++i)
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._crcs[i]);
if (offset != tlvsize)
{
ok = false;