diff --git a/include/opendht/indexation/pht.h b/include/opendht/indexation/pht.h index 815fb1c1ae2ecaa31f8f28f8378a7b465f73750c..aed1921c44046b9dfb45cb2255bd5c9cfadb30fb 100644 --- a/include/opendht/indexation/pht.h +++ b/include/opendht/indexation/pht.h @@ -42,6 +42,8 @@ struct Prefix { return Prefix(*this, len); } + Prefix getFullSize() { return Prefix(*this, content_.size()*8); } + /** * This methods gets the prefix of its sibling in the PHT structure. * diff --git a/src/indexation/pht.cpp b/src/indexation/pht.cpp index 1b2e2636a95a6311487d780621213f22742ffedf..4ac390a514447c199f5fed529803f2ee4c706936 100644 --- a/src/indexation/pht.cpp +++ b/src/indexation/pht.cpp @@ -24,6 +24,12 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi, if (is_leaf or *lo > *hi) { // leaf node if (cb) + if (vals->size() == 0 and max_common_prefix_len and mid > 0) { + auto p_ = (p.getPrefix(mid)).getSibling().getFullSize(); + *lo = mid; + *hi = p_.size_; + lookupStep(p_, lo, hi, vals, cb, done_cb, max_common_prefix_len); + } cb(*vals, p.getPrefix(mid)); if (done_cb) done_cb(true); diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp index 1480b25fe3964cdf31f366dc8018767cf1eef32d..ee3199be9b0cc1eaac0b6c3bbbaa16a5f369f863 100644 --- a/tools/dhtnode.cpp +++ b/tools/dhtnode.cpp @@ -60,16 +60,16 @@ void print_help() { << " lr Print the full current routing table of this node" << std::endl; std::cout << std::endl << "Operations on the DHT:" << std::endl - << " b ip:port Ping potential node at given IP address/port." << std::endl - << " g [key] [where] Get values at [key]. [where] is the 'where' part of an SQL-ish string." << std::endl - << " q [key] [query] Query field values at [key]. [query] is an SQL-ish string." << std::endl - << " l [key] [where] Listen for value changes at [key]. [where] is the 'where' part of an SQL-ish string." << std::endl - << " p [key] [str] Put string value at [key]." << std::endl - << " s [key] [str] Put string value at [key], signed with our generated private key." << std::endl - << " e [key] [dest] [str] Put string value at [key], encrypted for [dest] with its public key (if found)." << std::endl; + << " b <ip:port> Ping potential node at given IP address/port." << std::endl + << " g <key> Get values at <key>." << std::endl + << " l <key> Listen for value changes at <key>." << std::endl + << " p <key> <str> Put string value at <key>." << std::endl + << " s <key> <str> Put string value at <key>, signed with our generated private key." << std::endl + << " e <key> <dest> <str> Put string value at <key>, encrypted for <dest> with its public key (if found)." << std::endl; std::cout << std::endl << "Indexation operations on the DHT:" << std::endl - << " il [name] [key] Lookup the index named [name] with the key [key]." << std::endl - << " ii [name] [key] [value] Inserts the value [value] under the key [key] in the index named [name]." << std::endl + << " il <name> <key> [exact match] Lookup the index named <name> with the key <key>." << std::endl + << " Set [exact match] to 'false' for inexact match lookup." << std::endl + << " ii <name> <key> <value> Inserts the value <value> under the key <key> in the index named <name>." << std::endl << std::endl; } @@ -265,6 +265,8 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa }); } else if (op == "il") { + std::string exact_match; + iss >> exact_match; indexes.at(index).lookup(createPhtKey(parseStringMap(keystr)), [=](std::vector<std::shared_ptr<indexation::Value>>& vals, indexation::Prefix p) { std::cout << "Pht::lookup: at prefix \"" << p.toString() << "\"" << ", hash is " << p.hash() << std::endl; @@ -278,7 +280,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa if (not ok) { std::cout << "Pht::lookup: dht Get failed." << std::endl; } - } + }, exact_match.size() != 0 and exact_match == "false" ? false : true ); } else if (op == "ii") {