mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
simplified the code in the post download CRC check routine and removed a potential bug.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3574 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
750c1a9403
commit
47b48769e4
@ -60,10 +60,9 @@ const int32_t FT_TM_FAST_RTT = 1.0;
|
|||||||
const int32_t FT_TM_STD_RTT = 5.0;
|
const int32_t FT_TM_STD_RTT = 5.0;
|
||||||
const int32_t FT_TM_SLOW_RTT = 9.0;
|
const int32_t FT_TM_SLOW_RTT = 9.0;
|
||||||
|
|
||||||
const uint32_t FT_TM_CRC_MAP_STATE_DONT_HAVE = 0 ;
|
const uint32_t FT_TM_CRC_MAP_STATE_NOCHECK = 0 ;
|
||||||
const uint32_t FT_TM_CRC_MAP_STATE_NOCHECK = 1 ;
|
const uint32_t FT_TM_CRC_MAP_STATE_DONT_HAVE = 1 ;
|
||||||
const uint32_t FT_TM_CRC_MAP_STATE_ASKED = 2 ;
|
const uint32_t FT_TM_CRC_MAP_STATE_HAVE = 2 ;
|
||||||
const uint32_t FT_TM_CRC_MAP_STATE_HAVE = 3 ;
|
|
||||||
|
|
||||||
#define FT_TM_FLAG_DOWNLOADING 0
|
#define FT_TM_FLAG_DOWNLOADING 0
|
||||||
#define FT_TM_FLAG_CANCELED 1
|
#define FT_TM_FLAG_CANCELED 1
|
||||||
@ -87,7 +86,8 @@ ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftCon
|
|||||||
//mChunkSize = 10000;
|
//mChunkSize = 10000;
|
||||||
desiredRate = 1000000; /* 1MB/s ??? */
|
desiredRate = 1000000; /* 1MB/s ??? */
|
||||||
actualRate = 0;
|
actualRate = 0;
|
||||||
return;
|
_crcmap_state = FT_TM_CRC_MAP_STATE_NOCHECK ;
|
||||||
|
_crcmap_last_asked_time = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
ftTransferModule::~ftTransferModule()
|
ftTransferModule::~ftTransferModule()
|
||||||
@ -573,20 +573,19 @@ bool ftTransferModule::checkFile()
|
|||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_hash_thread->hash() == mHash)
|
std::string check_hash( _hash_thread->hash() ) ;
|
||||||
|
|
||||||
|
delete _hash_thread ;
|
||||||
|
_hash_thread = NULL ;
|
||||||
|
|
||||||
|
if(check_hash == mHash)
|
||||||
{
|
{
|
||||||
mFlag = FT_TM_FLAG_COMPLETE ; // Transfer is complete.
|
mFlag = FT_TM_FLAG_COMPLETE ; // Transfer is complete.
|
||||||
#ifdef FT_DEBUG
|
#ifdef FT_DEBUG
|
||||||
std::cerr << "ftTransferModule::checkFile(): hash finished. File verification complete ! Setting mFlag to 1" << std::endl ;
|
std::cerr << "ftTransferModule::checkFile(): hash finished. File verification complete ! Setting mFlag to 1" << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
delete _hash_thread ;
|
|
||||||
_hash_thread = NULL ;
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete _hash_thread ;
|
|
||||||
_hash_thread = NULL ;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
forceCheck() ;
|
forceCheck() ;
|
||||||
return false ;
|
return false ;
|
||||||
@ -603,7 +602,6 @@ void ftTransferModule::forceCheck()
|
|||||||
// setup flags for CRC state machine to work properly
|
// setup flags for CRC state machine to work properly
|
||||||
_crcmap_state = FT_TM_CRC_MAP_STATE_DONT_HAVE ;
|
_crcmap_state = FT_TM_CRC_MAP_STATE_DONT_HAVE ;
|
||||||
_crcmap_last_asked_time = 0 ;
|
_crcmap_last_asked_time = 0 ;
|
||||||
_crcmap_last_source_id = -1 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftTransferModule::checkCRC()
|
bool ftTransferModule::checkCRC()
|
||||||
@ -646,35 +644,38 @@ bool ftTransferModule::checkCRC()
|
|||||||
#endif
|
#endif
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case FT_TM_CRC_MAP_STATE_ASKED:
|
|
||||||
std::cerr << "FT_TM_CRC_MAP_STATE_ASKED: last time is " << _crcmap_last_asked_time << std::endl ;
|
|
||||||
std::cerr << "FT_TM_CRC_MAP_STATE_ASKED: now is " << now << std::endl ;
|
|
||||||
std::cerr << "Limit is " << (uint64_t)_crcmap_last_asked_time + (uint64_t)(FT_TM_CRC_MAP_MAX_WAIT_PER_GIG * (1+mSize/float(1024ull*1024ull*1024ull))) << std::endl ;
|
|
||||||
if( (uint64_t)_crcmap_last_asked_time + (uint64_t)(FT_TM_CRC_MAP_MAX_WAIT_PER_GIG * (1+mSize/float(1024ull*1024ull*1024ull))) > (uint64_t)now)
|
|
||||||
{
|
|
||||||
#ifdef FT_DEBUG
|
|
||||||
std::cerr << "ftTransferModule::checkCRC(): state is NOCHECK. Doing nothing." << std::endl ;
|
|
||||||
#endif
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
#ifdef FT_DEBUG
|
|
||||||
else
|
|
||||||
std::cerr << "ftTransferModule::checkCRC(): state is ASKED, but time is too long. Asking again." << std::endl ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case FT_TM_CRC_MAP_STATE_DONT_HAVE:
|
case FT_TM_CRC_MAP_STATE_DONT_HAVE:
|
||||||
{
|
{
|
||||||
|
// Check wether we have a CRC map or not.
|
||||||
|
//
|
||||||
|
std::cerr << "FT_TM_CRC_MAP_STATE_ASKED: last time is " << _crcmap_last_asked_time << std::endl ;
|
||||||
|
std::cerr << "FT_TM_CRC_MAP_STATE_ASKED: now is " << now << std::endl ;
|
||||||
|
|
||||||
|
uint64_t threshold = (uint64_t)(FT_TM_CRC_MAP_MAX_WAIT_PER_GIG * (1+mSize/float(1024ull*1024ull*1024ull))) ;
|
||||||
|
|
||||||
|
std::cerr << "Threshold is " << threshold << std::endl;
|
||||||
|
std::cerr << "Limit is " << (uint64_t)_crcmap_last_asked_time + threshold << std::endl ;
|
||||||
|
|
||||||
|
if( (uint64_t)_crcmap_last_asked_time + threshold > (uint64_t)now)
|
||||||
|
{
|
||||||
|
#ifdef FT_DEBUG
|
||||||
|
std::cerr << "ftTransferModule::checkCRC(): state is NOCHECK. Doing nothing." << std::endl ;
|
||||||
|
#endif
|
||||||
|
break ;
|
||||||
|
}
|
||||||
// Ask the ones we should ask for. We use a very coarse strategy now: we
|
// Ask the ones we should ask for. We use a very coarse strategy now: we
|
||||||
// send the request to a random source. We'll make this more sensible
|
// send the request to a random source. We'll make this more sensible
|
||||||
// later.
|
// later.
|
||||||
|
|
||||||
#ifdef FT_DEBUG
|
#ifdef FT_DEBUG
|
||||||
std::cerr << "ftTransferModule::checkCRC(): state is DONT_HAVE. Selecting a source for asking a CRC map." << std::endl ;
|
std::cerr << "ftTransferModule::checkCRC(): state is DONT_HAVE or last request is too old. Selecting a source for asking a CRC map." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
// if(_crcmap_last_source_id < 0)
|
if(mFileSources.empty())
|
||||||
// _crcmap_last_source_id=lrand48() ;
|
{
|
||||||
|
std::cerr << "ftTransferModule::checkCRC(): No sources available for checking file " << mHash << ": waiting 3 additional sec." <<std::endl ;
|
||||||
// _crcmap_last_source_id = (_crcmap_last_source_id+1)%mFileSources.size() ;
|
_crcmap_last_asked_time = now - threshold + 3 ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
int n = rand()%(mFileSources.size()) ;
|
int n = rand()%(mFileSources.size()) ;
|
||||||
int p=0 ;
|
int p=0 ;
|
||||||
@ -686,8 +687,6 @@ bool ftTransferModule::checkCRC()
|
|||||||
#endif
|
#endif
|
||||||
_crcmap_last_asked_time = now ;
|
_crcmap_last_asked_time = now ;
|
||||||
mMultiplexor->sendCRC32MapRequest(mit->first,mHash);
|
mMultiplexor->sendCRC32MapRequest(mit->first,mHash);
|
||||||
|
|
||||||
_crcmap_state = FT_TM_CRC_MAP_STATE_ASKED ;
|
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
|
@ -194,7 +194,6 @@ private:
|
|||||||
CRC32Map _crcmap ;
|
CRC32Map _crcmap ;
|
||||||
uint32_t _crcmap_state ;
|
uint32_t _crcmap_state ;
|
||||||
time_t _crcmap_last_asked_time ;
|
time_t _crcmap_last_asked_time ;
|
||||||
int _crcmap_last_source_id ;
|
|
||||||
|
|
||||||
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user