added filter in p3turtle against banned hashes in tunnel requests and search results

This commit is contained in:
csoler 2018-08-22 21:57:56 +02:00
parent 365464623a
commit 3055897425
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
6 changed files with 50 additions and 0 deletions

View File

@ -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) ;

View File

@ -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) ;

View File

@ -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);
}

View File

@ -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

View File

@ -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.

View File

@ -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)) ;