diff --git a/include/opendht/value.h b/include/opendht/value.h index 320fd27e5fa7ee1dcada200b89e4b46a8adcd4a2..31e3ac418d426f3263db29eb75535e5ecd6d071d 100644 --- a/include/opendht/value.h +++ b/include/opendht/value.h @@ -116,13 +116,15 @@ struct ValueType { */ struct Value { - enum class Field { + enum class Field : int { None = 0, - Id, - ValueType, - OwnerPk, - SeqNum, - UserType, + Id, /* Value::id */ + ValueType, /* Value::type */ + OwnerPk, /* Value::owner */ + SeqNum, /* Value::seq */ + UserType, /* Value::user_type */ + + COUNT /* the total number of fields */ }; typedef uint64_t Id; @@ -814,13 +816,13 @@ struct Query { static const std::string QUERY_PARSE_ERROR; - Query(Select s = {}, Where w = {}) : select(s), where(w) { }; + Query(Select s = {}, Where w = {}, bool none = false) : select(s), where(w), none(none) { }; /** * Initializes a query based on a SQL-ish formatted string. The abstract * form of such a string is the following: * - * [SELECT <$field$> [WHERE <$field$=$value$>]] + * [SELECT $field$ [WHERE $field$=$value$]] * * where * @@ -864,6 +866,7 @@ struct Query Select select {}; Where where {}; + bool none {false}; /* When true, any query satisfies this. */ }; /*! diff --git a/src/dht.cpp b/src/dht.cpp index e673724a41a3b980c1d63154ab611c7f8104dee3..e7f9f803dba0c7f836778a567fa0ade9b25a4881 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -1078,7 +1078,7 @@ Dht::searchSendGetValues(std::shared_ptr<Search> sr, SearchNode* pn, bool update auto cb = sr->callbacks.begin(); do { /* for all requests to send */ SearchNode* n = nullptr; - auto query = not sr->callbacks.empty() ? cb->second.query : std::make_shared<Query>(); + auto query = not sr->callbacks.empty() ? cb->second.query : std::make_shared<Query>(Select {}, Where {}, true); const time_point up = not sr->callbacks.empty() and update ? sr->getLastGetTime(query) : time_point::min(); @@ -1104,14 +1104,7 @@ Dht::searchSendGetValues(std::shared_ptr<Search> sr, SearchNode* pn, bool update n->getStatus[query] = network_engine.sendFindNode(n->node, sr->id, -1, - [this,ws,query](const Request& status, NetworkEngine::RequestAnswer&& answer) { - if (auto sr = ws.lock()) { - if (auto sn = sr->getNode(status.node)) { - sn->getStatus.erase(query); - } - } - searchNodeGetDone(status, std::forward<NetworkEngine::RequestAnswer>(answer), ws, query); - }, + std::bind(&Dht::searchNodeGetDone, this, _1, _2, ws, query), std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, query)); } else { /* 'get' request */ diff --git a/src/value.cpp b/src/value.cpp index fc8eecd3374f9d45a50694bfa83da67e218a4a64..a1f4b628254dc01bff919ef7951a687b9ee5b832 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -209,7 +209,7 @@ FieldValueIndex::FieldValueIndex(const Value& v, Select s) }); } else { index.clear(); - for (size_t f = 1 ; f < 6 ; ++f) + for (size_t f = 1 ; f < static_cast<int>(Value::Field::COUNT) ; ++f) index[static_cast<Value::Field>(f)] = {}; } for (const auto& fvp : index) { @@ -421,7 +421,7 @@ bool Where::isSatisfiedBy(const Where& ow) const { } bool Query::isSatisfiedBy(const Query& q) const { - return where.isSatisfiedBy(q.where) and select.isSatisfiedBy(q.select); + return none or (where.isSatisfiedBy(q.where) and select.isSatisfiedBy(q.select)); } std::ostream& operator<<(std::ostream& s, const dht::Select& select) {