From b94e4376a4d67c6d10fd7ae23c7cf26d3f5033ea Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 22 Nov 2010 20:57:53 +0000 Subject: [PATCH] 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 --- libretroshare/src/ft/ftchunkmap.cc | 11 +++++------ libretroshare/src/ft/ftchunkmap.h | 6 ++---- libretroshare/src/ft/ftcontroller.cc | 4 +++- libretroshare/src/ft/ftfilecreator.cc | 8 +++++--- libretroshare/src/ft/ftfilecreator.h | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libretroshare/src/ft/ftchunkmap.cc b/libretroshare/src/ft/ftchunkmap.cc index 1efa008a9..5ed39703e 100644 --- a/libretroshare/src/ft/ftchunkmap.cc +++ b/libretroshare/src/ft/ftchunkmap.cc @@ -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 ; diff --git a/libretroshare/src/ft/ftchunkmap.h b/libretroshare/src/ft/ftchunkmap.h index 46a088c6f..7b79259fd 100644 --- a/libretroshare/src/ft/ftchunkmap.h +++ b/libretroshare/src/ft/ftchunkmap.h @@ -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& 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 _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. }; diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 41e12d856..79264dbe4 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -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 diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 32c5b480f..fe14ee871 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -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 diff --git a/libretroshare/src/ft/ftfilecreator.h b/libretroshare/src/ft/ftfilecreator.h index 1048fa7c7..7915d95ae 100644 --- a/libretroshare/src/ft/ftfilecreator.h +++ b/libretroshare/src/ft/ftfilecreator.h @@ -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();