mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-18 10:58:43 -04:00
saving intermediate work for id cleaning
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7087 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
08d64be2e5
commit
33ab4ee3b5
61 changed files with 1016 additions and 1005 deletions
|
@ -267,15 +267,15 @@ void ChunkMap::setChunkCheckingResult(uint32_t chunk_number,bool check_succeeded
|
|||
// - chunks pushed when new chunks are needed
|
||||
// - chunks removed when completely downloaded
|
||||
//
|
||||
bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed)
|
||||
bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed)
|
||||
{
|
||||
#ifdef DEBUG_FTCHUNK
|
||||
std::cerr << "*** ChunkMap::getDataChunk: size_hint = " << size_hint << std::endl ;
|
||||
#endif
|
||||
// 1 - find if this peer already has an active chunk.
|
||||
//
|
||||
std::map<std::string,Chunk>::iterator it = _active_chunks_feed.find(peer_id) ;
|
||||
std::map<std::string,Chunk>::iterator falsafe_it = _active_chunks_feed.end() ;
|
||||
std::map<RsPeerId,Chunk>::iterator it = _active_chunks_feed.find(peer_id) ;
|
||||
std::map<RsPeerId,Chunk>::iterator falsafe_it = _active_chunks_feed.end() ;
|
||||
|
||||
if(it == _active_chunks_feed.end())
|
||||
{
|
||||
|
@ -284,7 +284,7 @@ bool ChunkMap::getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChun
|
|||
// 0 - Look into other pending chunks and slice from here. We only consider chunks with size smaller than
|
||||
// the requested size,
|
||||
//
|
||||
for(std::map<std::string,Chunk>::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit)
|
||||
for(std::map<RsPeerId,Chunk>::iterator pit(_active_chunks_feed.begin());pit!=_active_chunks_feed.end();++pit)
|
||||
{
|
||||
uint32_t c = pit->second._start / _chunk_size ;
|
||||
|
||||
|
@ -385,10 +385,10 @@ void ChunkMap::removeInactiveChunks(std::vector<ftChunk::ChunkId>& to_remove)
|
|||
|
||||
// Also remove the chunk from the chunk feed, to free the associated peer.
|
||||
//
|
||||
for(std::map<std::string,Chunk>::iterator it3=_active_chunks_feed.begin();it3!=_active_chunks_feed.end();)
|
||||
for(std::map<RsPeerId,Chunk>::iterator it3=_active_chunks_feed.begin();it3!=_active_chunks_feed.end();)
|
||||
if(it3->second._start == _chunk_size*uint64_t(it->first))
|
||||
{
|
||||
std::map<std::string,Chunk>::iterator tmp3 = it3 ;
|
||||
std::map<RsPeerId,Chunk>::iterator tmp3 = it3 ;
|
||||
++it3 ;
|
||||
_active_chunks_feed.erase(tmp3) ;
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ bool ChunkMap::isChunkAvailable(uint64_t offset, uint32_t chunk_size) const
|
|||
return true ;
|
||||
}
|
||||
|
||||
void ChunkMap::setPeerAvailabilityMap(const std::string& peer_id,const CompressedChunkMap& cmap)
|
||||
void ChunkMap::setPeerAvailabilityMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap)
|
||||
{
|
||||
#ifdef DEBUG_FTCHUNK
|
||||
std::cout << "ChunkMap::Receiving new availability map for peer " << peer_id << std::endl ;
|
||||
|
@ -469,9 +469,9 @@ uint32_t ChunkMap::sizeOfChunk(uint32_t cid) const
|
|||
return _chunk_size ;
|
||||
}
|
||||
|
||||
SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id)
|
||||
SourceChunksInfo *ChunkMap::getSourceChunksInfo(const RsPeerId& peer_id)
|
||||
{
|
||||
std::map<std::string,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
std::map<RsPeerId,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
|
||||
// Do we have a chunk map for this file source ?
|
||||
// - if yes, we use it
|
||||
|
@ -508,16 +508,16 @@ SourceChunksInfo *ChunkMap::getSourceChunksInfo(const std::string& peer_id)
|
|||
return &(it->second) ;
|
||||
}
|
||||
|
||||
void ChunkMap::getSourcesList(uint32_t chunk_number,std::vector<std::string>& sources)
|
||||
void ChunkMap::getSourcesList(uint32_t chunk_number,std::vector<RsPeerId>& sources)
|
||||
{
|
||||
sources.clear() ;
|
||||
|
||||
for(std::map<std::string,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
for(std::map<RsPeerId,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
if(it->second.cmap[chunk_number])
|
||||
sources.push_back(it->first) ;
|
||||
}
|
||||
|
||||
uint32_t ChunkMap::getAvailableChunk(const std::string& peer_id,bool& map_is_too_old)
|
||||
uint32_t ChunkMap::getAvailableChunk(const RsPeerId& peer_id,bool& map_is_too_old)
|
||||
{
|
||||
// Quite simple strategy: Check for 1st availabe chunk for this peer starting from the given start location.
|
||||
//
|
||||
|
@ -601,13 +601,13 @@ void ChunkMap::getChunksInfo(FileChunksInfo& info) const
|
|||
|
||||
info.compressed_peer_availability_maps.clear() ;
|
||||
|
||||
for(std::map<std::string,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
for(std::map<RsPeerId,SourceChunksInfo>::const_iterator it(_peers_chunks_availability.begin());it!=_peers_chunks_availability.end();++it)
|
||||
info.compressed_peer_availability_maps[it->first] = it->second.cmap ;
|
||||
}
|
||||
|
||||
void ChunkMap::removeFileSource(const std::string& peer_id)
|
||||
void ChunkMap::removeFileSource(const RsPeerId& peer_id)
|
||||
{
|
||||
std::map<std::string,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
std::map<RsPeerId,SourceChunksInfo>::iterator it(_peers_chunks_availability.find(peer_id)) ;
|
||||
|
||||
if(it == _peers_chunks_availability.end())
|
||||
return ;
|
||||
|
|
|
@ -43,7 +43,7 @@ class ftChunk
|
|||
ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk
|
||||
time_t ts; // time of last data received
|
||||
int *ref_cnt; // shared counter of number of sub-blocks. Used when a slice gets split.
|
||||
std::string peer_id ;
|
||||
RsPeerId peer_id ;
|
||||
};
|
||||
|
||||
// This class handles a single fixed-sized chunk. Although each chunk is requested at once,
|
||||
|
@ -118,7 +118,7 @@ class ChunkMap
|
|||
/// On return:
|
||||
/// - source_chunk_map_needed = true if the source map should be asked
|
||||
|
||||
virtual bool getDataChunk(const std::string& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ;
|
||||
virtual bool getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk& chunk,bool& source_chunk_map_needed) ;
|
||||
|
||||
/// Notify received a slice of data. This needs to
|
||||
/// - carve in the map of chunks what is received, what is not.
|
||||
|
@ -145,7 +145,7 @@ class ChunkMap
|
|||
void setAvailabilityMap(const CompressedChunkMap& cmap) ;
|
||||
|
||||
/// Removes the source availability map. The map
|
||||
void removeFileSource(const std::string& peer_id) ;
|
||||
void removeFileSource(const RsPeerId& peer_id) ;
|
||||
|
||||
/// This function fills in a plain map for a file of the given size. This
|
||||
/// is used to ensure that the chunk size will be consistent with the rest
|
||||
|
@ -165,12 +165,12 @@ class ChunkMap
|
|||
|
||||
/// Updates the peer's availablility map
|
||||
//
|
||||
void setPeerAvailabilityMap(const std::string& peer_id,const CompressedChunkMap& peer_map) ;
|
||||
void setPeerAvailabilityMap(const RsPeerId& peer_id,const CompressedChunkMap& peer_map) ;
|
||||
|
||||
/// Returns a pointer to the availability chunk map of the given source, and possibly
|
||||
/// allocates it if necessary.
|
||||
//
|
||||
SourceChunksInfo *getSourceChunksInfo(const std::string& peer_id) ;
|
||||
SourceChunksInfo *getSourceChunksInfo(const RsPeerId& peer_id) ;
|
||||
|
||||
/// Returns the total size of downloaded data in the file.
|
||||
uint64_t getTotalReceived() const { return _total_downloaded ; }
|
||||
|
@ -188,7 +188,7 @@ class ChunkMap
|
|||
void getChunksToCheck(std::vector<uint32_t>& chunks_to_ask) ;
|
||||
|
||||
/// Get all available sources for this chunk
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<std::string>& sources) ;
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<RsPeerId>& sources) ;
|
||||
|
||||
/// sets all chunks to checking state
|
||||
void forceCheck() ;
|
||||
|
@ -203,16 +203,16 @@ class ChunkMap
|
|||
|
||||
/// Returns a chunk available for this peer_id, depending on the chunk strategy.
|
||||
//
|
||||
uint32_t getAvailableChunk(const std::string& peer_id,bool& chunk_map_too_old) ;
|
||||
uint32_t getAvailableChunk(const RsPeerId& peer_id,bool& chunk_map_too_old) ;
|
||||
|
||||
private:
|
||||
uint64_t _file_size ; //! total size of the file in bytes.
|
||||
uint32_t _chunk_size ; //! Size of chunks. Common to all chunks.
|
||||
FileChunksInfo::ChunkStrategy _strategy ; //! how do we allocate new chunks
|
||||
std::map<std::string,Chunk> _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer.
|
||||
std::map<RsPeerId,Chunk> _active_chunks_feed ; //! vector of chunks being downloaded. Exactly 1 chunk per peer.
|
||||
std::map<ChunkNumber,ChunkDownloadInfo> _slices_to_download ; //! list of (slice id,slice size)
|
||||
std::vector<FileChunksInfo::ChunkState> _map ; //! vector of chunk state over the whole file
|
||||
std::map<std::string,SourceChunksInfo> _peers_chunks_availability ; //! what does each source peer have
|
||||
std::map<RsPeerId,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.
|
||||
|
|
|
@ -161,7 +161,7 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun
|
|||
return false ;
|
||||
}
|
||||
|
||||
void ftController::addFileSource(const std::string& hash,const std::string& peer_id)
|
||||
void ftController::addFileSource(const std::string& hash,const SSLIdType& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
|
@ -184,7 +184,7 @@ void ftController::addFileSource(const std::string& hash,const std::string& peer
|
|||
std::cerr << "... not added: hash not found." << std::endl ;
|
||||
#endif
|
||||
}
|
||||
void ftController::removeFileSource(const std::string& hash,const std::string& peer_id)
|
||||
void ftController::removeFileSource(const std::string& hash,const SSLIdType& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
|
@ -293,7 +293,7 @@ void ftController::searchForDirectSources()
|
|||
|
||||
if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
|
||||
for(std::list<TransferInfo>::const_iterator pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
||||
if(rsPeers->servicePermissionFlags_sslid(pit->peerId) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
if(rsPeers->servicePermissionFlags(pit->peerId) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
if(it->second->mTransfer->addFileSource(pit->peerId)) /* if the sources don't exist already - add in */
|
||||
setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mLinkMgr->isOnline( pit->peerId ));
|
||||
}
|
||||
|
@ -1070,9 +1070,9 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
|||
|
||||
bool ftController::FileRequest(const std::string& fname, const std::string& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &_srcIds, uint16_t state)
|
||||
const std::list<SSLIdType> &_srcIds, uint16_t state)
|
||||
{
|
||||
std::list<std::string> srcIds(_srcIds) ;
|
||||
std::list<SSLIdType> srcIds(_srcIds) ;
|
||||
|
||||
/* check if we have the file */
|
||||
|
||||
|
@ -1134,10 +1134,10 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
// remove the sources from the list, if they don't have clearance for direct transfer. This happens only for non cache files.
|
||||
//
|
||||
if(!(flags & RS_FILE_REQ_CACHE))
|
||||
for(std::list<std::string>::iterator it = srcIds.begin(); it != srcIds.end(); )
|
||||
if(!(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL))
|
||||
for(std::list<SSLIdType>::iterator it = srcIds.begin(); it != srcIds.end(); )
|
||||
if(!(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL))
|
||||
{
|
||||
std::list<std::string>::iterator tmp(it) ;
|
||||
std::list<SSLIdType>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
srcIds.erase(it) ;
|
||||
it = tmp ;
|
||||
|
@ -1145,7 +1145,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
else
|
||||
++it ;
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
std::list<SSLIdType>::const_iterator it;
|
||||
std::list<TransferInfo>::const_iterator pit;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
|
@ -1191,7 +1191,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
*/
|
||||
|
||||
for(it = srcIds.begin(); it != srcIds.end(); it++)
|
||||
if(rsPeers->servicePermissionFlags_sslid(*it) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
if(rsPeers->servicePermissionFlags(*it) & RS_SERVICE_PERM_DIRECT_DL)
|
||||
{
|
||||
uint32_t i, j;
|
||||
if ((dit->second)->mTransfer->getPeerState(*it, i, j))
|
||||
|
@ -1248,7 +1248,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
#endif
|
||||
// Because this is auto-add, we only add sources that we allow to DL from using direct transfers.
|
||||
|
||||
if ((srcIds.end() == std::find( srcIds.begin(), srcIds.end(), pit->peerId)) && (RS_SERVICE_PERM_DIRECT_DL & rsPeers->servicePermissionFlags_sslid(pit->peerId)))
|
||||
if ((srcIds.end() == std::find( srcIds.begin(), srcIds.end(), pit->peerId)) && (RS_SERVICE_PERM_DIRECT_DL & rsPeers->servicePermissionFlags(pit->peerId)))
|
||||
{
|
||||
srcIds.push_back(pit->peerId);
|
||||
|
||||
|
@ -1331,7 +1331,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t maxrate, bool online)
|
||||
bool ftController::setPeerState(ftTransferModule *tm, const SSLIdType& id, uint32_t maxrate, bool online)
|
||||
{
|
||||
if (id == mLinkMgr->getOwnId())
|
||||
{
|
||||
|
@ -1708,8 +1708,8 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
|||
info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; // file being downloaded anonymously are always anonymously available.
|
||||
|
||||
/* get list of sources from transferModule */
|
||||
std::list<std::string> peerIds;
|
||||
std::list<std::string>::iterator pit;
|
||||
std::list<SSLIdType> peerIds;
|
||||
std::list<SSLIdType>::iterator pit;
|
||||
|
||||
if (!completed)
|
||||
{
|
||||
|
@ -1922,7 +1922,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
|
|||
#endif
|
||||
|
||||
/* Request File */
|
||||
std::list<std::string> ids;
|
||||
std::list<SSLIdType> ids;
|
||||
ids.push_back(id);
|
||||
|
||||
FileInfo info ;
|
||||
|
|
|
@ -96,7 +96,7 @@ class ftPendingRequest
|
|||
public:
|
||||
ftPendingRequest(const std::string& fname, const std::string& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &srcIds, uint16_t state)
|
||||
const std::list<SSLIdType> &srcIds, uint16_t state)
|
||||
: mName(fname), mHash(hash), mSize(size),
|
||||
mDest(dest), mFlags(flags), mSrcIds(srcIds), mState(state) { return; }
|
||||
|
||||
|
@ -107,7 +107,7 @@ class ftPendingRequest
|
|||
uint64_t mSize;
|
||||
std::string mDest;
|
||||
TransferRequestFlags mFlags;
|
||||
std::list<std::string> mSrcIds;
|
||||
std::list<SSLIdType> mSrcIds;
|
||||
uint16_t mState;
|
||||
};
|
||||
|
||||
|
@ -133,7 +133,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
|
||||
bool FileRequest(const std::string& fname, const std::string& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING);
|
||||
const std::list<SSLIdType> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING);
|
||||
|
||||
/// Do we already have this file, either in download or in file lists ?
|
||||
bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||
|
@ -184,12 +184,12 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
|
||||
/// Returns true is full source availability can be assumed for this peer.
|
||||
///
|
||||
bool assumeAvailability(const std::string& peer_id) const ;
|
||||
bool assumeAvailability(const SSLIdType& peer_id) const ;
|
||||
|
||||
/* pqiMonitor callback (also provided mConnMgr pointer!) */
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
void addFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||
void removeFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||
void addFileSource(const std::string& hash,const SSLIdType& peer_id) ;
|
||||
void removeFileSource(const std::string& hash,const SSLIdType& peer_id) ;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -226,7 +226,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
bool completeFile(std::string hash);
|
||||
bool handleAPendingRequest();
|
||||
|
||||
bool setPeerState(ftTransferModule *tm, std::string id,
|
||||
bool setPeerState(ftTransferModule *tm, const SSLIdType& id,
|
||||
uint32_t maxrate, bool online);
|
||||
|
||||
time_t last_save_time ;
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <util/rsid.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
/*************** SEND INTERFACE *******************/
|
||||
|
@ -51,23 +50,23 @@ class ftDataSend
|
|||
virtual ~ftDataSend() { return; }
|
||||
|
||||
/* Client Send */
|
||||
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
|
||||
/* Server Send */
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
virtual bool sendData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
|
||||
/// Send a chunkmap[request]. Because requests/chunkmaps can go both
|
||||
//directions, but for different usages, we have this "is_client" flags,
|
||||
//that gives the ultimate goal of the data. "is_client==true" means that
|
||||
//the message is for a client (download) instead of a server.
|
||||
//
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
virtual bool sendChunkMap(const RsPeerId& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
|
||||
/// Send a request for a chunk crc map
|
||||
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) = 0;
|
||||
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number) = 0;
|
||||
/// Send a chunk crc map
|
||||
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) = 0;
|
||||
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -80,19 +79,19 @@ class ftDataRecv
|
|||
virtual ~ftDataRecv() { return; }
|
||||
|
||||
/* Client Recv */
|
||||
virtual bool recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
virtual bool recvData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
|
||||
/* Server Recv */
|
||||
virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
virtual bool recvDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) = 0;
|
||||
|
||||
/// Send a request for a chunk map
|
||||
virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
virtual bool recvChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
|
||||
/// Send a chunk map
|
||||
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
virtual bool recvChunkMap(const RsPeerId& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
|
||||
virtual bool recvSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) = 0;
|
||||
virtual bool recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0;
|
||||
virtual bool recvSingleChunkCRCRequest(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_id) = 0;
|
||||
virtual bool recvSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -63,14 +63,14 @@ const uint32_t FT_SERVER_CHUNK_MAP_REQ = 0x0004; // chunk map request to be tre
|
|||
//const uint32_t FT_CRC32MAP_REQ = 0x0005; // crc32 map request to be treated by server
|
||||
const uint32_t FT_CLIENT_CHUNK_CRC_REQ = 0x0006; // chunk sha1 crc request to be treated
|
||||
|
||||
ftRequest::ftRequest(uint32_t type, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data)
|
||||
ftRequest::ftRequest(uint32_t type, const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data)
|
||||
:mType(type), mPeerId(peerId), mHash(hash), mSize(size),
|
||||
mOffset(offset), mChunk(chunk), mData(data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ftDataMultiplex::ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search)
|
||||
ftDataMultiplex::ftDataMultiplex(const RsPeerId& ownId, ftDataSend *server, ftSearch *search)
|
||||
:RsQueueThread(DMULTIPLEX_MIN, DMULTIPLEX_MAX, DMULTIPLEX_RELAX), dataMtx("ftDataMultiplex"),
|
||||
mDataSend(server), mSearch(search), mOwnId(ownId)
|
||||
{
|
||||
|
@ -204,7 +204,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
|
|||
/*************** SEND INTERFACE (calls ftDataSend) *******************/
|
||||
|
||||
/* Client Send */
|
||||
bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftDataMultiplex::sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::sendDataRequest() Client Send";
|
||||
|
@ -214,7 +214,7 @@ bool ftDataMultiplex::sendDataRequest(const std::string& peerId, const std::stri
|
|||
}
|
||||
|
||||
/* Server Send */
|
||||
bool ftDataMultiplex::sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
bool ftDataMultiplex::sendData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::sendData() Server Send";
|
||||
|
@ -227,7 +227,7 @@ bool ftDataMultiplex::sendData(const std::string& peerId, const std::string& has
|
|||
/*************** RECV INTERFACE (provides ftDataRecv) ****************/
|
||||
|
||||
/* Client Recv */
|
||||
bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
bool ftDataMultiplex::recvData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvData() Client Recv";
|
||||
|
@ -242,7 +242,7 @@ bool ftDataMultiplex::recvData(const std::string& peerId, const std::string& has
|
|||
|
||||
|
||||
/* Server Recv */
|
||||
bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftDataMultiplex::recvDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvDataRequest() Server Recv";
|
||||
|
@ -256,7 +256,7 @@ bool ftDataMultiplex::recvDataRequest(const std::string& peerId, const std::stri
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client)
|
||||
bool ftDataMultiplex::recvChunkMapRequest(const RsPeerId& peerId, const std::string& hash,bool is_client)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
|
||||
|
@ -273,7 +273,7 @@ bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::recvSingleChunkCRCRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_number)
|
||||
bool ftDataMultiplex::recvSingleChunkCRCRequest(const RsPeerId& peerId, const std::string& hash,uint32_t chunk_number)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
|
||||
|
@ -406,7 +406,7 @@ bool ftDataMultiplex::doWork()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::recvSingleChunkCRC(const std::string& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
bool ftDataMultiplex::recvSingleChunkCRC(const RsPeerId& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
|
@ -503,7 +503,7 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
|
|||
// - an uploader has sent his chunk map, so we need to store it in the corresponding ftFileProvider
|
||||
// - a source for a download has sent his chunk map, so we need to send it to the corresponding ftFileCreator.
|
||||
//
|
||||
bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string& hash,const CompressedChunkMap& compressed_map,bool client)
|
||||
bool ftDataMultiplex::recvChunkMap(const RsPeerId& peerId, const std::string& hash,const CompressedChunkMap& compressed_map,bool client)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
|
@ -549,7 +549,7 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string&
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash)
|
||||
bool ftDataMultiplex::handleRecvClientChunkMapRequest(const RsPeerId& peerId, const std::string& hash)
|
||||
{
|
||||
CompressedChunkMap cmap ;
|
||||
|
||||
|
@ -581,7 +581,7 @@ bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId,
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash, uint32_t chunk_number)
|
||||
bool ftDataMultiplex::handleRecvChunkCrcRequest(const RsPeerId& peerId, const std::string& hash, uint32_t chunk_number)
|
||||
{
|
||||
// look into the sha1sum cache
|
||||
|
||||
|
@ -705,7 +705,7 @@ bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash)
|
||||
bool ftDataMultiplex::handleRecvServerChunkMapRequest(const RsPeerId& peerId, const std::string& hash)
|
||||
{
|
||||
CompressedChunkMap cmap ;
|
||||
std::map<std::string, ftFileProvider *>::iterator it ;
|
||||
|
@ -754,9 +754,7 @@ bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleRecvData(const std::string& peerId,
|
||||
const std::string& hash, uint64_t /*size*/,
|
||||
uint64_t offset, uint32_t chunksize, void *data)
|
||||
bool ftDataMultiplex::handleRecvData(const RsPeerId& peerId, const std::string& hash, uint64_t /*size*/, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
ftTransferModule *transfer_module = NULL ;
|
||||
|
||||
|
@ -787,7 +785,7 @@ bool ftDataMultiplex::handleRecvData(const std::string& peerId,
|
|||
|
||||
|
||||
/* called by ftTransferModule */
|
||||
bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftDataMultiplex::handleRecvDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
/**** Find Files *****/
|
||||
|
||||
|
@ -833,8 +831,7 @@ bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
||||
std::string peerId, std::string hash, uint64_t size,
|
||||
bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, const RsPeerId& peerId, const std::string& hash, uint64_t size,
|
||||
uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
if(chunksize > uint32_t(10*1024*1024))
|
||||
|
@ -875,7 +872,7 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std::string& peerId,CompressedChunkMap& cmap)
|
||||
bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const RsPeerId& peerId,CompressedChunkMap& cmap)
|
||||
{
|
||||
bool too_old = false;
|
||||
{
|
||||
|
@ -897,7 +894,7 @@ bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client)
|
||||
bool ftDataMultiplex::sendChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,bool is_client)
|
||||
{
|
||||
return mDataSend->sendChunkMapRequest(peer_id,hash,is_client);
|
||||
}
|
||||
|
@ -947,13 +944,13 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
if(it4 == mClients.end())
|
||||
continue ;
|
||||
|
||||
std::vector<std::string> sources ;
|
||||
std::vector<RsPeerId> sources ;
|
||||
it4->second.mCreator->getSourcesList(it2->first,sources) ;
|
||||
|
||||
// 1 - go through all sources. Take the oldest one.
|
||||
//
|
||||
|
||||
std::string best_source ;
|
||||
RsPeerId best_source ;
|
||||
time_t oldest_timestamp = now ;
|
||||
|
||||
for(uint32_t i=0;i<sources.size();++i)
|
||||
|
@ -961,7 +958,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Examining source " << sources[i] << std::endl;
|
||||
#endif
|
||||
std::map<std::string,time_t>::const_iterator it3(it2->second.second.find(sources[i])) ;
|
||||
std::map<RsPeerId,time_t>::const_iterator it3(it2->second.second.find(sources[i])) ;
|
||||
|
||||
if(it3 == it2->second.second.end()) // source not found. So this one is surely the oldest one to have been requested.
|
||||
{
|
||||
|
@ -984,7 +981,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Source too recently used! So using it directly." << std::endl;
|
||||
#endif
|
||||
}
|
||||
if(best_source != "")
|
||||
if(!best_source.isNull())
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Asking crc of chunk " << it2->first << " to peer " << best_source << " for hash " << it->first << std::endl;
|
||||
|
@ -1044,7 +1041,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
|||
++sit ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::string& hash)
|
||||
bool ftDataMultiplex::handleSearchRequest(const RsPeerId& peerId, const std::string& hash)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handleSearchRequest(";
|
||||
|
|
|
@ -63,13 +63,13 @@ class ftRequest
|
|||
{
|
||||
public:
|
||||
|
||||
ftRequest(uint32_t type, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data);
|
||||
ftRequest(uint32_t type, const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunk, void *data);
|
||||
|
||||
ftRequest()
|
||||
:mType(0), mSize(0), mOffset(0), mChunk(0), mData(NULL) { return; }
|
||||
|
||||
uint32_t mType;
|
||||
std::string mPeerId;
|
||||
SSLIdType mPeerId;
|
||||
std::string mHash;
|
||||
uint64_t mSize;
|
||||
uint64_t mOffset;
|
||||
|
@ -77,7 +77,7 @@ class ftRequest
|
|||
void *mData;
|
||||
};
|
||||
|
||||
typedef std::map<std::string,time_t> ChunkCheckSumSourceList ;
|
||||
typedef std::map<RsPeerId,time_t> ChunkCheckSumSourceList ;
|
||||
|
||||
class Sha1CacheEntry
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
|
||||
public:
|
||||
|
||||
ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search);
|
||||
ftDataMultiplex(const SSLIdType& ownId, ftDataSend *server, ftSearch *search);
|
||||
|
||||
/* ftController Interface */
|
||||
bool addTransferModule(ftTransferModule *mod, ftFileCreator *f);
|
||||
|
@ -112,13 +112,13 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
/*************** SEND INTERFACE (calls ftDataSend) *******************/
|
||||
|
||||
/* Client Send */
|
||||
bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool sendDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
/* Server Send */
|
||||
bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool sendData(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
|
||||
/* Server/client Send */
|
||||
bool sendChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) ;
|
||||
bool sendChunkMapRequest(const SSLIdType& peerId, const std::string& hash,bool is_client) ;
|
||||
|
||||
|
||||
/* called from a separate thread */
|
||||
|
@ -129,22 +129,22 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
/*************** RECV INTERFACE (provides ftDataRecv) ****************/
|
||||
|
||||
/* Client Recv */
|
||||
virtual bool recvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool recvData(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
/* Server Recv */
|
||||
virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool recvDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
/// Receive a request for a chunk map
|
||||
virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool recvChunkMapRequest(const SSLIdType& peer_id,const std::string& hash,bool is_client) ;
|
||||
/// Receive a chunk map
|
||||
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool recvChunkMap(const SSLIdType& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
|
||||
virtual bool recvSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) ;
|
||||
virtual bool recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ;
|
||||
virtual bool recvSingleChunkCRCRequest(const SSLIdType& peer_id,const std::string& hash,uint32_t chunk_id) ;
|
||||
virtual bool recvSingleChunkCRC(const SSLIdType& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ;
|
||||
|
||||
// Returns the chunk map from the file uploading client. Also initiates a chunk map request if this
|
||||
// map is too old. This supposes that the caller will ask again in a few seconds.
|
||||
//
|
||||
bool getClientChunkMap(const std::string& upload_hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||
bool getClientChunkMap(const std::string& upload_hash,const SSLIdType& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -155,15 +155,15 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
private:
|
||||
|
||||
/* Handling Job Queues */
|
||||
bool handleRecvData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool handleRecvDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool handleSearchRequest(const std::string& peerId, const std::string& hash);
|
||||
bool handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) ;
|
||||
bool handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) ;
|
||||
bool handleRecvChunkCrcRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_id) ;
|
||||
bool handleRecvData(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool handleRecvDataRequest(const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool handleSearchRequest(const SSLIdType& peerId, const std::string& hash);
|
||||
bool handleRecvClientChunkMapRequest(const SSLIdType& peerId, const std::string& hash) ;
|
||||
bool handleRecvServerChunkMapRequest(const SSLIdType& peerId, const std::string& hash) ;
|
||||
bool handleRecvChunkCrcRequest(const SSLIdType& peerId, const std::string& hash,uint32_t chunk_id) ;
|
||||
|
||||
/* We end up doing the actual server job here */
|
||||
bool locked_handleServerRequest(ftFileProvider *provider, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool locked_handleServerRequest(ftFileProvider *provider, const SSLIdType& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
RsMutex dataMtx;
|
||||
|
||||
|
@ -178,7 +178,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
|
||||
ftDataSend *mDataSend;
|
||||
ftSearch *mSearch;
|
||||
std::string mOwnId;
|
||||
RsPeerId mOwnId;
|
||||
|
||||
friend class ftServer;
|
||||
};
|
||||
|
|
|
@ -122,7 +122,7 @@ bool ftFiStore::search(const std::string &hash, FileSearchFlags hintflags, FileI
|
|||
}
|
||||
|
||||
|
||||
ftFiMonitor::ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid,const std::string& config_dir)
|
||||
ftFiMonitor::ftFiMonitor(CacheStrapper *cs,std::string cachedir, const RsPeerId& pid,const std::string& config_dir)
|
||||
:FileIndexMonitor(cs,cachedir, pid,config_dir), p3Config(CONFIG_TYPE_FT_SHARED)
|
||||
{
|
||||
return;
|
||||
|
@ -130,9 +130,9 @@ ftFiMonitor::ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid
|
|||
|
||||
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
return search(hash,hintflags,"",info) ;
|
||||
return search(hash,hintflags,RsPeerId(),info) ;
|
||||
}
|
||||
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id,FileInfo &info) const
|
||||
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, const RsPeerId& peer_id,FileInfo &info) const
|
||||
{
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags;
|
||||
|
|
|
@ -58,11 +58,11 @@ virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo
|
|||
class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
||||
{
|
||||
public:
|
||||
ftFiMonitor(CacheStrapper *cs,std::string cachedir, std::string pid,const std::string& config_dir);
|
||||
ftFiMonitor(CacheStrapper *cs,std::string cachedir, const RsPeerId& pid,const std::string& config_dir);
|
||||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id, FileInfo &info) const;
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, const RsPeerId& peer_id, FileInfo &info) const;
|
||||
|
||||
/* overloaded set dirs enables config indication */
|
||||
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
||||
|
|
|
@ -65,7 +65,7 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::
|
|||
#endif
|
||||
}
|
||||
|
||||
bool ftFileCreator::getFileData(const std::string& 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)
|
||||
{
|
||||
// Only send the data if we actually have it.
|
||||
//
|
||||
|
@ -243,7 +243,7 @@ void ftFileCreator::removeInactiveChunks()
|
|||
#endif
|
||||
}
|
||||
|
||||
void ftFileCreator::removeFileSource(const std::string& peer_id)
|
||||
void ftFileCreator::removeFileSource(const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
#ifdef FILE_DEBUG
|
||||
|
@ -456,7 +456,7 @@ void ftFileCreator::setChunkStrategy(FileChunksInfo::ChunkStrategy s)
|
|||
* But can return size = 0, if we are still waiting for the data.
|
||||
*/
|
||||
|
||||
bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t& size,bool& source_chunk_map_needed)
|
||||
bool ftFileCreator::getMissingChunk(const RsPeerId& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t& size,bool& source_chunk_map_needed)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
#ifdef FILE_DEBUG
|
||||
|
@ -559,7 +559,7 @@ bool ftFileCreator::locked_printChunkMap()
|
|||
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)
|
||||
for(std::map<RsPeerId,ZeroInitCounter>::const_iterator it(mChunksPerPeer.begin());it!=mChunksPerPeer.end();++it)
|
||||
std::cerr << " " << it->first << "\t: " << it->second.cnt << std::endl;
|
||||
|
||||
return true;
|
||||
|
@ -586,14 +586,14 @@ void ftFileCreator::getAvailabilityMap(CompressedChunkMap& map)
|
|||
chunkMap.getAvailabilityMap(map) ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::sourceIsComplete(const std::string& peer_id)
|
||||
bool ftFileCreator::sourceIsComplete(const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
return chunkMap.getSourceChunksInfo(peer_id)->is_full ;
|
||||
}
|
||||
|
||||
void ftFileCreator::setSourceMap(const std::string& peer_id,const CompressedChunkMap& compressed_map)
|
||||
void ftFileCreator::setSourceMap(const RsPeerId& peer_id,const CompressedChunkMap& compressed_map)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -646,7 +646,7 @@ void ftFileCreator::forceCheck()
|
|||
chunkMap.forceCheck();
|
||||
}
|
||||
|
||||
void ftFileCreator::getSourcesList(uint32_t chunk_num,std::vector<std::string>& sources)
|
||||
void ftFileCreator::getSourcesList(uint32_t chunk_num,std::vector<RsPeerId>& sources)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class ftFileCreator: public ftFileProvider
|
|||
~ftFileCreator();
|
||||
|
||||
/* overloaded from FileProvider */
|
||||
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
bool finished() ;
|
||||
uint64_t getRecvd();
|
||||
|
||||
|
@ -91,7 +91,7 @@ class ftFileCreator: public ftFileProvider
|
|||
// - no chunkmap info is available. In such a case, the chunk info is irrelevant and false is returned.
|
||||
// - the chunk info is too old. In tis case, true is returned, and the chunks info can be used.
|
||||
//
|
||||
bool getMissingChunk(const std::string& peer_id,uint32_t size_hint,uint64_t& offset, uint32_t& size,bool& is_chunk_map_too_old);
|
||||
bool getMissingChunk(const SSLIdType& peer_id,uint32_t size_hint,uint64_t& offset, uint32_t& size,bool& is_chunk_map_too_old);
|
||||
|
||||
// Takes care of purging any inactive chunks. This should be called regularly, because some peers may disconnect
|
||||
// and let inactive chunks not finished.
|
||||
|
@ -99,11 +99,11 @@ class ftFileCreator: public ftFileProvider
|
|||
void removeInactiveChunks() ;
|
||||
|
||||
// removes the designated file source from the chunkmap.
|
||||
void removeFileSource(const std::string& peer_id) ;
|
||||
void removeFileSource(const SSLIdType& peer_id) ;
|
||||
|
||||
// Get all available sources for this chunk
|
||||
//
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<std::string>& sources) ;
|
||||
void getSourcesList(uint32_t chunk_number,std::vector<SSLIdType>& sources) ;
|
||||
|
||||
// Returns resets the time stamp of the last data receive.
|
||||
time_t lastRecvTimeStamp() ;
|
||||
|
@ -124,11 +124,11 @@ class ftFileCreator: public ftFileProvider
|
|||
|
||||
// This is called when receiving the availability map from a source peer, for the file being handled.
|
||||
//
|
||||
void setSourceMap(const std::string& peer_id,const CompressedChunkMap& map) ;
|
||||
void setSourceMap(const SSLIdType& peer_id,const CompressedChunkMap& map) ;
|
||||
|
||||
// Returns true id the given file source is complete.
|
||||
//
|
||||
bool sourceIsComplete(const std::string& peer_id) ;
|
||||
bool sourceIsComplete(const SSLIdType& peer_id) ;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -146,7 +146,7 @@ class ftFileCreator: public ftFileProvider
|
|||
uint64_t mEnd;
|
||||
|
||||
std::map<uint64_t, ftChunk> mChunks;
|
||||
std::map<std::string,ZeroInitCounter> mChunksPerPeer ;
|
||||
std::map<SSLIdType,ZeroInitCounter> mChunksPerPeer ;
|
||||
|
||||
ChunkMap chunkMap ;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ bool ftFileProvider::FileDetails(FileInfo &info)
|
|||
info.peers.clear() ;
|
||||
float total_transfer_rate = 0.0f ;
|
||||
|
||||
for(std::map<std::string,PeerUploadInfo>::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it)
|
||||
for(std::map<SSLIdType,PeerUploadInfo>::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it)
|
||||
{
|
||||
TransferInfo inf ;
|
||||
inf.peerId = it->first ;
|
||||
|
@ -109,13 +109,13 @@ bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration)
|
|||
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": examining peers." << std::endl ;
|
||||
#endif
|
||||
bool ret = true ;
|
||||
for(std::map<std::string,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
|
||||
for(std::map<SSLIdType,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
|
||||
if( (*it).second.lastTS+max_duration < (uint32_t)now)
|
||||
{
|
||||
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " is too old. Removing." << std::endl ;
|
||||
#endif
|
||||
std::map<std::string,PeerUploadInfo>::iterator tmp = it ;
|
||||
std::map<SSLIdType,PeerUploadInfo>::iterator tmp = it ;
|
||||
++tmp ;
|
||||
uploading_peers.erase(it) ;
|
||||
it=tmp ;
|
||||
|
@ -139,7 +139,7 @@ void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap)
|
|||
}
|
||||
|
||||
|
||||
bool ftFileProvider::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
bool ftFileProvider::getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
{
|
||||
/* dodgey checking outside of mutex...
|
||||
* much check again inside FileAttrs().
|
||||
|
@ -250,7 +250,7 @@ void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_
|
|||
total_size += req_size ;
|
||||
}
|
||||
|
||||
void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap)
|
||||
void ftFileProvider::setClientMap(const SSLIdType& peer_id,const CompressedChunkMap& cmap)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -259,7 +259,7 @@ void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChu
|
|||
uploading_peers[peer_id].client_chunk_map_stamp = time(NULL) ;
|
||||
}
|
||||
|
||||
void ftFileProvider::getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
|
||||
void ftFileProvider::getClientMap(const SSLIdType& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class ftFileProvider
|
|||
ftFileProvider(const std::string& path, uint64_t size, const std::string& hash);
|
||||
virtual ~ftFileProvider();
|
||||
|
||||
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool getFileData(const SSLIdType& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool FileDetails(FileInfo &info);
|
||||
std::string getHash();
|
||||
uint64_t getFileSize();
|
||||
|
@ -54,8 +54,8 @@ class ftFileProvider
|
|||
virtual void getAvailabilityMap(CompressedChunkMap& cmap) ;
|
||||
|
||||
// a ftFileProvider feeds a distant peer. To display what the peers already has, we need to store/read this info.
|
||||
void getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ;
|
||||
void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ;
|
||||
void getClientMap(const RsPeerId& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ;
|
||||
void setClientMap(const RsPeerId& peer_id,const CompressedChunkMap& cmap) ;
|
||||
|
||||
// Removes inactive peers from the client list. Returns true if all peers have been removed.
|
||||
//
|
||||
|
@ -100,7 +100,7 @@ class ftFileProvider
|
|||
|
||||
// Contains statistics (speed, peer name, etc.) of all uploading peers for that file.
|
||||
//
|
||||
std::map<std::string,PeerUploadInfo> uploading_peers ;
|
||||
std::map<RsPeerId,PeerUploadInfo> uploading_peers ;
|
||||
|
||||
/*
|
||||
* Mutex Required for stuff below
|
||||
|
|
|
@ -102,12 +102,14 @@ void ftServer::addConfigComponents(p3ConfigMgr */*mgr*/)
|
|||
/* NOT SURE ABOUT THIS ONE */
|
||||
}
|
||||
|
||||
std::string ftServer::OwnId()
|
||||
const RsPeerId& ftServer::OwnId()
|
||||
{
|
||||
std::string ownId;
|
||||
static RsPeerId null_id ;
|
||||
|
||||
if (mLinkMgr)
|
||||
ownId = mLinkMgr->getOwnId();
|
||||
return ownId;
|
||||
return mLinkMgr->getOwnId();
|
||||
else
|
||||
return null_id ;
|
||||
}
|
||||
|
||||
/* Final Setup (once everything is assigned) */
|
||||
|
@ -117,7 +119,7 @@ void ftServer::SetupFtServer()
|
|||
/* setup FiStore/Monitor */
|
||||
std::string localcachedir = mConfigPath + "/cache/local";
|
||||
std::string remotecachedir = mConfigPath + "/cache/remote";
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
RsPeerId ownId = mLinkMgr->getOwnId();
|
||||
|
||||
/* search/extras List */
|
||||
mFtExtra = new ftExtraList();
|
||||
|
@ -264,7 +266,7 @@ bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
|||
return mFtController->alreadyHaveFile(hash, info);
|
||||
}
|
||||
|
||||
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds)
|
||||
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds)
|
||||
{
|
||||
std::string error_string ;
|
||||
|
||||
|
@ -407,7 +409,7 @@ bool ftServer::FileDownloads(std::list<std::string> &hashs)
|
|||
//return mFtDataplex->FileDownloads(hashs);
|
||||
}
|
||||
|
||||
bool ftServer::FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& cmap)
|
||||
bool ftServer::FileUploadChunksDetails(const std::string& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap)
|
||||
{
|
||||
return mFtDataplex->getClientChunkMap(hash,peer_id,cmap);
|
||||
}
|
||||
|
@ -481,7 +483,7 @@ void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualP
|
|||
mFtController->removeFileSource(hash,virtual_peer_id) ;
|
||||
}
|
||||
|
||||
bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& peer_id)
|
||||
bool ftServer::handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id)
|
||||
{
|
||||
FileInfo info ;
|
||||
bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info);
|
||||
|
@ -545,7 +547,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
|||
/******************** Directory Listing ************************/
|
||||
/***************************************************************/
|
||||
|
||||
int ftServer::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details)
|
||||
int ftServer::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::RequestDirDetails(uid:" << uid;
|
||||
|
@ -610,12 +612,12 @@ uint32_t ftServer::getType(void *ref, FileSearchFlags flags)
|
|||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchKeywords(keywords, results,flags,"");
|
||||
return mFiMon->SearchKeywords(keywords, results,flags,RsPeerId());
|
||||
else
|
||||
return mFiStore->SearchKeywords(keywords, results,flags);
|
||||
return 0 ;
|
||||
}
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id)
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::SearchKeywords()";
|
||||
|
@ -637,12 +639,12 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetai
|
|||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,"") ;
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,RsPeerId()) ;
|
||||
else
|
||||
return mFiStore->searchBoolExp(exp, results);
|
||||
return 0 ;
|
||||
}
|
||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id)
|
||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ;
|
||||
|
@ -870,7 +872,7 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
|
|||
/***************************************************************/
|
||||
|
||||
/* Client Send */
|
||||
bool ftServer::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
bool ftServer::sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl;
|
||||
|
@ -908,7 +910,7 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client)
|
||||
bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const std::string& hash,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
|
@ -937,7 +939,7 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,const CompressedChunkMap& map,bool is_client)
|
||||
bool ftServer::sendChunkMap(const RsPeerId& peerId,const std::string& hash,const CompressedChunkMap& map,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
|
@ -968,7 +970,7 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::string& hash,uint32_t chunk_number)
|
||||
bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const std::string& hash,uint32_t chunk_number)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
|
||||
|
@ -999,7 +1001,7 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
|
||||
|
@ -1033,7 +1035,7 @@ bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& h
|
|||
}
|
||||
|
||||
/* Server Send */
|
||||
bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
bool ftServer::sendData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
|
@ -1131,7 +1133,7 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
//
|
||||
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
||||
const std::string& hash,
|
||||
const std::string& virtual_peer_id,
|
||||
const RsPeerId& virtual_peer_id,
|
||||
RsTurtleGenericTunnelItem::Direction direction)
|
||||
{
|
||||
switch(i->PacketSubType())
|
||||
|
|
|
@ -94,7 +94,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
virtual CacheStrapper *getCacheStrapper();
|
||||
virtual CacheTransfer *getCacheTransfer();
|
||||
|
||||
std::string OwnId();
|
||||
const RsPeerId& OwnId();
|
||||
|
||||
/* Final Setup (once everything is assigned) */
|
||||
void SetupFtServer() ;
|
||||
|
@ -106,8 +106,8 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
|
||||
// Implements RsTurtleClientService
|
||||
//
|
||||
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
virtual bool handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
|
||||
|
||||
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
|
||||
|
@ -130,7 +130,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
* Control of Downloads
|
||||
***/
|
||||
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds);
|
||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds);
|
||||
virtual bool FileCancel(const std::string& hash);
|
||||
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
||||
virtual bool FileClearCompleted();
|
||||
|
@ -163,7 +163,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||
virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||
virtual bool FileUploadChunksDetails(const std::string& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
|
||||
/***
|
||||
|
@ -179,14 +179,14 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
/***
|
||||
* Directory Listing / Search Interface
|
||||
***/
|
||||
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
||||
virtual int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details);
|
||||
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
|
||||
virtual uint32_t getType(void *ref,FileSearchFlags flags) ;
|
||||
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||
|
||||
/***
|
||||
* Utility Functions
|
||||
|
@ -230,12 +230,12 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
/*************** Data Transfer Interface ***********************/
|
||||
/***************************************************************/
|
||||
public:
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
virtual bool sendData(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const RsPeerId& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
|
||||
/*************** Internal Transfer Fns *************************/
|
||||
virtual int tick();
|
||||
|
|
|
@ -103,7 +103,7 @@ ftTransferModule::~ftTransferModule()
|
|||
}
|
||||
|
||||
|
||||
bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
||||
bool ftTransferModule::setFileSources(const std::list<SSLIdType>& peerIds)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
|
@ -114,7 +114,7 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
|||
std::cerr << " List of peers: " ;
|
||||
#endif
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
std::list<SSLIdType>::const_iterator it;
|
||||
for(it = peerIds.begin(); it != peerIds.end(); it++)
|
||||
{
|
||||
|
||||
|
@ -123,7 +123,7 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
|||
#endif
|
||||
|
||||
peerInfo pInfo(*it);
|
||||
mFileSources.insert(std::pair<std::string,peerInfo>(*it,pInfo));
|
||||
mFileSources.insert(std::pair<SSLIdType,peerInfo>(*it,pInfo));
|
||||
}
|
||||
|
||||
#ifdef FT_DEBUG
|
||||
|
@ -133,10 +133,10 @@ bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
|
||||
bool ftTransferModule::getFileSources(std::list<SSLIdType> &peerIds)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator it;
|
||||
std::map<SSLIdType,peerInfo>::iterator it;
|
||||
for(it = mFileSources.begin(); it != mFileSources.end(); it++)
|
||||
{
|
||||
peerIds.push_back(it->first);
|
||||
|
@ -144,17 +144,17 @@ bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftTransferModule::addFileSource(const std::string& peerId)
|
||||
bool ftTransferModule::addFileSource(const SSLIdType& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end())
|
||||
{
|
||||
/* add in new source */
|
||||
peerInfo pInfo(peerId);
|
||||
mFileSources.insert(std::pair<std::string,peerInfo>(peerId,pInfo));
|
||||
mFileSources.insert(std::pair<SSLIdType,peerInfo>(peerId,pInfo));
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
mMultiplexor->sendChunkMapRequest(peerId, mHash,false) ;
|
||||
|
@ -177,10 +177,10 @@ bool ftTransferModule::addFileSource(const std::string& peerId)
|
|||
}
|
||||
}
|
||||
|
||||
bool ftTransferModule::removeFileSource(const std::string& peerId)
|
||||
bool ftTransferModule::removeFileSource(const SSLIdType& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit != mFileSources.end())
|
||||
|
@ -199,7 +199,7 @@ bool ftTransferModule::removeFileSource(const std::string& peerId)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate)
|
||||
bool ftTransferModule::setPeerState(const SSLIdType& peerId,uint32_t state,uint32_t maxRate)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
#ifdef FT_DEBUG
|
||||
|
@ -209,7 +209,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
|
|||
std::cerr << " maxRate: " << maxRate << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end())
|
||||
|
@ -229,7 +229,7 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
|
|||
// Start it off at zero....
|
||||
// (mit->second).actualRate=maxRate; /* should give big kick in right direction */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<SSLIdType>::iterator it;
|
||||
it = std::find(mOnlinePeers.begin(), mOnlinePeers.end(), peerId);
|
||||
|
||||
if (state!=PQIPEER_NOT_ONLINE)
|
||||
|
@ -247,10 +247,10 @@ bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uin
|
|||
}
|
||||
|
||||
|
||||
bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate)
|
||||
bool ftTransferModule::getPeerState(const SSLIdType& peerId,uint32_t &state,uint32_t &tfRate)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end()) return false;
|
||||
|
@ -267,10 +267,10 @@ bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,ui
|
|||
return true;
|
||||
}
|
||||
|
||||
uint32_t ftTransferModule::getDataRate(const std::string& peerId)
|
||||
uint32_t ftTransferModule::getDataRate(const SSLIdType& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
if (mit == mFileSources.end())
|
||||
{
|
||||
|
@ -296,7 +296,7 @@ time_t ftTransferModule::lastActvTimeStamp()
|
|||
}
|
||||
|
||||
//interface to client module
|
||||
bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data)
|
||||
bool ftTransferModule::recvFileData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size, void *data)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
#ifdef FT_DEBUG
|
||||
|
@ -310,7 +310,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
|
|||
|
||||
bool ok = false;
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
mit = mFileSources.find(peerId);
|
||||
|
||||
if (mit == mFileSources.end())
|
||||
|
@ -332,7 +332,7 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
|
|||
return ok;
|
||||
}
|
||||
|
||||
void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size)
|
||||
void ftTransferModule::locked_requestData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size)
|
||||
{
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::requestData()";
|
||||
|
@ -347,7 +347,7 @@ void ftTransferModule::locked_requestData(const std::string& peerId, uint64_t of
|
|||
mMultiplexor->sendDataRequest(peerId, mHash, mSize, offset,chunk_size);
|
||||
}
|
||||
|
||||
bool ftTransferModule::locked_getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size)
|
||||
bool ftTransferModule::locked_getChunk(const SSLIdType& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size)
|
||||
{
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::locked_getChunk()";
|
||||
|
@ -427,7 +427,7 @@ bool ftTransferModule::queryInactive()
|
|||
if (mFileStatus.stat == ftFileStatus::PQIFILE_CHECKING)
|
||||
return false ;
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
for(mit = mFileSources.begin(); mit != mFileSources.end(); mit++)
|
||||
{
|
||||
locked_tickPeerTransfer(mit->second);
|
||||
|
@ -496,7 +496,7 @@ int ftTransferModule::tick()
|
|||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "Peers: ";
|
||||
std::map<std::string,peerInfo>::iterator it;
|
||||
std::map<SSLIdType,peerInfo>::iterator it;
|
||||
for(it = mFileSources.begin(); it != mFileSources.end(); it++)
|
||||
{
|
||||
std::cerr << " " << it->first;
|
||||
|
@ -645,7 +645,7 @@ void ftTransferModule::adjustSpeed()
|
|||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<SSLIdType,peerInfo>::iterator mit;
|
||||
|
||||
|
||||
actualRate = 0;
|
||||
|
|
|
@ -56,7 +56,7 @@ class HashThread ;
|
|||
class peerInfo
|
||||
{
|
||||
public:
|
||||
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
||||
peerInfo(const SSLIdType& peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
||||
lastTS(0),
|
||||
recvTS(0), lastTransfers(0), nResets(0),
|
||||
rtt(0), rttActive(false), rttStart(0), rttOffset(0),
|
||||
|
@ -64,7 +64,7 @@ public:
|
|||
{
|
||||
return;
|
||||
}
|
||||
peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in):
|
||||
peerInfo(const SSLIdType& peerId_in,uint32_t state_in,uint32_t maxRate_in):
|
||||
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
|
||||
lastTS(0),
|
||||
recvTS(0), lastTransfers(0), nResets(0),
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
{
|
||||
return;
|
||||
}
|
||||
std::string peerId;
|
||||
SSLIdType peerId;
|
||||
uint32_t state;
|
||||
double desiredRate;
|
||||
double actualRate;
|
||||
|
@ -124,13 +124,13 @@ public:
|
|||
~ftTransferModule();
|
||||
|
||||
//interface to download controller
|
||||
bool setFileSources(const std::list<std::string>& peerIds);
|
||||
bool addFileSource(const std::string& peerId);
|
||||
bool removeFileSource(const std::string& peerId);
|
||||
bool setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
|
||||
bool getFileSources(std::list<std::string> &peerIds);
|
||||
bool getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate);
|
||||
uint32_t getDataRate(const std::string& peerId);
|
||||
bool setFileSources(const std::list<SSLIdType>& peerIds);
|
||||
bool addFileSource(const SSLIdType& peerId);
|
||||
bool removeFileSource(const SSLIdType& peerId);
|
||||
bool setPeerState(const SSLIdType& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
|
||||
bool getFileSources(std::list<SSLIdType> &peerIds);
|
||||
bool getPeerState(const SSLIdType& peerId,uint32_t &state,uint32_t &tfRate);
|
||||
uint32_t getDataRate(const SSLIdType& peerId);
|
||||
bool cancelTransfer();
|
||||
bool cancelFileTransferUpward();
|
||||
bool completeFileTransfer();
|
||||
|
@ -138,11 +138,11 @@ public:
|
|||
void forceCheck() ;
|
||||
|
||||
//interface to multiplex module
|
||||
bool recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data);
|
||||
void locked_requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size);
|
||||
bool recvFileData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size, void *data);
|
||||
void locked_requestData(const SSLIdType& peerId, uint64_t offset, uint32_t chunk_size);
|
||||
|
||||
//interface to file creator
|
||||
bool locked_getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size);
|
||||
bool locked_getChunk(const SSLIdType& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size);
|
||||
bool locked_storeData(uint64_t offset, uint32_t chunk_size, void *data);
|
||||
|
||||
int tick();
|
||||
|
@ -180,8 +180,8 @@ private:
|
|||
|
||||
RsMutex tfMtx; /* below is mutex protected */
|
||||
|
||||
std::list<std::string> mOnlinePeers;
|
||||
std::map<std::string,peerInfo> mFileSources;
|
||||
std::list<SSLIdType> mOnlinePeers;
|
||||
std::map<SSLIdType,peerInfo> mFileSources;
|
||||
|
||||
uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete, 3: checking hash, 4: checking chunks
|
||||
double desiredRate;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue