mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
merge of branch v0.6-idclean 7180
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7815efb16f
commit
0f29d28b1b
397 changed files with 6503 additions and 5702 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.
|
||||
|
|
|
@ -89,7 +89,7 @@ ftFileControl::ftFileControl()
|
|||
|
||||
ftFileControl::ftFileControl(std::string fname,
|
||||
std::string tmppath, std::string dest,
|
||||
uint64_t size, std::string hash, TransferRequestFlags flags,
|
||||
uint64_t size, const RsFileHash &hash, TransferRequestFlags flags,
|
||||
ftFileCreator *fc, ftTransferModule *tm)
|
||||
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
||||
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||
|
@ -124,11 +124,11 @@ void ftController::setFtSearchNExtra(ftSearch *search, ftExtraList *list)
|
|||
mExtraList = list;
|
||||
}
|
||||
|
||||
bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
||||
bool ftController::getFileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash) ;
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
{
|
||||
|
@ -161,11 +161,11 @@ 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 RsFileHash& hash,const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
//#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||
|
@ -184,11 +184,11 @@ 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 RsFileHash& hash,const RsPeerId& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||
|
@ -245,7 +245,7 @@ void ftController::run()
|
|||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
it->second->mCreator->removeInactiveChunks() ;
|
||||
|
||||
last_clean_time = now ;
|
||||
|
@ -263,7 +263,7 @@ void ftController::run()
|
|||
tickTransfers() ;
|
||||
|
||||
{
|
||||
std::list<std::string> files_to_complete ;
|
||||
std::list<RsFileHash> files_to_complete ;
|
||||
|
||||
{
|
||||
RsStackMutex stack2(doneMutex);
|
||||
|
@ -271,7 +271,7 @@ void ftController::run()
|
|||
mDone.clear();
|
||||
}
|
||||
|
||||
for(std::list<std::string>::iterator it(files_to_complete.begin()); it != files_to_complete.end(); ++it)
|
||||
for(std::list<RsFileHash>::iterator it(files_to_complete.begin()); it != files_to_complete.end(); ++it)
|
||||
completeFile(*it);
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ void ftController::searchForDirectSources()
|
|||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
|
||||
if(! (it->second->mFlags & RS_FILE_REQ_CACHE))
|
||||
{
|
||||
|
@ -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 ));
|
||||
}
|
||||
|
@ -310,16 +310,16 @@ void ftController::tickTransfers()
|
|||
#endif
|
||||
// Collect all non queued files.
|
||||
//
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
|
||||
it->second->mTransfer->tick() ;
|
||||
}
|
||||
|
||||
bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
||||
bool ftController::getPriority(const RsFileHash& hash,DwlSpeed& p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
{
|
||||
|
@ -330,11 +330,11 @@ bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
|||
return false ;
|
||||
}
|
||||
|
||||
void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||
void ftController::setPriority(const RsFileHash& hash,DwlSpeed p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
it->second->mTransfer->setDownloadPriority(p) ;
|
||||
|
@ -342,13 +342,13 @@ void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
|||
|
||||
void ftController::cleanCacheDownloads()
|
||||
{
|
||||
std::vector<std::string> toCancel ;
|
||||
std::vector<RsFileHash> toCancel ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
if (((it->second)->mFlags & RS_FILE_REQ_CACHE) && it->second->mState != ftFileControl::DOWNLOADING)
|
||||
// check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER
|
||||
{
|
||||
|
@ -423,7 +423,7 @@ void ftController::checkDownloadQueue()
|
|||
time_t now = time(NULL) ;
|
||||
uint32_t nb_moved = 0 ; // don't move more files than the size of the queue.
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it)
|
||||
for(std::map<RsFileHash,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it)
|
||||
if( it->second->mState != ftFileControl::QUEUED
|
||||
&& (it->second->mState == ftFileControl::PAUSED
|
||||
|| now > it->second->mTransfer->lastActvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED))
|
||||
|
@ -557,11 +557,11 @@ uint32_t ftController::getQueueSize()
|
|||
return _max_active_downloads ;
|
||||
}
|
||||
|
||||
void ftController::moveInQueue(const std::string& hash,QueueMove mv)
|
||||
void ftController::moveInQueue(const RsFileHash& hash,QueueMove mv)
|
||||
{
|
||||
RsStackMutex mtx(ctrlMutex) ;
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it == mDownloads.end())
|
||||
{
|
||||
|
@ -658,7 +658,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
|||
}
|
||||
}
|
||||
|
||||
bool ftController::FlagFileComplete(std::string hash)
|
||||
bool ftController::FlagFileComplete(const RsFileHash& hash)
|
||||
{
|
||||
RsStackMutex stack2(doneMutex);
|
||||
mDone.push_back(hash);
|
||||
|
@ -780,7 +780,7 @@ bool ftController::copyFile(const std::string& source,const std::string& dest)
|
|||
|
||||
|
||||
|
||||
bool ftController::completeFile(std::string hash)
|
||||
bool ftController::completeFile(const RsFileHash& hash)
|
||||
{
|
||||
/* variables... so we can drop mutex later */
|
||||
std::string path;
|
||||
|
@ -799,7 +799,7 @@ bool ftController::completeFile(std::string hash)
|
|||
std::cerr << "ftController:completeFile(" << hash << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
std::map<std::string, ftFileControl*>::iterator it(mDownloads.find(hash));
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it(mDownloads.find(hash));
|
||||
|
||||
if (it == mDownloads.end())
|
||||
{
|
||||
|
@ -840,7 +840,7 @@ bool ftController::completeFile(std::string hash)
|
|||
/* done - cleanup */
|
||||
|
||||
// (csoler) I'm copying this because "delete fc->mTransfer" deletes the hash string!
|
||||
std::string hash_to_suppress(fc->mTransfer->hash());
|
||||
RsFileHash hash_to_suppress(fc->mTransfer->hash());
|
||||
|
||||
// This should be done that early, because once the file creator is
|
||||
// deleted, it should not be accessed by the data multiplex anymore!
|
||||
|
@ -965,9 +965,9 @@ bool ftController::completeFile(std::string hash)
|
|||
|
||||
/* Notify GUI */
|
||||
if ((flags & RS_FILE_REQ_CACHE) == 0) {
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash, name, "");
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash.toStdString(), name, "");
|
||||
|
||||
RsServer::notify()->notifyDownloadComplete(hash);
|
||||
RsServer::notify()->notifyDownloadComplete(hash.toStdString());
|
||||
RsServer::notify()->notifyDownloadCompleteCount(completeCount);
|
||||
|
||||
rsFiles->ForceDirectoryCheck() ;
|
||||
|
@ -1019,12 +1019,12 @@ bool ftController::handleAPendingRequest()
|
|||
//
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string,RsFileTransfer*>::iterator it(mPendingChunkMaps.find(req.mHash)) ;
|
||||
std::map<RsFileHash,RsFileTransfer*>::iterator it(mPendingChunkMaps.find(req.mHash)) ;
|
||||
|
||||
if(it != mPendingChunkMaps.end())
|
||||
{
|
||||
RsFileTransfer *rsft = it->second ;
|
||||
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
|
||||
if((fit==mDownloads.end() || (fit->second)->mCreator == NULL))
|
||||
{
|
||||
|
@ -1055,7 +1055,7 @@ bool ftController::handleAPendingRequest()
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||
bool ftController::alreadyHaveFile(const RsFileHash& hash, FileInfo &info)
|
||||
{
|
||||
// check for downloads
|
||||
if (FileDetails(hash, info) && (info.downloadStatus == FT_STATE_COMPLETE))
|
||||
|
@ -1068,11 +1068,11 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
|||
return false ;
|
||||
}
|
||||
|
||||
bool ftController::FileRequest(const std::string& fname, const std::string& hash,
|
||||
bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &_srcIds, uint16_t state)
|
||||
const std::list<RsPeerId> &_srcIds, uint16_t state)
|
||||
{
|
||||
std::list<std::string> srcIds(_srcIds) ;
|
||||
std::list<RsPeerId> 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<RsPeerId>::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<RsPeerId>::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<RsPeerId>::const_iterator it;
|
||||
std::list<TransferInfo>::const_iterator pit;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
|
@ -1174,7 +1174,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::const_iterator dit = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::const_iterator dit = mDownloads.find(hash);
|
||||
|
||||
if (dit != mDownloads.end())
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -1268,7 +1268,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
savepath = mPartialsPath + "/" + hash;
|
||||
savepath = mPartialsPath + "/" + hash.toStdString();
|
||||
destination = dest + "/" + fname;
|
||||
|
||||
/* if no destpath - send to download directory */
|
||||
|
@ -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 RsPeerId& id, uint32_t maxrate, bool online)
|
||||
{
|
||||
if (id == mLinkMgr->getOwnId())
|
||||
{
|
||||
|
@ -1363,9 +1363,9 @@ bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t
|
|||
}
|
||||
|
||||
|
||||
bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s)
|
||||
bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s)
|
||||
{
|
||||
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
std::map<RsFileHash,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
if (mit==mDownloads.end())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
|
@ -1378,7 +1378,7 @@ bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::Chun
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftController::FileCancel(const std::string& hash)
|
||||
bool ftController::FileCancel(const RsFileHash& hash)
|
||||
{
|
||||
rsTurtle->stopMonitoringTunnels(hash) ;
|
||||
|
||||
|
@ -1390,7 +1390,7 @@ bool ftController::FileCancel(const std::string& hash)
|
|||
{
|
||||
RsStackMutex mtx(ctrlMutex) ;
|
||||
|
||||
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
std::map<RsFileHash,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
if (mit==mDownloads.end())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
|
@ -1461,7 +1461,7 @@ bool ftController::FileCancel(const std::string& hash)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftController::FileControl(const std::string& hash, uint32_t flags)
|
||||
bool ftController::FileControl(const RsFileHash& hash, uint32_t flags)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::FileControl(" << hash << ",";
|
||||
|
@ -1470,7 +1470,7 @@ bool ftController::FileControl(const std::string& hash, uint32_t flags)
|
|||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
/*check if the file in the download map*/
|
||||
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
std::map<RsFileHash,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||
if (mit==mDownloads.end())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
|
@ -1513,7 +1513,7 @@ bool ftController::FileClearCompleted()
|
|||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<std::string, ftFileControl*>::iterator it(mCompleted.begin());it!=mCompleted.end();++it)
|
||||
for(std::map<RsFileHash, ftFileControl*>::iterator it(mCompleted.begin());it!=mCompleted.end();++it)
|
||||
delete it->second ;
|
||||
|
||||
mCompleted.clear();
|
||||
|
@ -1527,11 +1527,11 @@ bool ftController::FileClearCompleted()
|
|||
}
|
||||
|
||||
/* get Details of File Transfers */
|
||||
bool ftController::FileDownloads(std::list<std::string> &hashs)
|
||||
bool ftController::FileDownloads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator it;
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it;
|
||||
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
||||
{
|
||||
hashs.push_back(it->second->mHash);
|
||||
|
@ -1611,7 +1611,7 @@ bool ftController::setPartialsDirectory(std::string path)
|
|||
|
||||
#if 0 /*** FIX ME !!!**************/
|
||||
/* move all existing files! */
|
||||
std::map<std::string, ftFileControl>::iterator it;
|
||||
std::map<RsFileHash, ftFileControl>::iterator it;
|
||||
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
||||
{
|
||||
(it->second).mCreator->changePartialDirectory(mPartialPath);
|
||||
|
@ -1638,10 +1638,10 @@ std::string ftController::getPartialsDirectory()
|
|||
return mPartialsPath;
|
||||
}
|
||||
|
||||
bool ftController::setDestinationDirectory(const std::string& hash,const std::string& dest_dir)
|
||||
bool ftController::setDestinationDirectory(const RsFileHash& hash,const std::string& dest_dir)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
if (it == mDownloads.end())
|
||||
return false;
|
||||
|
@ -1654,10 +1654,10 @@ bool ftController::setDestinationDirectory(const std::string& hash,const std::st
|
|||
|
||||
return true ;
|
||||
}
|
||||
bool ftController::setDestinationName(const std::string& hash,const std::string& dest_name)
|
||||
bool ftController::setDestinationName(const RsFileHash& hash,const std::string& dest_name)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
|
||||
if (it == mDownloads.end())
|
||||
return false;
|
||||
|
@ -1675,12 +1675,12 @@ bool ftController::setDestinationName(const std::string& hash,const std::string&
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
||||
bool ftController::FileDetails(const RsFileHash &hash, FileInfo &info)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
bool completed = false;
|
||||
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||
if (it == mDownloads.end())
|
||||
{
|
||||
/* search completed files too */
|
||||
|
@ -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<RsPeerId> peerIds;
|
||||
std::list<RsPeerId>::iterator pit;
|
||||
|
||||
if (!completed)
|
||||
{
|
||||
|
@ -1821,7 +1821,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||
uint32_t rate = FT_CNTRL_STANDARD_RATE;
|
||||
|
||||
/* add online to all downloads */
|
||||
std::map<std::string, ftFileControl*>::iterator it;
|
||||
std::map<RsFileHash, ftFileControl*>::iterator it;
|
||||
std::list<pqipeer>::const_iterator pit;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
|
@ -1913,7 +1913,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||
}
|
||||
|
||||
/* Cache Interface */
|
||||
bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
bool ftController::RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::RequestCacheFile(" << id << ",";
|
||||
|
@ -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<RsPeerId> ids;
|
||||
ids.push_back(id);
|
||||
|
||||
FileInfo info ;
|
||||
|
@ -1937,7 +1937,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
|
|||
std::cerr << "Copying it !!" << std::endl ;
|
||||
#endif
|
||||
|
||||
if(info.size > 0 && copyFile(info.path,path+"/"+hash))
|
||||
if(info.size > 0 && copyFile(info.path,path+"/"+hash.toStdString()))
|
||||
{
|
||||
CompletedCache(hash);
|
||||
return true ;
|
||||
|
@ -1946,13 +1946,13 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
|
|||
return false ;
|
||||
}
|
||||
|
||||
FileRequest(hash, hash, size, path, RS_FILE_REQ_CACHE | RS_FILE_REQ_NO_SEARCH, ids);
|
||||
FileRequest(hash.toStdString(), hash, size, path, RS_FILE_REQ_CACHE | RS_FILE_REQ_NO_SEARCH, ids);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ftController::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
bool ftController::CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
|
||||
{
|
||||
std::cerr << "ftController::CancelCacheFile(" << id << ",";
|
||||
std::cerr << path << "," << hash << "," << size << ")";
|
||||
|
@ -1994,7 +1994,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
/* create a key/value set for most of the parameters */
|
||||
std::map<std::string, std::string> configMap;
|
||||
std::map<std::string, std::string>::iterator mit;
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsFileHash>::iterator it;
|
||||
|
||||
/* basic control parameters */
|
||||
std::string s ;
|
||||
|
@ -2043,7 +2043,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
|
||||
|
||||
/* get Details of File Transfers */
|
||||
std::list<std::string> hashs;
|
||||
std::list<RsFileHash> hashs;
|
||||
FileDownloads(hashs);
|
||||
|
||||
for(it = hashs.begin(); it != hashs.end(); it++)
|
||||
|
@ -2051,7 +2051,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
/* stack mutex released each loop */
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(*it);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator fit = mDownloads.find(*it);
|
||||
if (fit == mDownloads.end())
|
||||
continue;
|
||||
|
||||
|
@ -2083,24 +2083,18 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
RsDirUtil::removeTopDir(fit->second->mDestination, rft->file.path); /* remove fname */
|
||||
rft->flags = fit->second->mFlags.toUInt32();
|
||||
rft->state = fit->second->mState;
|
||||
fit->second->mTransfer->getFileSources(rft->allPeerIds.ids);
|
||||
|
||||
rft->transferred = fit->second->mCreator->getRecvd();
|
||||
std::list<RsPeerId> lst ;
|
||||
fit->second->mTransfer->getFileSources(lst);
|
||||
|
||||
// Remove turtle peers from sources, as they are not supposed to survive a reboot of RS, since they are dynamic sources.
|
||||
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed.
|
||||
//
|
||||
for(std::list<std::string>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
|
||||
if(mTurtle->isTurtlePeer(*sit))
|
||||
{
|
||||
std::list<std::string>::iterator sittmp(sit) ;
|
||||
++sittmp ;
|
||||
rft->allPeerIds.ids.erase(sit) ;
|
||||
sit = sittmp ;
|
||||
}
|
||||
else
|
||||
++sit ;
|
||||
for(std::list<RsPeerId>::const_iterator it(lst.begin());it!=lst.end();++it)
|
||||
if(!mTurtle->isTurtlePeer(*it))
|
||||
rft->allPeerIds.ids.push_back(*it) ;
|
||||
|
||||
rft->transferred = fit->second->mCreator->getRecvd();
|
||||
fit->second->mCreator->getAvailabilityMap(rft->compressed_chunk_map) ;
|
||||
rft->chunk_strategy = fit->second->mCreator->getChunkStrategy() ;
|
||||
|
||||
|
@ -2117,7 +2111,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
/* make RsFileTransfer item for save list */
|
||||
RsFileTransfer *rft = NULL;
|
||||
|
||||
std::map<std::string,RsFileTransfer*>::iterator rit = mPendingChunkMaps.find(pit->mHash);
|
||||
std::map<RsFileHash,RsFileTransfer*>::iterator rit = mPendingChunkMaps.find(pit->mHash);
|
||||
if (rit != mPendingChunkMaps.end()) {
|
||||
/* use item from the not loaded pending list */
|
||||
rft = new RsFileTransfer(*(rit->second));
|
||||
|
@ -2132,18 +2126,24 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
RsDirUtil::removeTopDir(pit->mDest, rft->file.path); /* remove fname */
|
||||
rft->flags = pit->mFlags.toUInt32();
|
||||
rft->state = pit->mState;
|
||||
rft->allPeerIds.ids = pit->mSrcIds;
|
||||
|
||||
rft->allPeerIds.ids.clear() ;
|
||||
for(std::list<RsPeerId>::const_iterator it(pit->mSrcIds.begin());it!=pit->mSrcIds.end();++it)
|
||||
rft->allPeerIds.ids.push_back( *it ) ;
|
||||
}
|
||||
|
||||
// Remove turtle peers from sources, as they are not supposed to survive a reboot of RS, since they are dynamic sources.
|
||||
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed.
|
||||
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed. We do that in post
|
||||
// process since the rft object may have been created from mPendingChunkMaps
|
||||
//
|
||||
for(std::list<std::string>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
|
||||
if(mTurtle->isTurtlePeer(*sit))
|
||||
{
|
||||
std::list<std::string>::iterator sittmp(sit) ;
|
||||
sit = rft->allPeerIds.ids.erase(sit) ;
|
||||
}
|
||||
for(std::list<RsPeerId>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
|
||||
if(mTurtle->isTurtlePeer(RsPeerId(*sit)))
|
||||
{
|
||||
std::list<RsPeerId>::iterator sittmp(sit) ;
|
||||
++sittmp ;
|
||||
rft->allPeerIds.ids.erase(sit) ;
|
||||
sit = sittmp ;
|
||||
}
|
||||
else
|
||||
++sit ;
|
||||
|
||||
|
@ -2201,12 +2201,16 @@ bool ftController::loadList(std::list<RsItem *>& load)
|
|||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::loadList(): requesting " << rsft->file.name << ", " << rsft->file.hash << ", " << rsft->file.filesize << std::endl ;
|
||||
#endif
|
||||
FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize, rsft->file.path, TransferRequestFlags(rsft->flags), rsft->allPeerIds.ids, rsft->state);
|
||||
std::list<RsPeerId> src_lst ;
|
||||
for(std::list<RsPeerId>::const_iterator it(rsft->allPeerIds.ids.begin());it!=rsft->allPeerIds.ids.end();++it)
|
||||
src_lst.push_back(*it) ;
|
||||
|
||||
FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize, rsft->file.path, TransferRequestFlags(rsft->flags), src_lst, rsft->state);
|
||||
|
||||
{
|
||||
RsStackMutex mtx(ctrlMutex) ;
|
||||
|
||||
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
std::map<RsFileHash, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||
|
||||
if((fit==mDownloads.end() || (fit->second)->mCreator == NULL))
|
||||
{
|
||||
|
|
|
@ -74,7 +74,7 @@ class ftFileControl
|
|||
|
||||
ftFileControl();
|
||||
ftFileControl(std::string fname, std::string tmppath, std::string dest,
|
||||
uint64_t size, std::string hash, TransferRequestFlags flags,
|
||||
uint64_t size, const RsFileHash& hash, TransferRequestFlags flags,
|
||||
ftFileCreator *fc, ftTransferModule *tm);
|
||||
|
||||
std::string mName;
|
||||
|
@ -83,7 +83,7 @@ class ftFileControl
|
|||
ftTransferModule * mTransfer;
|
||||
ftFileCreator * mCreator;
|
||||
uint32_t mState;
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
TransferRequestFlags mFlags;
|
||||
time_t mCreateTime;
|
||||
|
@ -94,20 +94,20 @@ class ftFileControl
|
|||
class ftPendingRequest
|
||||
{
|
||||
public:
|
||||
ftPendingRequest(const std::string& fname, const std::string& hash,
|
||||
ftPendingRequest(const std::string& fname, const RsFileHash& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &srcIds, uint16_t state)
|
||||
const std::list<RsPeerId> &srcIds, uint16_t state)
|
||||
: mName(fname), mHash(hash), mSize(size),
|
||||
mDest(dest), mFlags(flags), mSrcIds(srcIds), mState(state) { return; }
|
||||
|
||||
ftPendingRequest() : mSize(0), mFlags(0), mState(0) { return; }
|
||||
|
||||
std::string mName;
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
std::string mDest;
|
||||
TransferRequestFlags mFlags;
|
||||
std::list<std::string> mSrcIds;
|
||||
std::list<RsPeerId> mSrcIds;
|
||||
uint16_t mState;
|
||||
};
|
||||
|
||||
|
@ -131,34 +131,34 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
/********************** Controller Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool FileRequest(const std::string& fname, const std::string& hash,
|
||||
bool FileRequest(const std::string& fname, const RsFileHash& hash,
|
||||
uint64_t size, const std::string& dest, TransferRequestFlags flags,
|
||||
const std::list<std::string> &sourceIds, uint16_t state = ftFileControl::DOWNLOADING);
|
||||
const std::list<RsPeerId> &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);
|
||||
bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info);
|
||||
|
||||
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||
bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s);
|
||||
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||
uint32_t freeDiskSpaceLimit() const ;
|
||||
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
|
||||
bool FileCancel(const std::string& hash);
|
||||
bool FileControl(const std::string& hash, uint32_t flags);
|
||||
bool FileCancel(const RsFileHash& hash);
|
||||
bool FileControl(const RsFileHash& hash, uint32_t flags);
|
||||
bool FileClearCompleted();
|
||||
bool FlagFileComplete(std::string hash);
|
||||
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
|
||||
bool setDestinationName(const std::string& hash,const std::string& dest_name) ;
|
||||
bool setDestinationDirectory(const std::string& hash,const std::string& dest_name) ;
|
||||
bool FlagFileComplete(const RsFileHash& hash);
|
||||
bool getFileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info);
|
||||
bool setDestinationName(const RsFileHash& hash,const std::string& dest_name) ;
|
||||
bool setDestinationDirectory(const RsFileHash& hash,const std::string& dest_name) ;
|
||||
|
||||
// Download speed
|
||||
bool getPriority(const std::string& hash,DwlSpeed& p);
|
||||
void setPriority(const std::string& hash,DwlSpeed p);
|
||||
bool getPriority(const RsFileHash& hash,DwlSpeed& p);
|
||||
void setPriority(const RsFileHash& hash,DwlSpeed p);
|
||||
|
||||
// Action on queue position
|
||||
//
|
||||
void moveInQueue(const std::string& hash,QueueMove mv) ;
|
||||
void moveInQueue(const RsFileHash& hash,QueueMove mv) ;
|
||||
void clearQueue() ;
|
||||
void setQueueSize(uint32_t size) ;
|
||||
uint32_t getQueueSize() ;
|
||||
|
@ -166,14 +166,14 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
uint32_t getMinPrioritizedTransfers() ;
|
||||
|
||||
/* get Details of File Transfers */
|
||||
bool FileDownloads(std::list<std::string> &hashs);
|
||||
bool FileDownloads(std::list<RsFileHash> &hashs);
|
||||
|
||||
/* Directory Handling */
|
||||
bool setDownloadDirectory(std::string path);
|
||||
bool setDownloadDirectory(std::string path);
|
||||
bool setPartialsDirectory(std::string path);
|
||||
std::string getDownloadDirectory();
|
||||
std::string getPartialsDirectory();
|
||||
bool FileDetails(const std::string &hash, FileInfo &info);
|
||||
bool FileDetails(const RsFileHash &hash, FileInfo &info);
|
||||
|
||||
bool moveFile(const std::string& source,const std::string& dest) ;
|
||||
bool copyFile(const std::string& source,const std::string& dest) ;
|
||||
|
@ -184,17 +184,17 @@ 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 RsPeerId& 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 RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
void removeFileSource(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||
virtual bool RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
|
||||
|
||||
void cleanCacheDownloads() ;
|
||||
void searchForDirectSources() ;
|
||||
|
@ -223,10 +223,10 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
void locked_queueRemove(uint32_t pos) ; // delete this element from the queue
|
||||
void locked_swapQueue(uint32_t pos1,uint32_t pos2) ; // swap position of the two elements
|
||||
|
||||
bool completeFile(std::string hash);
|
||||
bool completeFile(const RsFileHash& hash);
|
||||
bool handleAPendingRequest();
|
||||
|
||||
bool setPeerState(ftTransferModule *tm, std::string id,
|
||||
bool setPeerState(ftTransferModule *tm, const RsPeerId& id,
|
||||
uint32_t maxrate, bool online);
|
||||
|
||||
time_t last_save_time ;
|
||||
|
@ -241,8 +241,8 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
|
||||
RsMutex ctrlMutex;
|
||||
|
||||
std::map<std::string, ftFileControl*> mCompleted;
|
||||
std::map<std::string, ftFileControl*> mDownloads;
|
||||
std::map<RsFileHash, ftFileControl*> mCompleted;
|
||||
std::map<RsFileHash, ftFileControl*> mDownloads;
|
||||
std::vector<ftFileControl*> _queue ;
|
||||
|
||||
std::string mConfigPath;
|
||||
|
@ -253,13 +253,13 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
|
||||
/* callback list (for File Completion) */
|
||||
RsMutex doneMutex;
|
||||
std::list<std::string> mDone;
|
||||
std::list<RsFileHash> mDone;
|
||||
|
||||
/* List to Pause File transfers until Caches are properly loaded */
|
||||
bool mFtActive;
|
||||
bool mFtPendingDone;
|
||||
std::list<ftPendingRequest> mPendingRequests;
|
||||
std::map<std::string,RsFileTransfer*> mPendingChunkMaps ;
|
||||
std::map<RsFileHash,RsFileTransfer*> mPendingChunkMaps ;
|
||||
|
||||
FileChunksInfo::ChunkStrategy mDefaultChunkStrategy ;
|
||||
|
||||
|
|
|
@ -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 RsFileHash& 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 RsFileHash& 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 RsFileHash& hash,bool is_client) = 0;
|
||||
virtual bool sendChunkMap(const RsPeerId& peer_id,const RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& hash,uint32_t chunk_id) = 0;
|
||||
virtual bool recvSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& 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 RsFileHash& 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)
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ ftDataMultiplex::ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch
|
|||
bool ftDataMultiplex::addTransferModule(ftTransferModule *mod, ftFileCreator *f)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator it;
|
||||
std::map<RsFileHash, ftClient>::iterator it;
|
||||
if (mClients.end() != (it = mClients.find(mod->hash())))
|
||||
{
|
||||
/* error */
|
||||
|
@ -91,11 +91,11 @@ bool ftDataMultiplex::addTransferModule(ftTransferModule *mod, ftFileCreator *f)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::removeTransferModule(std::string hash)
|
||||
bool ftDataMultiplex::removeTransferModule(const RsFileHash& hash)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string, ftClient>::iterator it;
|
||||
std::map<RsFileHash, ftClient>::iterator it;
|
||||
if (mClients.end() == (it = mClients.find(hash)))
|
||||
{
|
||||
/* error */
|
||||
|
@ -111,7 +111,7 @@ bool ftDataMultiplex::removeTransferModule(std::string hash)
|
|||
// With the current action, the next server request will re-create the server as
|
||||
// a ftFileProvider.
|
||||
//
|
||||
std::map<std::string, ftFileProvider*>::iterator sit = mServers.find(hash) ;
|
||||
std::map<RsFileHash, ftFileProvider*>::iterator sit = mServers.find(hash) ;
|
||||
|
||||
if(sit != mServers.end())
|
||||
mServers.erase(sit);
|
||||
|
@ -120,10 +120,10 @@ bool ftDataMultiplex::removeTransferModule(std::string hash)
|
|||
}
|
||||
|
||||
|
||||
bool ftDataMultiplex::FileUploads(std::list<std::string> &hashs)
|
||||
bool ftDataMultiplex::FileUploads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftFileProvider *>::iterator sit;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator sit;
|
||||
for(sit = mServers.begin(); sit != mServers.end(); sit++)
|
||||
{
|
||||
hashs.push_back(sit->first);
|
||||
|
@ -131,10 +131,10 @@ bool ftDataMultiplex::FileUploads(std::list<std::string> &hashs)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
|
||||
bool ftDataMultiplex::FileDownloads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator cit;
|
||||
std::map<RsFileHash, ftClient>::iterator cit;
|
||||
for(cit = mClients.begin(); cit != mClients.end(); cit++)
|
||||
{
|
||||
hashs.push_back(cit->first);
|
||||
|
@ -143,7 +143,7 @@ bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
|
|||
}
|
||||
|
||||
|
||||
bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hintsflag, FileInfo &info)
|
||||
bool ftDataMultiplex::FileDetails(const RsFileHash &hash, FileSearchFlags hintsflag, FileInfo &info)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::FileDetails(";
|
||||
|
@ -155,7 +155,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
|
|||
|
||||
if(hintsflag & RS_FILE_HINTS_DOWNLOAD)
|
||||
{
|
||||
std::map<std::string, ftClient>::iterator cit;
|
||||
std::map<RsFileHash, ftClient>::iterator cit;
|
||||
if (mClients.end() != (cit = mClients.find(hash)))
|
||||
{
|
||||
|
||||
|
@ -173,7 +173,7 @@ bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hi
|
|||
|
||||
if(hintsflag & RS_FILE_HINTS_UPLOAD)
|
||||
{
|
||||
std::map<std::string, ftFileProvider *>::iterator sit;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator sit;
|
||||
sit = mServers.find(hash);
|
||||
if (sit != mServers.end())
|
||||
{
|
||||
|
@ -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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& 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 RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
|
@ -425,7 +425,7 @@ bool ftDataMultiplex::recvSingleChunkCRC(const std::string& peerId, const std::s
|
|||
|
||||
// update the cache: get size from the client.
|
||||
|
||||
std::map<std::string, ftClient>::iterator it = mClients.find(hash);
|
||||
std::map<RsFileHash, ftClient>::iterator it = mClients.find(hash);
|
||||
|
||||
if(it == mClients.end())
|
||||
{
|
||||
|
@ -456,9 +456,9 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
|
|||
|
||||
uint32_t MAX_CHECKSUM_CHECK_PER_FILE = 25 ;
|
||||
|
||||
for(std::map<std::string,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();)
|
||||
for(std::map<RsFileHash,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();)
|
||||
{
|
||||
std::map<std::string, ftClient>::iterator itc = mClients.find(it->first);
|
||||
std::map<RsFileHash, ftClient>::iterator itc = mClients.find(it->first);
|
||||
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::dispatchReceivedChunkCheckSum(): treating hash " << it->first << std::endl;
|
||||
|
@ -470,7 +470,7 @@ bool ftDataMultiplex::dispatchReceivedChunkCheckSum()
|
|||
std::cerr << "ftDataMultiplex::dispatchReceivedChunkCheckSum() ERROR: No matching Client for hash. This is probably a late answer. Dropping the hash. Hash=" << it->first << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string,Sha1CacheEntry>::iterator tmp(it) ;
|
||||
std::map<RsFileHash,Sha1CacheEntry>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
_cached_sha1maps.erase(it) ;
|
||||
it = tmp ;
|
||||
|
@ -503,13 +503,13 @@ 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 RsFileHash& hash,const CompressedChunkMap& compressed_map,bool client)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
if(client) // is the chunk map for a client, or for a server ?
|
||||
{
|
||||
std::map<std::string, ftClient>::iterator it = mClients.find(hash);
|
||||
std::map<RsFileHash, ftClient>::iterator it = mClients.find(hash);
|
||||
|
||||
if(it == mClients.end())
|
||||
{
|
||||
|
@ -531,7 +531,7 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string&
|
|||
}
|
||||
else
|
||||
{
|
||||
std::map<std::string, ftFileProvider *>::iterator it = mServers.find(hash) ;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator it = mServers.find(hash) ;
|
||||
|
||||
if(it == mServers.end())
|
||||
{
|
||||
|
@ -549,14 +549,14 @@ 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 RsFileHash& hash)
|
||||
{
|
||||
CompressedChunkMap cmap ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string, ftClient>::iterator it = mClients.find(hash);
|
||||
std::map<RsFileHash, ftClient>::iterator it = mClients.find(hash);
|
||||
|
||||
if(it == mClients.end())
|
||||
{
|
||||
|
@ -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 RsFileHash& hash, uint32_t chunk_number)
|
||||
{
|
||||
// look into the sha1sum cache
|
||||
|
||||
|
@ -614,7 +614,7 @@ bool ftDataMultiplex::handleRecvChunkCrcRequest(const std::string& peerId, const
|
|||
return true ;
|
||||
}
|
||||
|
||||
std::map<std::string, ftFileProvider *>::iterator it ;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator it ;
|
||||
std::string filename ;
|
||||
uint64_t filesize =0;
|
||||
found = true ;
|
||||
|
@ -705,10 +705,10 @@ 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 RsFileHash& hash)
|
||||
{
|
||||
CompressedChunkMap cmap ;
|
||||
std::map<std::string, ftFileProvider *>::iterator it ;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator it ;
|
||||
bool found = true ;
|
||||
|
||||
{
|
||||
|
@ -754,15 +754,13 @@ 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 RsFileHash& hash, uint64_t /*size*/, uint64_t offset, uint32_t chunksize, void *data)
|
||||
{
|
||||
ftTransferModule *transfer_module = NULL ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator it;
|
||||
std::map<RsFileHash, ftClient>::iterator it;
|
||||
if (mClients.end() == (it = mClients.find(hash)))
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
|
@ -787,12 +785,12 @@ 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 RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
/**** Find Files *****/
|
||||
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
std::map<std::string, ftClient>::iterator cit;
|
||||
std::map<RsFileHash, ftClient>::iterator cit;
|
||||
if (mOwnId == peerId)
|
||||
{
|
||||
/* own requests must be passed to Servers */
|
||||
|
@ -811,7 +809,7 @@ bool ftDataMultiplex::handleRecvDataRequest(const std::string& peerId, const std
|
|||
return true;
|
||||
}
|
||||
|
||||
std::map<std::string, ftFileProvider *>::iterator sit;
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator sit;
|
||||
if (mServers.end() != (sit = mServers.find(hash)))
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
|
@ -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 RsFileHash& hash, uint64_t size,
|
||||
uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
if(chunksize > uint32_t(10*1024*1024))
|
||||
|
@ -875,13 +872,13 @@ 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 RsFileHash& upload_hash,const RsPeerId& peerId,CompressedChunkMap& cmap)
|
||||
{
|
||||
bool too_old = false;
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string,ftFileProvider *>::iterator sit = mServers.find(upload_hash);
|
||||
std::map<RsFileHash,ftFileProvider *>::iterator sit = mServers.find(upload_hash);
|
||||
|
||||
if(mServers.end() == sit)
|
||||
return false ;
|
||||
|
@ -897,11 +894,11 @@ 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 RsFileHash& hash,bool is_client)
|
||||
{
|
||||
return mDataSend->sendChunkMapRequest(peer_id,hash,is_client);
|
||||
}
|
||||
bool ftDataMultiplex::sendSingleChunkCRCRequests(const std::string& hash, const std::vector<uint32_t>& to_ask)
|
||||
bool ftDataMultiplex::sendSingleChunkCRCRequests(const RsFileHash& hash, const std::vector<uint32_t>& to_ask)
|
||||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
|
@ -933,7 +930,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
// With this, only active sources are querried.
|
||||
//
|
||||
|
||||
for(std::map<std::string,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();++it)
|
||||
for(std::map<RsFileHash,Sha1CacheEntry>::iterator it(_cached_sha1maps.begin());it!=_cached_sha1maps.end();++it)
|
||||
for(std::map<uint32_t,std::pair<time_t,ChunkCheckSumSourceList> >::iterator it2(it->second._to_ask.begin());it2!=it->second._to_ask.end();++it2)
|
||||
if(it2->second.first + MAX_CHECKING_CHUNK_WAIT_DELAY < now) // is the last request old enough?
|
||||
{
|
||||
|
@ -942,18 +939,18 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
#endif
|
||||
// 0 - ask which sources can be used for this chunk
|
||||
//
|
||||
std::map<std::string,ftClient>::const_iterator it4(mClients.find(it->first)) ;
|
||||
std::map<RsFileHash,ftClient>::const_iterator it4(mClients.find(it->first)) ;
|
||||
|
||||
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;
|
||||
|
@ -1014,7 +1011,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
|||
//scan the uploads list in ftdatamultiplex and delete the items which time out
|
||||
time_t now = time(NULL);
|
||||
|
||||
for(std::map<std::string, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
|
||||
for(std::map<RsFileHash, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
|
||||
if(sit->second->purgeOldPeers(now,10))
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
|
@ -1033,7 +1030,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
|||
std::cerr << "ftDataMultiplex::deleteUnusedServers(): " << (void*)sit->second << " was not deleted because it's also a file creator." << std::endl ;
|
||||
#endif
|
||||
|
||||
std::map<std::string, ftFileProvider *>::iterator tmp(sit);
|
||||
std::map<RsFileHash, ftFileProvider *>::iterator tmp(sit);
|
||||
++tmp ;
|
||||
|
||||
mServers.erase(sit);
|
||||
|
@ -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 RsFileHash& hash)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handleSearchRequest(";
|
||||
|
@ -1085,7 +1082,7 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
|
|||
std::cerr << "ftDataMultiplex::handleSearchRequest(";
|
||||
std::cerr << " Found Local File, sharing...";
|
||||
#endif
|
||||
std::map<std::string,ftFileProvider*>::const_iterator it = mServers.find(hash) ;
|
||||
std::map<RsFileHash,ftFileProvider*>::const_iterator it = mServers.find(hash) ;
|
||||
ftFileProvider *provider ;
|
||||
|
||||
if(it == mServers.end())
|
||||
|
@ -1116,7 +1113,7 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
|
|||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
std::map<std::string,ftClient>::const_iterator it(mClients.find(hash)) ;
|
||||
std::map<RsFileHash,ftClient>::const_iterator it(mClients.find(hash)) ;
|
||||
|
||||
if(it != mClients.end())
|
||||
{
|
||||
|
|
|
@ -63,21 +63,21 @@ 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 RsPeerId& peerId, const RsFileHash& 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;
|
||||
std::string mHash;
|
||||
RsPeerId mPeerId;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
uint64_t mOffset;
|
||||
uint32_t mChunk;
|
||||
void *mData;
|
||||
};
|
||||
|
||||
typedef std::map<std::string,time_t> ChunkCheckSumSourceList ;
|
||||
typedef std::map<RsPeerId,time_t> ChunkCheckSumSourceList ;
|
||||
|
||||
class Sha1CacheEntry
|
||||
{
|
||||
|
@ -93,17 +93,17 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
|
||||
public:
|
||||
|
||||
ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search);
|
||||
ftDataMultiplex(const RsPeerId& ownId, ftDataSend *server, ftSearch *search);
|
||||
|
||||
/* ftController Interface */
|
||||
bool addTransferModule(ftTransferModule *mod, ftFileCreator *f);
|
||||
bool removeTransferModule(std::string hash);
|
||||
bool removeTransferModule(const RsFileHash& hash);
|
||||
|
||||
/* data interface */
|
||||
/* get Details of File Transfers */
|
||||
bool FileUploads(std::list<std::string> &hashs);
|
||||
bool FileDownloads(std::list<std::string> &hashs);
|
||||
bool FileDetails(const std::string &hash, FileSearchFlags hintsflag, FileInfo &info);
|
||||
bool FileUploads(std::list<RsFileHash> &hashs);
|
||||
bool FileDownloads(std::list<RsFileHash> &hashs);
|
||||
bool FileDetails(const RsFileHash &hash, FileSearchFlags hintsflag, FileInfo &info);
|
||||
|
||||
void deleteUnusedServers() ;
|
||||
void handlePendingCrcRequests() ;
|
||||
|
@ -112,39 +112,39 @@ 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 RsPeerId& peerId, const RsFileHash& 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 RsPeerId& peerId, const RsFileHash& 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 RsPeerId& peerId, const RsFileHash& hash,bool is_client) ;
|
||||
|
||||
|
||||
/* called from a separate thread */
|
||||
bool sendSingleChunkCRCRequests(const std::string& hash, const std::vector<uint32_t>& to_ask) ;
|
||||
bool sendSingleChunkCRCRequests(const RsFileHash& hash, const std::vector<uint32_t>& to_ask) ;
|
||||
|
||||
bool dispatchReceivedChunkCheckSum() ;
|
||||
|
||||
/*************** 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 RsPeerId& peerId, const RsFileHash& 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 RsPeerId& peerId, const RsFileHash& 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 RsPeerId& peer_id,const RsFileHash& 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 RsPeerId& peer_id,const RsFileHash& 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 RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_id) ;
|
||||
virtual bool recvSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& 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 RsFileHash& upload_hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -155,30 +155,29 @@ 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 RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
bool handleRecvDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
bool handleSearchRequest(const RsPeerId& peerId, const RsFileHash& hash);
|
||||
bool handleRecvClientChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash) ;
|
||||
bool handleRecvServerChunkMapRequest(const RsPeerId& peerId, const RsFileHash& hash) ;
|
||||
bool handleRecvChunkCrcRequest(const RsPeerId& peerId, const RsFileHash& 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 RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
|
||||
RsMutex dataMtx;
|
||||
|
||||
std::map<std::string, ftClient> mClients;
|
||||
std::map<std::string, ftFileProvider *> mServers;
|
||||
std::map<RsFileHash, ftClient> mClients;
|
||||
std::map<RsFileHash, ftFileProvider *> mServers;
|
||||
|
||||
std::list<ftRequest> mRequestQueue;
|
||||
std::list<ftRequest> mSearchQueue;
|
||||
// std::map<std::string, time_t> mUnknownHashs;
|
||||
|
||||
std::map<std::string,Sha1CacheEntry> _cached_sha1maps ; // one cache entry per file hash. Handled dynamically.
|
||||
std::map<RsFileHash,Sha1CacheEntry> _cached_sha1maps ; // one cache entry per file hash. Handled dynamically.
|
||||
|
||||
ftDataSend *mDataSend;
|
||||
ftSearch *mSearch;
|
||||
std::string mOwnId;
|
||||
RsPeerId mOwnId;
|
||||
|
||||
friend class ftServer;
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, p3PeerMgr *pm,
|
|||
return;
|
||||
}
|
||||
|
||||
bool ftFiStore::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftFiStore::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
/* could use hintflags to specify which bits of fileinfo to use additionally.
|
||||
eg. hintflags & FT_SEARCH_PEER_ID, then only return matching peers + hash.
|
||||
|
@ -122,17 +122,17 @@ 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;
|
||||
}
|
||||
|
||||
bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftFiMonitor::search(const RsFileHash &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 RsFileHash &hash, FileSearchFlags hintflags, const RsPeerId& peer_id,FileInfo &info) const
|
||||
{
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags;
|
||||
|
@ -385,7 +385,7 @@ ftCacheStrapper::ftCacheStrapper(p3LinkMgr *lm)
|
|||
}
|
||||
|
||||
/* overloaded search function */
|
||||
bool ftCacheStrapper::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftCacheStrapper::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) hintflags;
|
||||
|
|
|
@ -52,17 +52,17 @@ class ftFiStore: public FileIndexStore, public ftSearch
|
|||
RsPeerId ownid, std::string cachedir);
|
||||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
};
|
||||
|
||||
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 RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, const RsPeerId& peer_id, FileInfo &info) const;
|
||||
|
||||
/* overloaded set dirs enables config indication */
|
||||
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
||||
|
@ -94,7 +94,7 @@ class ftCacheStrapper: public CacheStrapper, public ftSearch
|
|||
ftCacheStrapper(p3LinkMgr *cm);
|
||||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ void ftExtraList::hashAFile()
|
|||
* If the File is alreay Hashed, then just add it in.
|
||||
**/
|
||||
|
||||
bool ftExtraList::addExtraFile(std::string path, std::string hash,
|
||||
bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags)
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
|
@ -180,7 +180,7 @@ bool ftExtraList::addExtraFile(std::string path, std::string hash,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags)
|
||||
bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags)
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) flags;
|
||||
|
@ -195,7 +195,7 @@ bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags)
|
|||
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
std::map<std::string, FileDetails>::iterator it;
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
it = mFiles.find(hash);
|
||||
if (it == mFiles.end())
|
||||
{
|
||||
|
@ -209,12 +209,12 @@ bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftExtraList::moveExtraFile(std::string fname, std::string hash, uint64_t /*size*/,
|
||||
bool ftExtraList::moveExtraFile(std::string fname, const RsFileHash &hash, uint64_t /*size*/,
|
||||
std::string destpath)
|
||||
{
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
std::map<std::string, FileDetails>::iterator it;
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
it = mFiles.find(hash);
|
||||
if (it == mFiles.end())
|
||||
{
|
||||
|
@ -246,10 +246,10 @@ bool ftExtraList::cleanupOldFiles()
|
|||
|
||||
time_t now = time(NULL);
|
||||
|
||||
std::list<std::string> toRemove;
|
||||
std::list<std::string>::iterator rit;
|
||||
std::list<RsFileHash> toRemove;
|
||||
std::list<RsFileHash>::iterator rit;
|
||||
|
||||
std::map<std::string, FileDetails>::iterator it;
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
for(it = mFiles.begin(); it != mFiles.end(); it++)
|
||||
{
|
||||
/* check timestamps */
|
||||
|
@ -317,12 +317,12 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
{
|
||||
/* Find in the path->hash map */
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
std::map<std::string, RsFileHash>::iterator it;
|
||||
if (mHashedList.end() == (it = mHashedList.find(path)))
|
||||
{
|
||||
return false;
|
||||
|
@ -336,7 +336,7 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info)
|
|||
* Search Function - used by File Transfer
|
||||
*
|
||||
**/
|
||||
bool ftExtraList::search(const std::string &hash, FileSearchFlags /*hintflags*/, FileInfo &info) const
|
||||
bool ftExtraList::search(const RsFileHash &hash, FileSearchFlags /*hintflags*/, FileInfo &info) const
|
||||
{
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
|
@ -345,7 +345,7 @@ bool ftExtraList::search(const std::string &hash, FileSearchFlags /*hintflags
|
|||
#endif
|
||||
|
||||
/* find hash */
|
||||
std::map<std::string, FileDetails>::const_iterator fit;
|
||||
std::map<RsFileHash, FileDetails>::const_iterator fit;
|
||||
if (mFiles.end() == (fit = mFiles.find(hash)))
|
||||
{
|
||||
return false;
|
||||
|
@ -397,7 +397,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
|||
RsStackMutex stack(extMutex);
|
||||
|
||||
|
||||
std::map<std::string, FileDetails>::const_iterator it;
|
||||
std::map<RsFileHash, FileDetails>::const_iterator it;
|
||||
for(it = mFiles.begin(); it != mFiles.end(); it++)
|
||||
{
|
||||
RsFileConfigItem *fi = new RsFileConfigItem();
|
||||
|
|
|
@ -90,7 +90,7 @@ class FileDetails
|
|||
std::list<std::string> sources;
|
||||
std::string path;
|
||||
std::string fname;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
uint64_t size;
|
||||
#endif
|
||||
|
||||
|
@ -117,11 +117,11 @@ class ftExtraList: public RsThread, public p3Config, public ftSearch
|
|||
* If the File is alreay Hashed, then just add it in.
|
||||
**/
|
||||
|
||||
bool addExtraFile(std::string path, std::string hash,
|
||||
bool addExtraFile(std::string path, const RsFileHash &hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
|
||||
bool removeExtraFile(std::string hash, TransferRequestFlags flags);
|
||||
bool moveExtraFile(std::string fname, std::string hash, uint64_t size,
|
||||
bool removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
bool moveExtraFile(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath);
|
||||
|
||||
|
||||
|
@ -138,7 +138,7 @@ bool hashExtraFileDone(std::string path, FileInfo &info);
|
|||
* implementation of ftSearch.
|
||||
*
|
||||
**/
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
/***
|
||||
* Thread Main Loop
|
||||
|
@ -165,8 +165,8 @@ bool cleanupEntry(std::string path, TransferRequestFlags flags);
|
|||
|
||||
std::list<FileDetails> mToHash;
|
||||
|
||||
std::map<std::string, std::string> mHashedList; /* path -> hash ( not saved ) */
|
||||
std::map<std::string, FileDetails> mFiles;
|
||||
std::map<std::string, RsFileHash> mHashedList; /* path -> hash ( not saved ) */
|
||||
std::map<RsFileHash, FileDetails> mFiles;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
***********************************************************/
|
||||
|
||||
ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::string& hash,bool assume_availability)
|
||||
ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const RsFileHash& hash,bool assume_availability)
|
||||
: ftFileProvider(path,size,hash), chunkMap(size,assume_availability)
|
||||
{
|
||||
/*
|
||||
|
@ -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 ******/
|
||||
|
||||
|
@ -617,7 +617,7 @@ bool ftFileCreator::finished()
|
|||
return chunkMap.isComplete() ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::hashReceivedData(std::string& hash)
|
||||
bool ftFileCreator::hashReceivedData(RsFileHash& hash)
|
||||
{
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "file creator asked for hashing received data " << file_name << std::endl;
|
||||
|
@ -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 ******/
|
||||
|
||||
|
|
|
@ -47,12 +47,12 @@ class ftFileCreator: public ftFileProvider
|
|||
{
|
||||
public:
|
||||
|
||||
ftFileCreator(const std::string& savepath, uint64_t size, const std::string& hash,bool assume_availability);
|
||||
ftFileCreator(const std::string& savepath, uint64_t size, const RsFileHash& hash,bool assume_availability);
|
||||
|
||||
~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 RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
bool finished() ;
|
||||
uint64_t getRecvd();
|
||||
|
||||
|
@ -69,7 +69,7 @@ class ftFileCreator: public ftFileProvider
|
|||
// long time. Therefore, we must pay attention not to call this function
|
||||
// at a time file_name nor hash can be modified, which is quite easy.
|
||||
|
||||
bool hashReceivedData(std::string& hash) ;
|
||||
bool hashReceivedData(RsFileHash& hash) ;
|
||||
|
||||
// Sets all chunks to checking state
|
||||
//
|
||||
|
@ -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 RsPeerId& 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 RsPeerId& 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<RsPeerId>& 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 RsPeerId& peer_id,const CompressedChunkMap& map) ;
|
||||
|
||||
// Returns true id the given file source is complete.
|
||||
//
|
||||
bool sourceIsComplete(const std::string& peer_id) ;
|
||||
bool sourceIsComplete(const RsPeerId& 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<RsPeerId,ZeroInitCounter> mChunksPerPeer ;
|
||||
|
||||
ChunkMap chunkMap ;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
static const time_t UPLOAD_CHUNK_MAPS_TIME = 20 ; // time to ask for a new chunkmap from uploaders in seconds.
|
||||
|
||||
ftFileProvider::ftFileProvider(const std::string& path, uint64_t size, const std::string& hash)
|
||||
ftFileProvider::ftFileProvider(const std::string& path, uint64_t size, const RsFileHash& hash)
|
||||
: mSize(size), hash(hash), file_name(path), fd(NULL), ftcMutex("ftFileProvider")
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
@ -53,7 +53,7 @@ bool ftFileProvider::fileOk()
|
|||
return (fd != NULL);
|
||||
}
|
||||
|
||||
std::string ftFileProvider::getHash()
|
||||
RsFileHash ftFileProvider::getHash()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
return hash;
|
||||
|
@ -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<RsPeerId,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<RsPeerId,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<RsPeerId,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 RsPeerId& 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 RsPeerId& 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 RsPeerId& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@
|
|||
class ftFileProvider
|
||||
{
|
||||
public:
|
||||
ftFileProvider(const std::string& path, uint64_t size, const std::string& hash);
|
||||
ftFileProvider(const std::string& path, uint64_t size, const RsFileHash& hash);
|
||||
virtual ~ftFileProvider();
|
||||
|
||||
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
|
||||
virtual bool FileDetails(FileInfo &info);
|
||||
std::string getHash();
|
||||
RsFileHash getHash();
|
||||
uint64_t getFileSize();
|
||||
bool fileOk();
|
||||
|
||||
|
@ -54,21 +54,21 @@ 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.
|
||||
//
|
||||
bool purgeOldPeers(time_t now,uint32_t max_duration) ;
|
||||
|
||||
const std::string& fileHash() const { return hash ; }
|
||||
const RsFileHash& fileHash() const { return hash ; }
|
||||
const std::string& fileName() const { return file_name ; }
|
||||
uint64_t fileSize() const { return mSize ; }
|
||||
protected:
|
||||
virtual int initializeFileAttrs(); /* does for both */
|
||||
|
||||
uint64_t mSize;
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
std::string file_name;
|
||||
FILE *fd;
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -75,7 +75,7 @@ bool ftFileSearch::addSearchMode(ftSearch *search, FileSearchFlags hintflags)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ftFileSearch::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
bool ftFileSearch::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||
{
|
||||
uint32_t hints, i;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class ftFileSearch: public ftSearch
|
|||
ftFileSearch();
|
||||
|
||||
bool addSearchMode(ftSearch *search, FileSearchFlags hintflags);
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -42,12 +42,12 @@ class ftSearch
|
|||
public:
|
||||
ftSearch() { return; }
|
||||
virtual ~ftSearch() { return; }
|
||||
virtual bool search(const std::string & /*hash*/, FileSearchFlags /*hintflags*/,const std::string& /*peer_id*/, FileInfo & /*info*/) const
|
||||
virtual bool search(const RsFileHash & /*hash*/, FileSearchFlags /*hintflags*/,const RsPeerId& /*peer_id*/, FileInfo & /*info*/) const
|
||||
{
|
||||
std::cerr << "Non overloaded search method called!!!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const = 0;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
@ -239,38 +241,23 @@ bool ftServer::ResumeTransfers()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::checkHash(const std::string& hash,std::string& error_string)
|
||||
bool ftServer::checkHash(const RsFileHash& hash,std::string& error_string)
|
||||
{
|
||||
static const uint32_t HASH_LENGTH = 40 ;
|
||||
|
||||
if(hash.length() != HASH_LENGTH)
|
||||
{
|
||||
rs_sprintf(error_string, "Line too long : %u chars, %ld expected.", hash.length(), HASH_LENGTH) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<hash.length();++i)
|
||||
if(!((hash[i] > 47 && hash[i] < 58) || (hash[i] > 96 && hash[i] < 103)))
|
||||
{
|
||||
rs_sprintf(error_string, "unexpected char code=%d '%c'", (int)hash[i], hash[i]) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||
bool ftServer::alreadyHaveFile(const RsFileHash& 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 RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds)
|
||||
{
|
||||
std::string error_string ;
|
||||
|
||||
if(!checkHash(hash,error_string))
|
||||
{
|
||||
RsServer::notify()->notifyErrorMsg(0,0,"Error handling hash \""+hash+"\". This hash appears to be invalid(Error string=\""+error_string+"\"). This is probably due an bad handling of strings.") ;
|
||||
RsServer::notify()->notifyErrorMsg(0,0,"Error handling hash \""+hash.toStdString()+"\". This hash appears to be invalid(Error string=\""+error_string+"\"). This is probably due an bad handling of strings.") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
@ -282,15 +269,15 @@ bool ftServer::FileRequest(const std::string& fname, const std::string& hash, ui
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::setDestinationName(const std::string& hash,const std::string& name)
|
||||
bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name)
|
||||
{
|
||||
return mFtController->setDestinationName(hash,name);
|
||||
}
|
||||
bool ftServer::setDestinationDirectory(const std::string& hash,const std::string& directory)
|
||||
bool ftServer::setDestinationDirectory(const RsFileHash& hash,const std::string& directory)
|
||||
{
|
||||
return mFtController->setDestinationDirectory(hash,directory);
|
||||
}
|
||||
bool ftServer::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s)
|
||||
bool ftServer::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s)
|
||||
{
|
||||
return mFtController->setChunkStrategy(hash,s);
|
||||
}
|
||||
|
@ -310,7 +297,7 @@ FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy()
|
|||
{
|
||||
return mFtController->defaultChunkStrategy() ;
|
||||
}
|
||||
bool ftServer::FileCancel(const std::string& hash)
|
||||
bool ftServer::FileCancel(const RsFileHash& hash)
|
||||
{
|
||||
// Remove from both queue and ftController, by default.
|
||||
//
|
||||
|
@ -319,7 +306,7 @@ bool ftServer::FileCancel(const std::string& hash)
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::FileControl(const std::string& hash, uint32_t flags)
|
||||
bool ftServer::FileControl(const RsFileHash& hash, uint32_t flags)
|
||||
{
|
||||
return mFtController->FileControl(hash, flags);
|
||||
}
|
||||
|
@ -345,17 +332,17 @@ uint32_t ftServer::getQueueSize()
|
|||
return mFtController->getQueueSize() ;
|
||||
}
|
||||
/* Control of Downloads Priority. */
|
||||
bool ftServer::changeQueuePosition(const std::string hash, QueueMove mv)
|
||||
bool ftServer::changeQueuePosition(const RsFileHash& hash, QueueMove mv)
|
||||
{
|
||||
mFtController->moveInQueue(hash,mv) ;
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::changeDownloadSpeed(const std::string hash, int speed)
|
||||
bool ftServer::changeDownloadSpeed(const RsFileHash& hash, int speed)
|
||||
{
|
||||
mFtController->setPriority(hash, (DwlSpeed)speed);
|
||||
return true ;
|
||||
}
|
||||
bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
|
||||
bool ftServer::getDownloadSpeed(const RsFileHash& hash, int & speed)
|
||||
{
|
||||
DwlSpeed _speed;
|
||||
int ret = mFtController->getPriority(hash, _speed);
|
||||
|
@ -364,12 +351,12 @@ bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
|
|||
|
||||
return ret;
|
||||
}
|
||||
bool ftServer::clearDownload(const std::string /*hash*/)
|
||||
bool ftServer::clearDownload(const RsFileHash& /*hash*/)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
||||
bool ftServer::FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info)
|
||||
{
|
||||
return mFtController->getFileDownloadChunksDetails(hash,info);
|
||||
}
|
||||
|
@ -400,24 +387,24 @@ std::string ftServer::getPartialsDirectory()
|
|||
/************************* Other Access ************************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::FileDownloads(std::list<std::string> &hashs)
|
||||
bool ftServer::FileDownloads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
return mFtController->FileDownloads(hashs);
|
||||
/* this only contains downloads.... not completed */
|
||||
//return mFtDataplex->FileDownloads(hashs);
|
||||
}
|
||||
|
||||
bool ftServer::FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& cmap)
|
||||
bool ftServer::FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap)
|
||||
{
|
||||
return mFtDataplex->getClientChunkMap(hash,peer_id,cmap);
|
||||
}
|
||||
|
||||
bool ftServer::FileUploads(std::list<std::string> &hashs)
|
||||
bool ftServer::FileUploads(std::list<RsFileHash> &hashs)
|
||||
{
|
||||
return mFtDataplex->FileUploads(hashs);
|
||||
}
|
||||
|
||||
bool ftServer::FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info)
|
||||
bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info)
|
||||
{
|
||||
if (hintflags & RS_FILE_HINTS_DOWNLOAD)
|
||||
if(mFtController->FileDetails(hash, info))
|
||||
|
@ -481,7 +468,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 RsFileHash& 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);
|
||||
|
@ -513,13 +500,13 @@ bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& pe
|
|||
/******************* ExtraFileList Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
||||
bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
uint32_t period, TransferRequestFlags flags)
|
||||
{
|
||||
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileRemove(std::string hash, TransferRequestFlags flags)
|
||||
bool ftServer::ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags)
|
||||
{
|
||||
return mFtExtra->removeExtraFile(hash, flags);
|
||||
}
|
||||
|
@ -534,7 +521,7 @@ bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info)
|
|||
return mFtExtra->hashExtraFileDone(localpath, info);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
||||
bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath)
|
||||
{
|
||||
return mFtExtra->moveExtraFile(fname, hash, size, destpath);
|
||||
|
@ -545,7 +532,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 +597,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 +624,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 +857,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 RsFileHash& 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 +895,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 RsFileHash& hash,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
|
@ -937,7 +924,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 RsFileHash& hash,const CompressedChunkMap& map,bool is_client)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
|
||||
|
@ -968,7 +955,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 RsFileHash& 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 +986,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 RsFileHash& 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 +1020,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 RsFileHash& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
|
@ -1130,8 +1117,8 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
// Dont delete the item. The client (p3turtle) is doing it after calling this.
|
||||
//
|
||||
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
||||
const std::string& hash,
|
||||
const std::string& virtual_peer_id,
|
||||
const RsFileHash& hash,
|
||||
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() ;
|
||||
|
@ -102,12 +102,12 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
|
||||
// Checks that the given hash is well formed. Used to chase
|
||||
// string bugs.
|
||||
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
||||
static bool checkHash(const RsFileHash& hash,std::string& error_string) ;
|
||||
|
||||
// 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 RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& 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) ;
|
||||
|
@ -129,14 +129,14 @@ 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 FileCancel(const std::string& hash);
|
||||
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
||||
virtual bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info);
|
||||
virtual bool FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds);
|
||||
virtual bool FileCancel(const RsFileHash& hash);
|
||||
virtual bool FileControl(const RsFileHash& hash, uint32_t flags);
|
||||
virtual bool FileClearCompleted();
|
||||
virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) ;
|
||||
virtual bool setDestinationName(const std::string& hash,const std::string& new_name) ;
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual bool setDestinationDirectory(const RsFileHash& hash,const std::string& new_path) ;
|
||||
virtual bool setDestinationName(const RsFileHash& hash,const std::string& new_name) ;
|
||||
virtual bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||
|
@ -150,43 +150,43 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
virtual void setMinPrioritizedTransfers(uint32_t s) ;
|
||||
virtual uint32_t getQueueSize() ;
|
||||
virtual void setQueueSize(uint32_t s) ;
|
||||
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
||||
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
||||
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
||||
virtual bool clearDownload(const std::string hash);
|
||||
virtual bool changeQueuePosition(const RsFileHash& hash, QueueMove queue_mv);
|
||||
virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed);
|
||||
virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed);
|
||||
virtual bool clearDownload(const RsFileHash& hash);
|
||||
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
||||
|
||||
/***
|
||||
* Download/Upload Details
|
||||
***/
|
||||
virtual bool FileDownloads(std::list<std::string> &hashs);
|
||||
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 FileDownloads(std::list<RsFileHash> &hashs);
|
||||
virtual bool FileUploads(std::list<RsFileHash> &hashs);
|
||||
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
|
||||
/***
|
||||
* Extra List Access
|
||||
***/
|
||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath);
|
||||
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath);
|
||||
|
||||
|
||||
/***
|
||||
* 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 RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& 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<RsPeerId>& 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<RsPeerId>::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<RsPeerId,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<RsPeerId> &peerIds)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator it;
|
||||
std::map<RsPeerId,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 RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,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<RsPeerId,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 RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,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 RsPeerId& 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<RsPeerId,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<RsPeerId>::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 RsPeerId& peerId,uint32_t &state,uint32_t &tfRate)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,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 RsPeerId& peerId)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,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 RsPeerId& 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<RsPeerId,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 RsPeerId& 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 RsPeerId& 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<RsPeerId,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<RsPeerId,peerInfo>::iterator it;
|
||||
for(it = mFileSources.begin(); it != mFileSources.end(); it++)
|
||||
{
|
||||
std::cerr << " " << it->first;
|
||||
|
@ -553,14 +553,14 @@ class HashThread: public RsThread
|
|||
#ifdef FT_DEBUG
|
||||
std::cerr << "hash thread is running for file " << std::endl;
|
||||
#endif
|
||||
std::string tmphash ;
|
||||
RsFileHash tmphash ;
|
||||
_m->hashReceivedData(tmphash) ;
|
||||
|
||||
RsStackMutex stack(_hashThreadMtx) ;
|
||||
_hash = tmphash ;
|
||||
_finished = true ;
|
||||
}
|
||||
std::string hash()
|
||||
RsFileHash hash()
|
||||
{
|
||||
RsStackMutex stack(_hashThreadMtx) ;
|
||||
return _hash ;
|
||||
|
@ -574,7 +574,7 @@ class HashThread: public RsThread
|
|||
RsMutex _hashThreadMtx ;
|
||||
ftFileCreator *_m ;
|
||||
bool _finished ;
|
||||
std::string _hash ;
|
||||
RsFileHash _hash ;
|
||||
};
|
||||
|
||||
bool ftTransferModule::checkFile()
|
||||
|
@ -607,7 +607,7 @@ bool ftTransferModule::checkFile()
|
|||
return false ;
|
||||
}
|
||||
|
||||
std::string check_hash( _hash_thread->hash() ) ;
|
||||
RsFileHash check_hash( _hash_thread->hash() ) ;
|
||||
|
||||
_hash_thread->join(); // allow releasing of resources when finished.
|
||||
|
||||
|
@ -645,7 +645,7 @@ void ftTransferModule::adjustSpeed()
|
|||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
std::map<std::string,peerInfo>::iterator mit;
|
||||
std::map<RsPeerId,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 RsPeerId& 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 RsPeerId& 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;
|
||||
RsPeerId peerId;
|
||||
uint32_t state;
|
||||
double desiredRate;
|
||||
double actualRate;
|
||||
|
@ -111,9 +111,9 @@ public:
|
|||
};
|
||||
|
||||
ftFileStatus():hash(""),stat(PQIFILE_INIT) {}
|
||||
ftFileStatus(std::string hash_in):hash(hash_in),stat(PQIFILE_INIT) {}
|
||||
ftFileStatus(const RsFileHash& hash_in):hash(hash_in),stat(PQIFILE_INIT) {}
|
||||
|
||||
std::string hash;
|
||||
RsFileHash hash;
|
||||
Status stat;
|
||||
};
|
||||
|
||||
|
@ -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<RsPeerId>& peerIds);
|
||||
bool addFileSource(const RsPeerId& peerId);
|
||||
bool removeFileSource(const RsPeerId& peerId);
|
||||
bool setPeerState(const RsPeerId& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
|
||||
bool getFileSources(std::list<RsPeerId> &peerIds);
|
||||
bool getPeerState(const RsPeerId& peerId,uint32_t &state,uint32_t &tfRate);
|
||||
uint32_t getDataRate(const RsPeerId& peerId);
|
||||
bool cancelTransfer();
|
||||
bool cancelFileTransferUpward();
|
||||
bool completeFileTransfer();
|
||||
|
@ -138,17 +138,17 @@ 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 RsPeerId& peerId, uint64_t offset, uint32_t chunk_size, void *data);
|
||||
void locked_requestData(const RsPeerId& 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 RsPeerId& 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();
|
||||
|
||||
std::string hash() { return mHash; }
|
||||
uint64_t size() { return mSize; }
|
||||
const RsFileHash& hash() const { return mHash; }
|
||||
uint64_t size() const { return mSize; }
|
||||
|
||||
//internal used functions
|
||||
bool queryInactive();
|
||||
|
@ -175,13 +175,13 @@ private:
|
|||
ftDataMultiplex *mMultiplexor;
|
||||
ftController *mFtController;
|
||||
|
||||
std::string mHash;
|
||||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
|
||||
RsMutex tfMtx; /* below is mutex protected */
|
||||
|
||||
std::list<std::string> mOnlinePeers;
|
||||
std::map<std::string,peerInfo> mFileSources;
|
||||
std::list<RsPeerId> mOnlinePeers;
|
||||
std::map<RsPeerId,peerInfo> mFileSources;
|
||||
|
||||
uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete, 3: checking hash, 4: checking chunks
|
||||
double desiredRate;
|
||||
|
|
|
@ -79,15 +79,6 @@ uint32_t RsTurtleFileMapItem::serial_size()
|
|||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileCrcRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleChunkCrcItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
@ -95,7 +86,7 @@ uint32_t RsTurtleChunkCrcItem::serial_size()
|
|||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // chunk number
|
||||
s += 20 ; // check_sum
|
||||
s += check_sum.serial_size() ; // check_sum
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
@ -179,40 +170,6 @@ bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize)
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleFileCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleFileCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
|
@ -273,7 +230,7 @@ bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize)
|
|||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, chunk_number);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, check_sum);
|
||||
ok &= check_sum.serialise(data, tlvsize, offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -353,7 +310,7 @@ RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
|||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_number) ;
|
||||
ok &= getRawSha1(data, pktsize, &offset, check_sum) ;
|
||||
ok &= check_sum.deserialise(data, pktsize, offset) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
|
@ -363,28 +320,7 @@ RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
|||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleFileCrcRequestItem::RsTurtleFileCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_CRC_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map request item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST)
|
||||
{
|
||||
|
@ -596,14 +532,6 @@ std::ostream& RsTurtleFileMapRequestItem::print(std::ostream& o, uint16_t)
|
|||
}
|
||||
|
||||
|
||||
std::ostream& RsTurtleFileCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File CRC request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
std::ostream& RsTurtleChunkCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
|
@ -615,7 +543,7 @@ std::ostream& RsTurtleChunkCrcRequestItem::print(std::ostream& o, uint16_t)
|
|||
}
|
||||
std::ostream& RsTurtleChunkCrcItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
o << "Chunk CRC item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " chunk num : " << chunk_number << std::endl ;
|
||||
|
|
|
@ -100,21 +100,6 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
|
|||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileCrcRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC_REQUEST);}
|
||||
RsTurtleFileCrcRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_SERVER ; }
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue