mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-25 01:01:40 -04:00
Improvements to file transfer:
- corrected 2 potential flaws of swarming causing request of unavailable data (This should normally be taken care of on the server side!) - improved swarming test code with fault simulation - only ask CRC32 maps to peers that have a complete file. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4947 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1fea734862
commit
2edb61758b
6 changed files with 85 additions and 41 deletions
|
@ -190,12 +190,12 @@ bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChun
|
|||
|
||||
if(it == _active_chunks_feed.end())
|
||||
{
|
||||
SourceChunksInfo *sci = getSourceChunksInfo(peer_id) ;
|
||||
|
||||
// 0 - Look into other pending chunks and slice from here.
|
||||
//
|
||||
for(std::map<std::string,Chunk>::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit)
|
||||
{
|
||||
SourceChunksInfo *sci = getSourceChunksInfo(pit->first) ;
|
||||
|
||||
if(sci->is_full || sci->cmap[pit->second._start / _chunk_size])
|
||||
{
|
||||
it = pit ;
|
||||
|
|
|
@ -84,6 +84,16 @@ class SourceChunksInfo
|
|||
CompressedChunkMap cmap ; //! map of what the peer has/doens't have
|
||||
time_t TS ; //! last update time for this info
|
||||
bool is_full ; //! is the map full ? In such a case, re-asking for it is unnecessary.
|
||||
|
||||
// Returns true if the offset is starting in a mapped chunk.
|
||||
//
|
||||
bool hasData(uint64_t offset,uint32_t fixed_chunk_size) const
|
||||
{
|
||||
if(is_full)
|
||||
return true ;
|
||||
|
||||
return cmap[offset / (uint64_t)fixed_chunk_size ] ;
|
||||
}
|
||||
};
|
||||
|
||||
class ChunkMap
|
||||
|
|
|
@ -447,17 +447,17 @@ bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hin
|
|||
// 0 - is there a faulting chunk that would need to be asked again ?
|
||||
|
||||
for(std::map<uint64_t,ftChunk>::iterator it(mChunks.begin());it!=mChunks.end();++it)
|
||||
if(it->second.ts + CHUNK_MAX_AGE < now)
|
||||
{
|
||||
offset = it->second.offset ;
|
||||
size = it->second.size ;
|
||||
it->second.ts = now ;
|
||||
if(it->second.ts + CHUNK_MAX_AGE < now && chunkMap.getSourceChunksInfo(peer_id)->hasData(it->second.offset,ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE))
|
||||
{
|
||||
offset = it->second.offset ;
|
||||
size = it->second.size ;
|
||||
it->second.ts = now ;
|
||||
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "ftFileCreator::getMissingChunk(): re-askign for chunk that wasn't received: " << offset << " + " << size << std::endl;
|
||||
std::cerr << "ftFileCreator::getMissingChunk(): re-asking for chunk that wasn't received: " << offset << " + " << size << std::endl;
|
||||
#endif
|
||||
return true ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
// 1 - is there an ongoing 1MB chunk for which we need to take a new slice?
|
||||
//
|
||||
|
@ -562,6 +562,13 @@ void ftFileCreator::getAvailabilityMap(CompressedChunkMap& map)
|
|||
chunkMap.getAvailabilityMap(map) ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::sourceIsComplete(const std::string& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
return chunkMap.getSourceChunksInfo(peer_id)->is_full ;
|
||||
}
|
||||
|
||||
void ftFileCreator::setSourceMap(const std::string& peer_id,const CompressedChunkMap& compressed_map)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
|
|
@ -117,6 +117,10 @@ class ftFileCreator: public ftFileProvider
|
|||
//
|
||||
void setSourceMap(const std::string& peer_id,const CompressedChunkMap& map) ;
|
||||
|
||||
// Returns true id the given file source is complete.
|
||||
//
|
||||
bool sourceIsComplete(const std::string& peer_id) ;
|
||||
|
||||
protected:
|
||||
|
||||
virtual int locked_initializeFileAttrs();
|
||||
|
|
|
@ -598,6 +598,8 @@ bool ftTransferModule::checkFile()
|
|||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
forceCheck() ;
|
||||
return false ;
|
||||
}
|
||||
|
@ -699,18 +701,21 @@ bool ftTransferModule::checkCRC()
|
|||
break ;
|
||||
}
|
||||
|
||||
int n = rand()%(mFileSources.size()) ;
|
||||
int p=0 ;
|
||||
std::map<std::string,peerInfo>::const_iterator mit ;
|
||||
for(mit = mFileSources.begin();mit != mFileSources.end() && p<n;++mit,++p) ;
|
||||
bool found = false ;
|
||||
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::checkCRC(): sending CRC map request to source " << mit->first << std::endl ;
|
||||
#endif
|
||||
_crcmap_last_asked_time = now ;
|
||||
_crcreq_source = mit->first ;
|
||||
for(std::map<std::string,peerInfo>::const_iterator mit = mFileSources.begin();mit != mFileSources.end();++mit)
|
||||
if(mFileCreator->sourceIsComplete(mit->first))
|
||||
{
|
||||
//#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::checkCRC(): sending CRC map request to source " << mit->first << std::endl ;
|
||||
//#endif
|
||||
_crcmap_last_asked_time = now ;
|
||||
_crcreq_source = mit->first ;
|
||||
|
||||
mMultiplexor->sendCRC32MapRequest(mit->first,mHash);
|
||||
mMultiplexor->sendCRC32MapRequest(mit->first,mHash);
|
||||
found = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
|
||||
|
@ -750,7 +755,7 @@ bool ftTransferModule::checkCRC()
|
|||
{
|
||||
// We do as if the file is not complete. This way, it finishes properly.
|
||||
//
|
||||
mFlag = FT_TM_FLAG_DOWNLOADING ;
|
||||
mFlag = FT_TM_FLAG_COMPLETE ; // Transfer is complete.
|
||||
mFileStatus.stat = ftFileStatus::PQIFILE_DOWNLOADING;
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::checkCRC(): Done. CRC check is ok, file is complete." << std::endl ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue