mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added filter in p3turtle against banned hashes in tunnel requests and search results
This commit is contained in:
parent
365464623a
commit
3055897425
@ -1919,6 +1919,17 @@ bool p3FileDatabase::unbanFile(const RsFileHash& real_file_hash)
|
||||
IndicateConfigChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3FileDatabase::isFileBanned(const RsFileHash& hash)
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
||||
RsFileHash hash_of_hash ;
|
||||
ftServer::encryptHash(hash,hash_of_hash) ;
|
||||
|
||||
return mBannedFileList.find(hash) != mBannedFileList.end() || mBannedFileList.find(hash_of_hash) != mBannedFileList.end() ;
|
||||
}
|
||||
|
||||
bool p3FileDatabase::getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files)
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
@ -142,6 +142,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
||||
|
||||
bool banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) ;
|
||||
bool unbanFile(const RsFileHash& real_file_hash);
|
||||
bool isFileBanned(const RsFileHash& hash) ;
|
||||
bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) ;
|
||||
bool trustFriendNodesForBannedFiles() const ;
|
||||
void setTrustFriendNodesForBannedFiles(bool b) ;
|
||||
|
@ -1846,3 +1846,8 @@ bool ftServer::getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& b
|
||||
{
|
||||
return mFileDatabase->getPrimaryBannedFilesList(banned_files) ;
|
||||
}
|
||||
|
||||
bool ftServer::isHashBanned(const RsFileHash& hash)
|
||||
{
|
||||
return mFileDatabase->isFileBanned(hash);
|
||||
}
|
||||
|
@ -195,6 +195,7 @@ public:
|
||||
virtual int banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) ;
|
||||
virtual int unbanFile(const RsFileHash& real_file_hash);
|
||||
virtual bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) ;
|
||||
virtual bool isHashBanned(const RsFileHash& hash);
|
||||
|
||||
/***
|
||||
* Utility Functions
|
||||
|
@ -271,6 +271,7 @@ public:
|
||||
virtual int banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) =0;
|
||||
virtual int unbanFile(const RsFileHash& real_file_hash)=0;
|
||||
virtual bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) =0;
|
||||
virtual bool isHashBanned(const RsFileHash& hash) =0;
|
||||
|
||||
/***
|
||||
* Utility Functions.
|
||||
|
@ -1109,6 +1109,27 @@ void p3turtle::performLocalSearch_files(RsTurtleFileSearchRequestItem *item,uint
|
||||
|
||||
void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
||||
{
|
||||
// Filter out banned hashes from the result.
|
||||
|
||||
RsTurtleFTSearchResultItem *ftsr_tmp = dynamic_cast<RsTurtleFTSearchResultItem*>(item) ;
|
||||
|
||||
if(ftsr_tmp != NULL)
|
||||
{
|
||||
for(auto it(ftsr_tmp->result.begin());it!=ftsr_tmp->result.end();)
|
||||
if( rsFiles->isHashBanned((*it).hash) )
|
||||
{
|
||||
std::cerr << "(II) filtering out banned hash " << (*it).hash << " from turtle result " << std::hex << item->request_id << std::dec << std::endl;
|
||||
it = ftsr_tmp->result.erase(it);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
|
||||
if(ftsr_tmp->result.empty())
|
||||
return ;
|
||||
}
|
||||
|
||||
// Then handle the result
|
||||
|
||||
std::list<std::pair<RsTurtleSearchResultItem*,RsTurtleClientService*> > results_to_notify_off_mutex ;
|
||||
|
||||
{
|
||||
@ -1525,6 +1546,16 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
item->print(std::cerr,0) ;
|
||||
#endif
|
||||
|
||||
// check first if the hash is in the ban list. If so, drop the request.
|
||||
|
||||
if(rsFiles->isHashBanned(item->file_hash))
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "(II) Rejecting tunnel request to ban hash " << item->file_hash << std::endl;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
|
||||
#ifdef TUNNEL_STATISTICS
|
||||
if(TS_request_bounces.find(item->request_id) != TS_request_bounces.end())
|
||||
TS_request_bounces[item->request_id].push_back(time(NULL)) ;
|
||||
|
Loading…
Reference in New Issue
Block a user