From 90c24e7135a08b4abeb068fdc137d287fd3f9504 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Oct 2014 21:30:28 +0000 Subject: [PATCH] improved anti-flooding stategy in g-router git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7624 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/grouter/groutermatrix.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/grouter/groutermatrix.cc b/libretroshare/src/grouter/groutermatrix.cc index a5732dd70..bafd8891c 100644 --- a/libretroshare/src/grouter/groutermatrix.cc +++ b/libretroshare/src/grouter/groutermatrix.cc @@ -52,12 +52,16 @@ bool GRouterMatrix::addRoutingClue(const GRouterKeyId& key_id,const RsPeerId& so // Prevent flooding. Happens in two scenarii: // 1 - a user restarts RS very often => keys get republished for some reason // 2 - a user intentionnaly floods a key - // - if(!lst.empty() && lst.front().friend_id == fid && lst.front().time_stamp + RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS > now) - { - std::cerr << "GRouterMatrix::addRoutingClue(): too many clues for key " << key_id.toStdString() << " from friend " << source_friend << " in a small interval of " << now - lst.front().time_stamp << " seconds. Flooding?" << std::endl; - return false ; - } + // + // Solution is to look for all recorded events, and not add any new event if an event came from the same friend + // too close in the past. Going through the list is not costly since it is bounded to RS_GROUTER_MATRIX_MAX_HIT_ENTRIES elemts. + + for(std::list::const_iterator mit(lst.begin());mit!=lst.end();++mit) + if((*mit).friend_id == fid && (*mit).time_stamp + RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS > now) + { + std::cerr << "GRouterMatrix::addRoutingClue(): too many clues for key " << key_id.toStdString() << " from friend " << source_friend << " in a small interval of " << now - lst.front().time_stamp << " seconds. Flooding?" << std::endl; + return false ; + } lst.push_front(rc) ; // create it if necessary