diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index cc9f6cfc3..e1ddd059c 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -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& banned_files) { RS_STACK_MUTEX(mFLSMtx) ; diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 65ed7b6ef..c58c9989a 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -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& banned_files) ; bool trustFriendNodesForBannedFiles() const ; void setTrustFriendNodesForBannedFiles(bool b) ; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 90ba9beac..d517a0114 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1846,3 +1846,8 @@ bool ftServer::getPrimaryBannedFilesList(std::map& b { return mFileDatabase->getPrimaryBannedFilesList(banned_files) ; } + +bool ftServer::isHashBanned(const RsFileHash& hash) +{ + return mFileDatabase->isFileBanned(hash); +} diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 7e9ccde6a..8e420092f 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -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& banned_files) ; + virtual bool isHashBanned(const RsFileHash& hash); /*** * Utility Functions diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 0af2708d6..918f1ab2f 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -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& banned_files) =0; + virtual bool isHashBanned(const RsFileHash& hash) =0; /*** * Utility Functions. diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index fcb77b134..36b4383a9 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -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(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 > 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)) ;