mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 21:58:57 -04:00
Merge branch 'master' into jsonapi
This commit is contained in:
commit
047ae7f723
260 changed files with 1737 additions and 1178 deletions
|
@ -31,7 +31,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "ftchunkmap.h"
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
static const uint32_t SOURCE_CHUNK_MAP_UPDATE_PERIOD = 60 ; //! TTL for chunkmap info
|
||||
static const uint32_t INACTIVE_CHUNK_TIME_LAPSE = 3600 ; //! TTL for an inactive chunk
|
||||
|
@ -264,7 +264,7 @@ bool ChunkMap::reAskPendingChunk( const RsPeerId& peer_id,
|
|||
if(_map[i] == FileChunksInfo::CHUNK_OUTSTANDING)
|
||||
return false ;
|
||||
|
||||
time_t now = time(NULL);
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
for(std::map<uint32_t,ChunkDownloadInfo>::iterator it(_slices_to_download.begin());it!=_slices_to_download.end();++it)
|
||||
for(std::map<ftChunk::OffsetInFile,ChunkDownloadInfo::SliceRequestInfo >::iterator it2(it->second._slices.begin());it2!=it->second._slices.end();++it2)
|
||||
|
@ -400,7 +400,7 @@ bool ChunkMap::getDataChunk(const RsPeerId& peer_id,uint32_t size_hint,ftChunk&
|
|||
void ChunkMap::removeInactiveChunks(std::vector<ftChunk::OffsetInFile>& to_remove)
|
||||
{
|
||||
to_remove.clear() ;
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
for(std::map<ChunkNumber,ChunkDownloadInfo>::iterator it(_slices_to_download.begin());it!=_slices_to_download.end();)
|
||||
if(now - it->second._last_data_received > (int)INACTIVE_CHUNK_TIME_LAPSE)
|
||||
|
@ -573,7 +573,7 @@ uint32_t ChunkMap::getAvailableChunk(const RsPeerId& peer_id,bool& map_is_too_ol
|
|||
// useful to get a new map that will also be full, but because we need to be careful not to mislead information,
|
||||
// we still keep asking.
|
||||
//
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
if((!peer_chunks->is_full) && ((int)now - (int)peer_chunks->TS > (int)SOURCE_CHUNK_MAP_UPDATE_PERIOD))
|
||||
{
|
||||
|
|
|
@ -63,7 +63,7 @@ class ftChunk
|
|||
uint64_t offset; // current offset of the slice
|
||||
uint64_t size; // size remaining to download
|
||||
OffsetInFile id ; // id of the chunk. Equal to the starting offset of the chunk
|
||||
time_t ts; // time of last data received
|
||||
rstime_t ts; // time of last data received
|
||||
int *ref_cnt; // shared counter of number of sub-blocks. Used when a slice gets split.
|
||||
RsPeerId peer_id ;
|
||||
};
|
||||
|
@ -98,20 +98,20 @@ struct ChunkDownloadInfo
|
|||
struct SliceRequestInfo
|
||||
{
|
||||
uint32_t size ; // size of the slice
|
||||
time_t request_time ; // last request time
|
||||
rstime_t request_time ; // last request time
|
||||
std::set<RsPeerId> peers ; // peers the slice was requested to. Normally only one, except at the end of the file.
|
||||
};
|
||||
|
||||
std::map<ftChunk::OffsetInFile,SliceRequestInfo> _slices ;
|
||||
uint32_t _remains ;
|
||||
time_t _last_data_received ;
|
||||
rstime_t _last_data_received ;
|
||||
};
|
||||
|
||||
class SourceChunksInfo
|
||||
{
|
||||
public:
|
||||
CompressedChunkMap cmap ; //! map of what the peer has/doens't have
|
||||
time_t TS ; //! last update time for this info
|
||||
rstime_t TS ; //! last update time for this info
|
||||
bool is_full ; //! is the map full ? In such a case, re-asking for it is unnecessary.
|
||||
|
||||
// Returns true if the offset is starting in a mapped chunk.
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
#include "rsitems/rsconfigitems.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* for (u)sleep() */
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
/******
|
||||
* #define CONTROL_DEBUG 1
|
||||
|
@ -226,7 +226,7 @@ void ftController::data_tick()
|
|||
doPending = (mFtActive) && (!mFtPendingDone);
|
||||
}
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
if(now > last_save_time + SAVE_TRANSFERS_DELAY)
|
||||
{
|
||||
IndicateConfigChanged() ;
|
||||
|
@ -421,11 +421,11 @@ void ftController::checkDownloadQueue()
|
|||
|
||||
// Check for inactive transfers, and queued transfers with online sources.
|
||||
//
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
for(std::map<RsFileHash,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() ;++it)
|
||||
if( it->second->mState != ftFileControl::QUEUED && (it->second->mState == ftFileControl::PAUSED
|
||||
|| now > it->second->mTransfer->lastActvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED))
|
||||
|| now > it->second->mTransfer->lastActvTimeStamp() + (rstime_t)MAX_TIME_INACTIVE_REQUEUED))
|
||||
{
|
||||
inactive_transfers.push_back(it->second) ;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class ftFileControl
|
|||
RsFileHash mHash;
|
||||
uint64_t mSize;
|
||||
TransferRequestFlags mFlags;
|
||||
time_t mCreateTime;
|
||||
rstime_t mCreateTime;
|
||||
uint32_t mQueuePriority ;
|
||||
uint32_t mQueuePosition ;
|
||||
};
|
||||
|
@ -226,8 +226,8 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
|
|||
bool setPeerState(ftTransferModule *tm, const RsPeerId& id,
|
||||
uint32_t maxrate, bool online);
|
||||
|
||||
time_t last_save_time ;
|
||||
time_t last_clean_time ;
|
||||
rstime_t last_save_time ;
|
||||
rstime_t last_clean_time ;
|
||||
/* pointers to other components */
|
||||
|
||||
ftSearch *mSearch;
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "util/rsdir.h"
|
||||
#include "util/rsmemory.h"
|
||||
#include <retroshare/rsturtle.h>
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
/* For Thread Behaviour */
|
||||
const uint32_t DMULTIPLEX_MIN = 10; /* 10 msec sleep */
|
||||
|
@ -452,7 +452,7 @@ bool ftDataMultiplex::recvSingleChunkCRC(const RsPeerId& peerId, const RsFileHas
|
|||
// remove this chunk from the request list as well.
|
||||
|
||||
Sha1CacheEntry& sha1cache(_cached_sha1maps[hash]) ;
|
||||
std::map<uint32_t,std::pair<time_t,ChunkCheckSumSourceList> >::iterator it2(sha1cache._to_ask.find(chunk_number)) ;
|
||||
std::map<uint32_t,std::pair<rstime_t,ChunkCheckSumSourceList> >::iterator it2(sha1cache._to_ask.find(chunk_number)) ;
|
||||
|
||||
if(it2 != sha1cache._to_ask.end())
|
||||
sha1cache._to_ask.erase(it2) ;
|
||||
|
@ -943,7 +943,7 @@ bool ftDataMultiplex::sendSingleChunkCRCRequests(const RsFileHash& hash, const s
|
|||
|
||||
for(uint32_t i=0;i<to_ask.size();++i)
|
||||
{
|
||||
std::pair<time_t,ChunkCheckSumSourceList>& list(ce._to_ask[to_ask[i]]) ;
|
||||
std::pair<rstime_t,ChunkCheckSumSourceList>& list(ce._to_ask[to_ask[i]]) ;
|
||||
list.first = 0 ; // set last request time to 0
|
||||
}
|
||||
return true ;
|
||||
|
@ -953,7 +953,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
{
|
||||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
uint32_t n=0 ;
|
||||
|
||||
// Go through the list of currently handled hashes. For each of them,
|
||||
|
@ -966,7 +966,7 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
//
|
||||
|
||||
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)
|
||||
for(std::map<uint32_t,std::pair<rstime_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?
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
|
@ -986,14 +986,14 @@ void ftDataMultiplex::handlePendingCrcRequests()
|
|||
//
|
||||
|
||||
RsPeerId best_source ;
|
||||
time_t oldest_timestamp = now ;
|
||||
rstime_t oldest_timestamp = now ;
|
||||
|
||||
for(uint32_t i=0;i<sources.size();++i)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::handlePendingCrcRequests(): Examining source " << sources[i] << std::endl;
|
||||
#endif
|
||||
std::map<RsPeerId,time_t>::const_iterator it3(it2->second.second.find(sources[i])) ;
|
||||
std::map<RsPeerId,rstime_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.
|
||||
{
|
||||
|
@ -1044,7 +1044,7 @@ void ftDataMultiplex::deleteUnusedServers()
|
|||
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||
|
||||
//scan the uploads list in ftdatamultiplex and delete the items which time out
|
||||
time_t now = time(NULL);
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
for(std::map<RsFileHash, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
|
||||
if(sit->second->purgeOldPeers(now,10))
|
||||
|
|
|
@ -74,15 +74,15 @@ class ftRequest
|
|||
void *mData;
|
||||
};
|
||||
|
||||
typedef std::map<RsPeerId,time_t> ChunkCheckSumSourceList ;
|
||||
typedef std::map<RsPeerId,rstime_t> ChunkCheckSumSourceList ;
|
||||
|
||||
class Sha1CacheEntry
|
||||
{
|
||||
public:
|
||||
Sha1Map _map ; // Map of available sha1 sums for every chunk.
|
||||
time_t last_activity ; // This is used for removing unused entries.
|
||||
rstime_t last_activity ; // This is used for removing unused entries.
|
||||
std::vector<uint32_t> _received ; // received chunk ids. To bedispatched.
|
||||
std::map<uint32_t,std::pair<time_t,ChunkCheckSumSourceList> > _to_ask ; // Chunks to ask to sources.
|
||||
std::map<uint32_t,std::pair<rstime_t,ChunkCheckSumSourceList> > _to_ask ; // Chunks to ask to sources.
|
||||
};
|
||||
|
||||
class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "util/rstime.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* for (u)sleep() */
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
/******
|
||||
* #define DEBUG_ELIST 1
|
||||
|
@ -49,7 +49,7 @@ ftExtraList::ftExtraList()
|
|||
void ftExtraList::data_tick()
|
||||
{
|
||||
bool todo = false;
|
||||
time_t now = time(NULL);
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
{
|
||||
RsStackMutex stack(extMutex);
|
||||
|
@ -96,7 +96,7 @@ void ftExtraList::hashAFile()
|
|||
FileDetails details;
|
||||
|
||||
{
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
if (mToHash.empty())
|
||||
return;
|
||||
|
@ -113,10 +113,9 @@ void ftExtraList::hashAFile()
|
|||
/* hash it! */
|
||||
std::string name, hash;
|
||||
//uint64_t size;
|
||||
if (RsDirUtil::hashFile(details.info.path, details.info.fname,
|
||||
details.info.hash, details.info.size))
|
||||
if (RsDirUtil::hashFile(details.info.path, details.info.fname, details.info.hash, details.info.size))
|
||||
{
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
/* stick it in the available queue */
|
||||
mFiles[details.info.hash] = details;
|
||||
|
@ -146,7 +145,7 @@ bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash,
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
FileDetails details;
|
||||
|
||||
|
@ -166,11 +165,9 @@ bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags)
|
||||
bool ftExtraList::removeExtraFile(const RsFileHash& hash)
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) flags;
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << "ftExtraList::removeExtraFile()";
|
||||
std::cerr << " hash: " << hash;
|
||||
|
@ -179,7 +176,7 @@ bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags f
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
mHashOfHash.erase(makeEncryptedHash(hash)) ;
|
||||
|
||||
|
@ -230,14 +227,14 @@ bool ftExtraList::cleanupOldFiles()
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
time_t now = time(NULL);
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
std::list<RsFileHash> toRemove;
|
||||
|
||||
for( std::map<RsFileHash, FileDetails>::iterator it = mFiles.begin(); it != mFiles.end(); ++it) /* check timestamps */
|
||||
if ((time_t)it->second.info.age < now)
|
||||
if ((rstime_t)it->second.info.age < now)
|
||||
toRemove.push_back(it->first);
|
||||
|
||||
if (toRemove.size() > 0)
|
||||
|
@ -286,7 +283,7 @@ bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequ
|
|||
#endif
|
||||
|
||||
/* add into queue */
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
FileDetails details(path, period, flags);
|
||||
details.info.age = time(NULL) + period;
|
||||
|
@ -305,7 +302,7 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info)
|
|||
RsFileHash hash;
|
||||
{
|
||||
/* Find in the path->hash map */
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
std::map<std::string, RsFileHash>::iterator it;
|
||||
if (mHashedList.end() == (it = mHashedList.find(path)))
|
||||
|
@ -420,7 +417,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(extMutex);
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
|
||||
std::map<RsFileHash, FileDetails>::const_iterator it;
|
||||
|
@ -453,7 +450,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
time_t ts = time(NULL);
|
||||
rstime_t ts = time(NULL);
|
||||
|
||||
|
||||
std::list<RsItem *>::iterator it;
|
||||
|
@ -478,7 +475,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
fclose(fd);
|
||||
fd = NULL ;
|
||||
|
||||
if (ts > (time_t)fi->file.age)
|
||||
if (ts > (rstime_t)fi->file.age)
|
||||
{
|
||||
/* to old */
|
||||
cleanupEntry(fi->file.path, TransferRequestFlags(fi->flags));
|
||||
|
@ -489,8 +486,8 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
/* add into system */
|
||||
FileDetails file;
|
||||
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
FileDetails details;
|
||||
|
||||
details.info.path = fi->file.path;
|
||||
|
@ -513,3 +510,12 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ftExtraList::getExtraFileList(std::vector<FileInfo>& files) const
|
||||
{
|
||||
RS_STACK_MUTEX(extMutex);
|
||||
|
||||
files.clear();
|
||||
|
||||
for(auto it(mFiles.begin());it!=mFiles.end();++it)
|
||||
files.push_back(it->second.info);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include "util/rsthreads.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "util/rstime.h"
|
||||
|
||||
class FileDetails
|
||||
{
|
||||
|
@ -117,11 +118,13 @@ public:
|
|||
bool addExtraFile(std::string path, const RsFileHash &hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
|
||||
bool removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
bool removeExtraFile(const RsFileHash& hash);
|
||||
bool moveExtraFile(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath);
|
||||
|
||||
|
||||
uint32_t size() const { return mFiles.size() ; }
|
||||
|
||||
/***
|
||||
* Hash file, and add to the files,
|
||||
* file is removed after period.
|
||||
|
@ -137,6 +140,12 @@ public:
|
|||
**/
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
/*!
|
||||
* \brief getExtraFileList
|
||||
* Retrieves the list for display purposes
|
||||
*/
|
||||
void getExtraFileList(std::vector<FileInfo>& files) const ;
|
||||
|
||||
/***
|
||||
* Thread Main Loop
|
||||
**/
|
||||
|
@ -146,6 +155,7 @@ public:
|
|||
* Configuration - store extra files.
|
||||
*
|
||||
**/
|
||||
|
||||
protected:
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem*>&);
|
||||
|
@ -168,7 +178,7 @@ private:
|
|||
std::map<RsFileHash, FileDetails> mFiles;
|
||||
std::map<RsFileHash, RsFileHash> mHashOfHash; /* sha1(hash) map so as to answer requests to encrypted transfers */
|
||||
|
||||
time_t cleanup ;
|
||||
rstime_t cleanup ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "ftfilecreator.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
#include <sys/stat.h>
|
||||
#include <util/rsdiscspace.h>
|
||||
#include <util/rsdir.h>
|
||||
|
@ -63,7 +63,7 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const RsFil
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
_creation_time = now ;
|
||||
|
||||
struct stat64 buf;
|
||||
|
@ -143,12 +143,12 @@ bool ftFileCreator::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32_
|
|||
return false ;
|
||||
}
|
||||
|
||||
time_t ftFileCreator::creationTimeStamp()
|
||||
rstime_t ftFileCreator::creationTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
return _creation_time ;
|
||||
}
|
||||
time_t ftFileCreator::lastRecvTimeStamp()
|
||||
rstime_t ftFileCreator::lastRecvTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
return _last_recv_time_t ;
|
||||
|
@ -520,7 +520,7 @@ bool ftFileCreator::getMissingChunk(const RsPeerId& peer_id,uint32_t size_hint,u
|
|||
locked_printChunkMap();
|
||||
#endif
|
||||
source_chunk_map_needed = false ;
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
// 0 - is there a faulting chunk that would need to be asked again ?
|
||||
|
||||
|
|
|
@ -103,8 +103,8 @@ class ftFileCreator: public ftFileProvider
|
|||
void getSourcesList(uint32_t chunk_number,std::vector<RsPeerId>& sources) ;
|
||||
|
||||
// Returns resets the time stamp of the last data receive.
|
||||
time_t lastRecvTimeStamp() ;
|
||||
time_t creationTimeStamp() ;
|
||||
rstime_t lastRecvTimeStamp() ;
|
||||
rstime_t creationTimeStamp() ;
|
||||
|
||||
// actually store data in the file, and update chunks info
|
||||
//
|
||||
|
@ -144,8 +144,8 @@ class ftFileCreator: public ftFileProvider
|
|||
|
||||
ChunkMap chunkMap ;
|
||||
|
||||
time_t _last_recv_time_t ; /// last time stamp when data was received. Used for queue control.
|
||||
time_t _creation_time ; /// time at which the file creator was created. Used to spot long-inactive transfers.
|
||||
rstime_t _last_recv_time_t ; /// last time stamp when data was received. Used for queue control.
|
||||
rstime_t _creation_time ; /// time at which the file creator was created. Used to spot long-inactive transfers.
|
||||
};
|
||||
|
||||
#endif // FT_FILE_CREATOR_HEADER
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "util/rsdir.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
/********
|
||||
* #define DEBUG_FT_FILE_PROVIDER 1
|
||||
|
@ -41,7 +41,7 @@
|
|||
#include <iomanip>
|
||||
#endif
|
||||
|
||||
static const time_t UPLOAD_CHUNK_MAPS_TIME = 20 ; // time to ask for a new chunkmap from uploaders in seconds.
|
||||
static const rstime_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 RsFileHash& hash)
|
||||
: mSize(size), hash(hash), file_name(path), fd(NULL), ftcMutex("ftFileProvider")
|
||||
|
@ -122,7 +122,7 @@ bool ftFileProvider::FileDetails(FileInfo &info)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration)
|
||||
bool ftFileProvider::purgeOldPeers(rstime_t now,uint32_t max_duration)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -232,7 +232,7 @@ bool ftFileProvider::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32
|
|||
|
||||
// This creates the peer info, and updates it.
|
||||
//
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
uploading_peers[peer_id].updateStatus(offset,data_size,now) ;
|
||||
|
||||
#ifdef DEBUG_TRANSFERS
|
||||
|
@ -254,7 +254,7 @@ bool ftFileProvider::getFileData(const RsPeerId& peer_id,uint64_t offset, uint32
|
|||
return 1;
|
||||
}
|
||||
|
||||
void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_size,time_t now)
|
||||
void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_size,rstime_t now)
|
||||
{
|
||||
lastTS = now ;
|
||||
long int diff = (long int)now - (long int)lastTS_t ; // in bytes/s. Average over multiple samples
|
||||
|
@ -293,7 +293,7 @@ void ftFileProvider::getClientMap(const RsPeerId& peer_id,CompressedChunkMap& cm
|
|||
|
||||
PeerUploadInfo& pui(uploading_peers[peer_id]) ;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
if(now - pui.client_chunk_map_stamp > UPLOAD_CHUNK_MAPS_TIME)
|
||||
{
|
||||
|
|
|
@ -65,7 +65,7 @@ class ftFileProvider
|
|||
|
||||
// Removes inactive peers from the client list. Returns true if all peers have been removed.
|
||||
//
|
||||
bool purgeOldPeers(time_t now,uint32_t max_duration) ;
|
||||
bool purgeOldPeers(rstime_t now,uint32_t max_duration) ;
|
||||
|
||||
const RsFileHash& fileHash() const { return hash ; }
|
||||
const std::string& fileName() const { return file_name ; }
|
||||
|
@ -88,12 +88,12 @@ class ftFileProvider
|
|||
PeerUploadInfo()
|
||||
: req_loc(0),req_size(1), lastTS_t(0), lastTS(0),transfer_rate(0), total_size(0), client_chunk_map_stamp(0) {}
|
||||
|
||||
void updateStatus(uint64_t offset,uint32_t data_size,time_t now) ;
|
||||
void updateStatus(uint64_t offset,uint32_t data_size,rstime_t now) ;
|
||||
|
||||
uint64_t req_loc;
|
||||
uint32_t req_size;
|
||||
time_t lastTS_t; // used for estimating transfer rate.
|
||||
time_t lastTS; // last update time (for purging)
|
||||
rstime_t lastTS_t; // used for estimating transfer rate.
|
||||
rstime_t lastTS; // last update time (for purging)
|
||||
|
||||
// these two are used for speed estimation
|
||||
float transfer_rate ;
|
||||
|
@ -101,7 +101,7 @@ class ftFileProvider
|
|||
|
||||
// Info about what the downloading peer already has
|
||||
CompressedChunkMap client_chunk_map ;
|
||||
time_t client_chunk_map_stamp ;
|
||||
rstime_t client_chunk_map_stamp ;
|
||||
};
|
||||
|
||||
// Contains statistics (speed, peer name, etc.) of all uploading peers for that file.
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#include "util/rsprint.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
/***
|
||||
* #define SERVER_DEBUG 1
|
||||
|
@ -62,8 +62,8 @@
|
|||
#define FTSERVER_DEBUG() std::cerr << time(NULL) << " : FILE_SERVER : " << __FUNCTION__ << " : "
|
||||
#define FTSERVER_ERROR() std::cerr << "(EE) FILE_SERVER ERROR : "
|
||||
|
||||
static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
|
||||
static const time_t FILE_TRANSFER_MAX_DELAY_BEFORE_DROP_USAGE_RECORD = 10 ; // keep usage records for 10 secs at most.
|
||||
static const rstime_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
|
||||
static const rstime_t FILE_TRANSFER_MAX_DELAY_BEFORE_DROP_USAGE_RECORD = 10 ; // keep usage records for 10 secs at most.
|
||||
|
||||
/* Setup */
|
||||
ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc)
|
||||
|
@ -174,8 +174,11 @@ void ftServer::SetupFtServer()
|
|||
void ftServer::connectToFileDatabase(p3FileDatabase *fdb)
|
||||
{
|
||||
mFileDatabase = fdb ;
|
||||
|
||||
mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_LOCAL); // due to a bug in addSearchModule, modules can only be added one by one. Using | between flags wont work.
|
||||
mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_REMOTE);
|
||||
|
||||
mFileDatabase->setExtraList(mFtExtra);
|
||||
}
|
||||
void ftServer::connectToTurtleRouter(p3turtle *fts)
|
||||
{
|
||||
|
@ -674,9 +677,10 @@ bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t
|
|||
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags)
|
||||
bool ftServer::ExtraFileRemove(const RsFileHash& hash)
|
||||
{
|
||||
return mFtExtra->removeExtraFile(hash, flags);
|
||||
mFileDatabase->removeExtraFile(hash);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags)
|
||||
|
@ -707,14 +711,9 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags
|
|||
return mFileDatabase->RequestDirDetails(ref,details,flags) ;
|
||||
}
|
||||
|
||||
bool ftServer::requestDirDetails( DirDetails& details, std::uintptr_t handle,
|
||||
FileSearchFlags flags )
|
||||
uint32_t ftServer::getType(void *ref, FileSearchFlags flags)
|
||||
{
|
||||
return RequestDirDetails(reinterpret_cast<void*>(handle), details, flags);
|
||||
}
|
||||
uint32_t ftServer::getType(void *ref, FileSearchFlags /* flags */)
|
||||
{
|
||||
return mFileDatabase->getType(ref) ;
|
||||
return mFileDatabase->getType(ref,flags) ;
|
||||
}
|
||||
/***************************************************************/
|
||||
/******************** Search Interface *************************/
|
||||
|
@ -1622,8 +1621,8 @@ int ftServer::tick()
|
|||
if(handleIncoming())
|
||||
moreToTick = true;
|
||||
|
||||
static time_t last_law_priority_tasks_handling_time = 0 ;
|
||||
time_t now = time(NULL) ;
|
||||
static rstime_t last_law_priority_tasks_handling_time = 0 ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
if(last_law_priority_tasks_handling_time + FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD < now)
|
||||
{
|
||||
|
@ -1663,10 +1662,10 @@ bool ftServer::checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash)
|
|||
|
||||
// Find the latest records for this pid.
|
||||
|
||||
std::map<RsFileHash,time_t>& tmap(mUploadLimitMap[pid]) ;
|
||||
std::map<RsFileHash,time_t>::iterator it ;
|
||||
std::map<RsFileHash,rstime_t>& tmap(mUploadLimitMap[pid]) ;
|
||||
std::map<RsFileHash,rstime_t>::iterator it ;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
// If the limit has been decresed, we arbitrarily drop some ongoing slots.
|
||||
|
||||
|
@ -1691,7 +1690,7 @@ bool ftServer::checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash)
|
|||
for(it = tmap.begin();it!=tmap.end() && cleaned<2;)
|
||||
if(it->second + FILE_TRANSFER_MAX_DELAY_BEFORE_DROP_USAGE_RECORD < now)
|
||||
{
|
||||
std::map<RsFileHash,time_t>::iterator tmp(it) ;
|
||||
std::map<RsFileHash,rstime_t>::iterator tmp(it) ;
|
||||
++tmp;
|
||||
tmap.erase(it) ;
|
||||
it = tmp;
|
||||
|
@ -1856,7 +1855,7 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
|||
bool ftServer::turtleSearchRequest(
|
||||
const std::string& matchString,
|
||||
const std::function<void (const std::list<TurtleFileInfo>& results)>& multiCallback,
|
||||
std::time_t maxWait )
|
||||
rstime_t maxWait )
|
||||
{
|
||||
if(matchString.empty())
|
||||
{
|
||||
|
|
|
@ -149,7 +149,7 @@ public:
|
|||
virtual bool turtleSearchRequest(
|
||||
const std::string& matchString,
|
||||
const std::function<void (const std::list<TurtleFileInfo>& results)>& multiCallback,
|
||||
std::time_t maxWait = 300 );
|
||||
rstime_t maxWait = 300 );
|
||||
|
||||
virtual TurtleSearchRequestId turtleSearch(const std::string& string_to_match) ;
|
||||
virtual TurtleSearchRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) ;
|
||||
|
@ -180,7 +180,7 @@ public:
|
|||
* Extra List Access
|
||||
***/
|
||||
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 ExtraFileRemove(const RsFileHash& hash);
|
||||
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, const RsFileHash& hash, uint64_t size, std::string destpath);
|
||||
|
@ -331,7 +331,7 @@ private:
|
|||
|
||||
std::map<RsFileHash,RsFileHash> mEncryptedHashes ; // This map is such that sha1(it->second) = it->first
|
||||
std::map<RsPeerId,RsFileHash> mEncryptedPeerIds ; // This map holds the hash to be used with each peer id
|
||||
std::map<RsPeerId,std::map<RsFileHash,time_t> > mUploadLimitMap ;
|
||||
std::map<RsPeerId,std::map<RsFileHash,rstime_t> > mUploadLimitMap ;
|
||||
|
||||
/** Store search callbacks with timeout*/
|
||||
std::map<
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
* #define FT_DEBUG 1
|
||||
*****/
|
||||
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
|
||||
#include "retroshare/rsturtle.h"
|
||||
#include "fttransfermodule.h"
|
||||
|
@ -285,7 +285,7 @@ void ftTransferModule::resetActvTimeStamp()
|
|||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
_last_activity_time_stamp = time(NULL);
|
||||
}
|
||||
time_t ftTransferModule::lastActvTimeStamp()
|
||||
rstime_t ftTransferModule::lastActvTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
return _last_activity_time_stamp ;
|
||||
|
@ -693,7 +693,7 @@ void ftTransferModule::adjustSpeed()
|
|||
bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
|
||||
{
|
||||
/* how long has it been? */
|
||||
time_t ts = time(NULL);
|
||||
rstime_t ts = time(NULL);
|
||||
|
||||
int ageRecv = ts - info.recvTS;
|
||||
int ageReq = ts - info.lastTS;
|
||||
|
@ -865,7 +865,7 @@ bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset, uint
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
time_t ts = time(NULL);
|
||||
rstime_t ts = time(NULL);
|
||||
info.recvTS = ts;
|
||||
info.nResets = 0;
|
||||
info.state = PQIPEER_DOWNLOADING;
|
||||
|
|
|
@ -76,15 +76,15 @@ public:
|
|||
double desiredRate;
|
||||
double actualRate;
|
||||
|
||||
time_t lastTS; /* last Request */
|
||||
time_t recvTS; /* last Recv */
|
||||
rstime_t lastTS; /* last Request */
|
||||
rstime_t recvTS; /* last Recv */
|
||||
uint32_t lastTransfers; /* data recvd in last second */
|
||||
uint32_t nResets; /* count to disable non-existant files */
|
||||
|
||||
/* rrt rate control */
|
||||
uint32_t rtt; /* last rtt */
|
||||
bool rttActive; /* have we initialised an rtt measurement */
|
||||
time_t rttStart; /* ts of request */
|
||||
rstime_t rttStart; /* ts of request */
|
||||
uint64_t rttOffset; /* end of request */
|
||||
float mRateIncrease; /* current rate */
|
||||
};
|
||||
|
@ -156,7 +156,7 @@ public:
|
|||
void setDownloadPriority(DwlSpeed p) { mPriority =p ; }
|
||||
|
||||
// read/reset the last time the transfer module was active (either wrote data, or was solicitaded by clients)
|
||||
time_t lastActvTimeStamp() ;
|
||||
rstime_t lastActvTimeStamp() ;
|
||||
void resetActvTimeStamp() ;
|
||||
|
||||
private:
|
||||
|
@ -185,7 +185,7 @@ private:
|
|||
double desiredRate;
|
||||
double actualRate;
|
||||
|
||||
time_t _last_activity_time_stamp ;
|
||||
rstime_t _last_activity_time_stamp ;
|
||||
|
||||
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue