mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-20 20:08:30 -04:00
added method in ftServer to allow retrieving data from shared/downloaded files (patch from electron, modified)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7999 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
400d3179e8
commit
a1b36cd530
13 changed files with 140 additions and 18 deletions
|
@ -65,7 +65,7 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const RsFil
|
|||
#endif
|
||||
}
|
||||
|
||||
bool ftFileCreator::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
bool ftFileCreator::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data, bool allow_unverified)
|
||||
{
|
||||
// Only send the data if we actually have it.
|
||||
//
|
||||
|
@ -77,6 +77,37 @@ bool ftFileCreator::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_
|
|||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
have_it = chunkMap.isChunkAvailable(offset, chunk_size) ;
|
||||
|
||||
#define ENABLE_SLICES
|
||||
#ifdef ENABLE_SLICES
|
||||
// try if we have data from an incomplete or not veryfied chunk
|
||||
if(!have_it && allow_unverified)
|
||||
{
|
||||
std::map<uint64_t, ftChunk>::iterator it;
|
||||
have_it = true;
|
||||
// this map contains chunks which are currently being downloaded
|
||||
for(std::map<uint64_t,ftChunk>::iterator it=mChunks.begin(); it!=mChunks.end(); ++it)
|
||||
{
|
||||
ftChunk chunk = it->second;
|
||||
// begin of slice is in requested range
|
||||
if(chunk.offset >= offset && chunk.offset < (offset+chunk_size))
|
||||
{
|
||||
// reduce the requested size
|
||||
chunk_size = chunk.offset - offset;
|
||||
}
|
||||
// end of slice is in requested range
|
||||
if((chunk.offset+chunk.size) >= offset && (chunk.offset+chunk.size) < (offset+chunk_size))
|
||||
{
|
||||
// can do nothing about this
|
||||
have_it = false;
|
||||
}
|
||||
}
|
||||
// check if the chunk was already started to download
|
||||
// if not, we don't have it
|
||||
if(chunkMap.isChunkOutstanding(offset, chunk_size))
|
||||
have_it = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef FILE_DEBUG
|
||||
if(have_it)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue