mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
added some safety checks to setting chunk strategy against inconsistent values.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3236 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f7ff141a37
commit
c8fc75c75c
@ -169,9 +169,7 @@ bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChun
|
|||||||
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: c = getAvailableChunk(rand()%_map.size(),peer_id,source_chunk_map_needed) ;
|
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: c = getAvailableChunk(rand()%_map.size(),peer_id,source_chunk_map_needed) ;
|
||||||
break ;
|
break ;
|
||||||
default:
|
default:
|
||||||
#ifdef DEBUG_FTCHUNK
|
|
||||||
std::cerr << "!!! ChunkMap::getDataChunk: error!: unknown strategy" << std::endl ;
|
std::cerr << "!!! ChunkMap::getDataChunk: error!: unknown strategy" << std::endl ;
|
||||||
#endif
|
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,6 +919,9 @@ bool ftController::handleAPendingRequest()
|
|||||||
req = mPendingRequests.front();
|
req = mPendingRequests.front();
|
||||||
mPendingRequests.pop_front();
|
mPendingRequests.pop_front();
|
||||||
}
|
}
|
||||||
|
#ifdef CONTROL_DEBUG
|
||||||
|
std::cerr << "Requesting pending hash " << req.mHash << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
FileRequest(req.mName, req.mHash, req.mSize, req.mDest, req.mFlags, req.mSrcIds);
|
FileRequest(req.mName, req.mHash, req.mSize, req.mDest, req.mFlags, req.mSrcIds);
|
||||||
|
|
||||||
@ -942,6 +945,10 @@ bool ftController::handleAPendingRequest()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef CONTROL_DEBUG
|
||||||
|
std::cerr << "Hash " << req.mHash << " is in downloads" << std::endl ;
|
||||||
|
std::cerr << " setting chunk strategy to " << rsft->chunk_strategy << std::endl;
|
||||||
|
#endif
|
||||||
(fit->second)->mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
|
(fit->second)->mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
|
||||||
(fit->second)->mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
|
(fit->second)->mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
|
||||||
}
|
}
|
||||||
@ -949,6 +956,10 @@ bool ftController::handleAPendingRequest()
|
|||||||
delete rsft ;
|
delete rsft ;
|
||||||
mPendingChunkMaps.erase(it) ;
|
mPendingChunkMaps.erase(it) ;
|
||||||
}
|
}
|
||||||
|
#ifdef CONTROL_DEBUG
|
||||||
|
else
|
||||||
|
std::cerr << "No pending chunkmap for hash " << req.mHash << std::endl ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
|
@ -138,7 +138,7 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
|||||||
#ifdef FILE_DEBUG
|
#ifdef FILE_DEBUG
|
||||||
std::cerr << "ftFileCreator::addFileData() added Data...";
|
std::cerr << "ftFileCreator::addFileData() added Data...";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << " pos: " << pos;
|
std::cerr << " pos: " << offset;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
@ -318,6 +318,13 @@ void ftFileCreator::setChunkStrategy(FileChunksInfo::ChunkStrategy s)
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
// Let's check, for safety.
|
||||||
|
if(s != FileChunksInfo::CHUNK_STRATEGY_STREAMING && s != FileChunksInfo::CHUNK_STRATEGY_RANDOM)
|
||||||
|
{
|
||||||
|
std::cerr << "ftFileCreator::ERROR: invalid chunk strategy " << s << "!" << " setting default value " << FileChunksInfo::CHUNK_STRATEGY_STREAMING << std::endl ;
|
||||||
|
s = FileChunksInfo::CHUNK_STRATEGY_STREAMING ;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef FILE_DEBUG
|
#ifdef FILE_DEBUG
|
||||||
std::cerr << "ftFileCtreator: setting chunk strategy to " << s << std::endl ;
|
std::cerr << "ftFileCtreator: setting chunk strategy to " << s << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user