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

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