only assume availability for cache transfers. All other transfers now use ChunkMaps

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3853 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-11-22 20:57:53 +00:00
parent 0b9a5e5b2b
commit b94e4376a4
5 changed files with 16 additions and 15 deletions

View File

@ -65,16 +65,17 @@ void Chunk::getSlice(uint32_t size_hint,ftChunk& chunk)
_offset += chunk.size ;
}
ChunkMap::ChunkMap(uint64_t s)
ChunkMap::ChunkMap(uint64_t s,bool availability)
: _file_size(s),
_chunk_size(CHUNKMAP_FIXED_CHUNK_SIZE) // 1MB chunks
_chunk_size(CHUNKMAP_FIXED_CHUNK_SIZE), // 1MB chunks
_assume_availability(availability)
{
uint64_t n = s/(uint64_t)_chunk_size ;
if(s% (uint64_t)_chunk_size != 0)
++n ;
_map.resize(n,FileChunksInfo::CHUNK_OUTSTANDING) ;
_strategy = FileChunksInfo::CHUNK_STRATEGY_STREAMING ;
_strategy = FileChunksInfo::CHUNK_STRATEGY_RANDOM ;
_total_downloaded = 0 ;
_file_is_complete = false ;
#ifdef DEBUG_FTCHUNK
@ -355,13 +356,11 @@ uint32_t ChunkMap::getAvailableChunk(const std::string& peer_id,bool& map_is_too
{
SourceChunksInfo& pchunks(_peers_chunks_availability[peer_id]) ;
bool assume_availability = !(rsTurtle!=NULL && rsTurtle->isTurtlePeer(peer_id)) ;
// Ok, we don't have the info, so two cases:
// - peer_id is a not a turtle peer, so he is considered having the full file source, so we init with a plain chunkmap
// - otherwise, a source map needs to be obtained, so we init with a blank chunkmap
//
if(assume_availability)
if(_assume_availability)
{
pchunks.cmap._map.resize( CompressedChunkMap::getCompressedSize(_map.size()),~(uint32_t)0 ) ;
pchunks.TS = 0 ;

View File

@ -92,10 +92,7 @@ class ChunkMap
/// Constructor. Decides what will be the size of chunks and how many there will be.
ChunkMap(uint64_t file_size) ;
/// constructor from saved map info
ChunkMap(uint64_t file_size,const std::vector<uint32_t>& map,uint32_t chunk_size,uint32_t chunk_number,FileChunksInfo::ChunkStrategy s) ;
ChunkMap(uint64_t file_size,bool assume_availability) ;
/// destructor
virtual ~ChunkMap() {}
@ -184,6 +181,7 @@ class ChunkMap
std::map<std::string,SourceChunksInfo> _peers_chunks_availability ; //! what does each source peer have
uint64_t _total_downloaded ; //! completion for the file
bool _file_is_complete ; //! set to true when the file is complete.
bool _assume_availability ; //! true if all sources always have the complete file.
};

View File

@ -1200,7 +1200,9 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
mTurtle->monitorFileTunnels(fname,hash,size) ;
ftFileCreator *fc = new ftFileCreator(savepath, size, hash);
bool assume_availability = flags & RS_FILE_HINTS_CACHE ; // assume availability for cache files
ftFileCreator *fc = new ftFileCreator(savepath, size, hash,assume_availability);
ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this);
#ifdef CONTROL_DEBUG

View File

@ -17,8 +17,8 @@
*
***********************************************************/
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash)
: ftFileProvider(path,size,hash), chunkMap(size)
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash,bool assume_availability)
: ftFileProvider(path,size,hash), chunkMap(size,assume_availability)
{
/*
* FIXME any inits to do?
@ -539,7 +539,9 @@ bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,
else
{
printf(" cannot fseek!\n") ;
return false ;
++bad_chunks ;
++incomplete_chunks ;
map.reset(i) ;
}
}
else

View File

@ -40,7 +40,7 @@ class ftFileCreator: public ftFileProvider
{
public:
ftFileCreator(std::string savepath, uint64_t size, std::string hash);
ftFileCreator(std::string savepath, uint64_t size, std::string hash,bool assume_availability);
~ftFileCreator();