mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 23:19:29 -05:00
changed a bit the file transfer strategy. To be tested further.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3898 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a79d2a8e53
commit
f5bfc8c92a
@ -41,7 +41,7 @@ static const uint32_t INACTIVE_CHUNK_TIME_LAPSE = 60 ; //! TTL for an inactive
|
||||
|
||||
std::ostream& operator<<(std::ostream& o,const ftChunk& c)
|
||||
{
|
||||
return o << "\tChunk [" << c.offset << "] size: " << c.size << " ChunkId: " << c.id << " Age: " << time(NULL) - c.ts ;
|
||||
return o << "\tChunk [" << c.offset << "] size: " << c.size << " ChunkId: " << c.id << " Age: " << time(NULL) - c.ts << ", owner: " << c.peer_id ;
|
||||
}
|
||||
|
||||
// Chunk: very bold implementation for now. We should compress the bits to have
|
||||
@ -221,6 +221,7 @@ bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChun
|
||||
if(_active_chunks_feed[peer_id].empty())
|
||||
_active_chunks_feed.erase(_active_chunks_feed.find(peer_id)) ;
|
||||
|
||||
chunk.peer_id = peer_id ;
|
||||
#ifdef DEBUG_FTCHUNK
|
||||
std::cout << "*** ChunkMap::getDataChunk: returning slice " << chunk << " for peer " << peer_id << std::endl ;
|
||||
#endif
|
||||
|
@ -42,6 +42,7 @@ class ftChunk
|
||||
uint64_t size;
|
||||
ChunkId id ;
|
||||
time_t ts;
|
||||
std::string peer_id ;
|
||||
};
|
||||
|
||||
// This class handles a single fixed-sized chunk. Although each chunk is requested at once,
|
||||
|
@ -8,8 +8,8 @@
|
||||
* #define FILE_DEBUG 1
|
||||
******/
|
||||
|
||||
#define CHUNK_MAX_AGE 20
|
||||
|
||||
#define CHUNK_MAX_AGE 40
|
||||
#define MAX_FTCHUNKS_PER_PEER 5
|
||||
|
||||
/***********************************************************
|
||||
*
|
||||
@ -202,6 +202,7 @@ void ftFileCreator::removeInactiveChunks()
|
||||
{
|
||||
std::map<uint64_t,ftChunk>::iterator tmp(it) ;
|
||||
++it ;
|
||||
--mChunksPerPeer[tmp->second.peer_id].cnt ;
|
||||
mChunks.erase(tmp) ;
|
||||
}
|
||||
else
|
||||
@ -320,8 +321,11 @@ int ftFileCreator::locked_notifyReceived(uint64_t offset, uint32_t chunk_size)
|
||||
chunk.offset += chunk_size;
|
||||
mChunks[chunk.offset] = chunk;
|
||||
}
|
||||
else // notify the chunkmap that the slice is finished
|
||||
else // notify the chunkmap that the slice is finished, and decrement the number of chunks for this peer.
|
||||
{
|
||||
chunkMap.dataReceived(chunk.id) ;
|
||||
--mChunksPerPeer[chunk.peer_id].cnt ;
|
||||
}
|
||||
|
||||
_last_recv_time_t = time(NULL) ;
|
||||
|
||||
@ -371,26 +375,36 @@ bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hin
|
||||
|
||||
/* check for freed chunks */
|
||||
time_t ts = time(NULL);
|
||||
time_t old = ts-CHUNK_MAX_AGE;
|
||||
// time_t old = ts-CHUNK_MAX_AGE;
|
||||
//
|
||||
// std::map<uint64_t, ftChunk>::iterator it;
|
||||
// for(it = mChunks.begin(); it != mChunks.end(); it++)
|
||||
// {
|
||||
// /* very simple algorithm */
|
||||
// if (it->second.ts < old)
|
||||
// {
|
||||
//#ifdef FILE_DEBUG
|
||||
// std::cerr << "ffc::getMissingChunk() Re-asking for an old chunk";
|
||||
// std::cerr << std::endl;
|
||||
//#endif
|
||||
//
|
||||
// /* retry this one */
|
||||
// it->second.ts = ts;
|
||||
// size = it->second.size;
|
||||
// offset = it->second.offset;
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
std::map<uint64_t, ftChunk>::iterator it;
|
||||
for(it = mChunks.begin(); it != mChunks.end(); it++)
|
||||
uint32_t& chunks_for_this_peer(mChunksPerPeer[peer_id].cnt) ;
|
||||
|
||||
if(chunks_for_this_peer >= MAX_FTCHUNKS_PER_PEER)
|
||||
{
|
||||
/* very simple algorithm */
|
||||
if (it->second.ts < old)
|
||||
{
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "ffc::getMissingChunk() Re-asking for an old chunk";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "ffc::getMissingChunk() too many chunks for peer " << peer_id << std::endl ;
|
||||
#endif
|
||||
|
||||
/* retry this one */
|
||||
it->second.ts = ts;
|
||||
size = it->second.size;
|
||||
offset = it->second.offset;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
/* else allocate a new chunk */
|
||||
@ -409,6 +423,8 @@ bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hin
|
||||
offset = chunk.offset ;
|
||||
size = chunk.size ;
|
||||
|
||||
++chunks_for_this_peer ; // increase number of chunks for this peer.
|
||||
|
||||
return true; /* cos more data to get */
|
||||
}
|
||||
|
||||
@ -436,6 +452,10 @@ bool ftFileCreator::locked_printChunkMap()
|
||||
for(it = mChunks.begin(); it != mChunks.end(); it++)
|
||||
std::cerr << " " << it->second << std::endl ;
|
||||
|
||||
std::cerr << "Active chunks per peer:" << std::endl ;
|
||||
for(std::map<std::string,ZeroInitCounter>::const_iterator it(mChunksPerPeer.begin());it!=mChunksPerPeer.end();++it)
|
||||
std::cerr << " " << it->first << "\t: " << it->second.cnt << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,13 @@
|
||||
#include "ftchunkmap.h"
|
||||
#include <map>
|
||||
|
||||
class ZeroInitCounter
|
||||
{
|
||||
public:
|
||||
ZeroInitCounter(): cnt(0) {}
|
||||
uint32_t cnt ;
|
||||
};
|
||||
|
||||
class ftFileCreator: public ftFileProvider
|
||||
{
|
||||
public:
|
||||
@ -131,6 +138,7 @@ class ftFileCreator: public ftFileProvider
|
||||
uint64_t mEnd;
|
||||
|
||||
std::map<uint64_t, ftChunk> mChunks;
|
||||
std::map<std::string,ZeroInitCounter> mChunksPerPeer ;
|
||||
|
||||
ChunkMap chunkMap ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user