From 41251fdd9e72a664ef1f0f87951c878de4a42435 Mon Sep 17 00:00:00 2001 From: RetroPooh Date: Fri, 15 Sep 2017 15:03:06 +0300 Subject: [PATCH] search spy --- libretroshare/src/retroshare/rsexpr.h | 4 +++- libretroshare/src/turtle/p3turtle.cc | 2 ++ libretroshare/src/turtle/p3turtle.h | 1 + libretroshare/src/turtle/rsturtleitem.h | 10 ++++++++-- libretroshare/src/util/rsexpr.cc | 11 +++++++++++ retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp | 3 +-- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/retroshare/rsexpr.h b/libretroshare/src/retroshare/rsexpr.h index 4cf9e7983..7dc5aeaf8 100644 --- a/libretroshare/src/retroshare/rsexpr.h +++ b/libretroshare/src/retroshare/rsexpr.h @@ -85,7 +85,9 @@ public: EXPR_SIZE_MB = 8 } token ; static Expression *toExpr(const LinearizedExpression& e) ; - + + std::string GetStrings(); + private: static Expression *toExpr(const LinearizedExpression& e,int&,int&,int&) ; static void readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list& strings,bool& b,StringOperator& op) ; diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 215e68c25..a31c180b6 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -907,6 +907,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item) req.origin = item->PeerId() ; req.time_stamp = time(NULL) ; req.depth = item->depth ; + req.keywords = item->GetKeywords() ; // If it's not for us, perform a local search. If something found, forward the search result back. @@ -2079,6 +2080,7 @@ void p3turtle::getInfo( std::vector >& hashes_info, info.source_peer_id = it->second.origin ; info.age = now - it->second.time_stamp ; info.depth = it->second.depth ; + info.keywords = it->second.keywords ; search_reqs_info.push_back(info) ; } diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index 36324f941..c75b882f8 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -172,6 +172,7 @@ class TurtleRequestInfo uint32_t time_stamp ; // last time the tunnel was actually used. Used for cleaning old tunnels. int depth ; // depth of the request. Used to optimize tunnel length. std::set responses; // responses to this request. Useful to avoid spamming tunnel responses. + std::string keywords; }; class TurtleTunnel diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index d4d061865..d70163194 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -71,7 +71,9 @@ class RsTurtleSearchRequestItem: public RsTurtleItem virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods virtual void performLocalSearch(std::list&) const = 0 ; // abstracts the search method - + + virtual std::string GetKeywords() = 0; + uint32_t request_id ; // randomly generated request id. uint16_t depth ; // Used for limiting search depth. }; @@ -82,7 +84,9 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem RsTurtleStringSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {} std::string match_string ; // string to match - + + std::string GetKeywords() { return match_string; } + virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; } virtual void performLocalSearch(std::list&) const ; @@ -99,6 +103,8 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem RsRegularExpression::LinearizedExpression expr ; // Reg Exp in linearised mode + std::string GetKeywords() { return expr.GetStrings(); } + virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; } virtual void performLocalSearch(std::list&) const ; diff --git a/libretroshare/src/util/rsexpr.cc b/libretroshare/src/util/rsexpr.cc index 7e35a1873..74a0699e3 100644 --- a/libretroshare/src/util/rsexpr.cc +++ b/libretroshare/src/util/rsexpr.cc @@ -199,6 +199,17 @@ void LinearizedExpression::readStringExpr(const LinearizedExpression& e,int& n_i strings.push_back(e._strings[n_strings++]) ; } +std::string LinearizedExpression::GetStrings() +{ + std::string str; + for (std::vector::const_iterator i = this->_strings.begin(); i != this->_strings.end(); ++i) + { + str += *i; + str += " "; + } + return str; +} + Expression *LinearizedExpression::toExpr(const LinearizedExpression& e,int& n_tok,int& n_ints,int& n_strings) { LinearizedExpression::token tok = static_cast(e._tokens[n_tok++]) ; diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index 4607a2541..8d837e957 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -795,8 +795,7 @@ void SearchDialog::advancedSearch(RsRegularExpression::Expression* expression) TurtleRequestId req_id = rsTurtle->turtleSearch(e) ; // This will act before turtle results come to the interface, thanks to the signals scheduling policy. - // The text "bool exp" should be replaced by an appropriate text describing the actual search. - initSearchResult("bool exp",req_id, ui.FileTypeComboBox->currentIndex(), true) ; + initSearchResult(QString::fromStdString(e.GetStrings()),req_id, ui.FileTypeComboBox->currentIndex(), true) ; rsFiles -> SearchBoolExp(expression, results, RS_FILE_HINTS_REMOTE);// | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);