mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 06:02:41 -04:00
fixed merged with upstream/master
This commit is contained in:
commit
c9b30f5a72
88 changed files with 3867 additions and 977 deletions
|
@ -71,7 +71,8 @@ ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc)
|
|||
mPeerMgr(pm), mServiceCtrl(sc),
|
||||
mFileDatabase(NULL),
|
||||
mFtController(NULL), mFtExtra(NULL),
|
||||
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
|
||||
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer"),
|
||||
mSearchCallbacksMapMutex("ftServer callbacks map")
|
||||
{
|
||||
addSerialType(new RsFileTransferSerialiser()) ;
|
||||
}
|
||||
|
@ -425,7 +426,7 @@ void ftServer::requestDirUpdate(void *ref)
|
|||
}
|
||||
|
||||
/* Directory Handling */
|
||||
bool ftServer::setDownloadDirectory(std::string path)
|
||||
bool ftServer::setDownloadDirectory(const std::string& path)
|
||||
{
|
||||
return mFtController->setDownloadDirectory(path);
|
||||
}
|
||||
|
@ -435,7 +436,7 @@ std::string ftServer::getDownloadDirectory()
|
|||
return mFtController->getDownloadDirectory();
|
||||
}
|
||||
|
||||
bool ftServer::setPartialsDirectory(std::string path)
|
||||
bool ftServer::setPartialsDirectory(const std::string& path)
|
||||
{
|
||||
return mFtController->setPartialsDirectory(path);
|
||||
}
|
||||
|
@ -1630,6 +1631,7 @@ int ftServer::tick()
|
|||
mFtDataplex->deleteUnusedServers() ;
|
||||
mFtDataplex->handlePendingCrcRequests() ;
|
||||
mFtDataplex->dispatchReceivedChunkCheckSum() ;
|
||||
cleanTimedOutSearches();
|
||||
}
|
||||
|
||||
return moreToTick;
|
||||
|
@ -1820,6 +1822,24 @@ int ftServer::handleIncoming()
|
|||
**********************************
|
||||
*********************************/
|
||||
|
||||
void ftServer::receiveSearchResult(RsTurtleFTSearchResultItem *item)
|
||||
{
|
||||
bool hasCallback = false;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
auto cbpt = mSearchCallbacksMap.find(item->request_id);
|
||||
if(cbpt != mSearchCallbacksMap.end())
|
||||
{
|
||||
hasCallback = true;
|
||||
cbpt->second.first(item->result);
|
||||
}
|
||||
} // end RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
|
||||
if(!hasCallback)
|
||||
RsServer::notify()->notifyTurtleSearchResult(item->PeerId(),item->request_id, item->result );
|
||||
}
|
||||
|
||||
/***************************** CONFIG ****************************/
|
||||
|
||||
bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
||||
|
@ -1832,6 +1852,42 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::turtleSearchRequest(
|
||||
const std::string& matchString,
|
||||
const std::function<void (const std::list<TurtleFileInfo>& results)>& multiCallback,
|
||||
std::time_t maxWait )
|
||||
{
|
||||
if(matchString.empty())
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " match string can't be empty!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
TurtleRequestId sId = turtleSearch(matchString);
|
||||
|
||||
RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
mSearchCallbacksMap.emplace(
|
||||
sId,
|
||||
std::make_pair(
|
||||
multiCallback,
|
||||
std::chrono::system_clock::now() +
|
||||
std::chrono::seconds(maxWait) ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ftServer::cleanTimedOutSearches()
|
||||
{
|
||||
RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
auto now = std::chrono::system_clock::now();
|
||||
for( auto cbpt = mSearchCallbacksMap.begin();
|
||||
cbpt != mSearchCallbacksMap.end(); )
|
||||
if(cbpt->second.second <= now)
|
||||
cbpt = mSearchCallbacksMap.erase(cbpt);
|
||||
else ++cbpt;
|
||||
}
|
||||
|
||||
// Offensive content file filtering
|
||||
|
||||
int ftServer::banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size)
|
||||
|
@ -1851,3 +1907,5 @@ bool ftServer::isHashBanned(const RsFileHash& hash)
|
|||
{
|
||||
return mFileDatabase->isFileBanned(hash);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include <map>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
|
||||
#include "ft/ftdata.h"
|
||||
#include "turtle/turtleclientservice.h"
|
||||
|
@ -96,7 +98,7 @@ public:
|
|||
uint16_t serviceId() const { return RS_SERVICE_TYPE_FILE_TRANSFER ; }
|
||||
virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||
virtual void receiveTurtleData(const RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
//virtual void receiveSearchResult(RsTurtleSearchResultItem *item);// TODO
|
||||
virtual void receiveSearchResult(RsTurtleFTSearchResultItem *item);
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_type) const ;
|
||||
virtual RsServiceSerializer *serializer() { return this ; }
|
||||
|
||||
|
@ -143,6 +145,12 @@ public:
|
|||
virtual void setFilePermDirectDL(uint32_t perm) ;
|
||||
virtual uint32_t filePermDirectDL() ;
|
||||
|
||||
/// @see RsFiles
|
||||
virtual bool turtleSearchRequest(
|
||||
const std::string& matchString,
|
||||
const std::function<void (const std::list<TurtleFileInfo>& results)>& multiCallback,
|
||||
std::time_t maxWait = 300 );
|
||||
|
||||
virtual TurtleSearchRequestId turtleSearch(const std::string& string_to_match) ;
|
||||
virtual TurtleSearchRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) ;
|
||||
|
||||
|
@ -210,8 +218,8 @@ public:
|
|||
* Directory Handling
|
||||
***/
|
||||
virtual void requestDirUpdate(void *ref) ; // triggers the update of the given reference. Used when browsing.
|
||||
virtual bool setDownloadDirectory(std::string path);
|
||||
virtual bool setPartialsDirectory(std::string path);
|
||||
virtual bool setDownloadDirectory(const std::string& path);
|
||||
virtual bool setPartialsDirectory(const std::string& path);
|
||||
virtual std::string getDownloadDirectory();
|
||||
virtual std::string getPartialsDirectory();
|
||||
|
||||
|
@ -319,6 +327,18 @@ 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 ;
|
||||
|
||||
/** Store search callbacks with timeout*/
|
||||
std::map<
|
||||
TurtleRequestId,
|
||||
std::pair<
|
||||
std::function<void (const std::list<TurtleFileInfo>& results)>,
|
||||
std::chrono::system_clock::time_point >
|
||||
> mSearchCallbacksMap;
|
||||
RsMutex mSearchCallbacksMapMutex;
|
||||
|
||||
/// Cleanup mSearchCallbacksMap
|
||||
void cleanTimedOutSearches();
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue