From c9cbced0c8216621a8d612c25ac38004c9bca7ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Mon, 26 Feb 2018 18:03:43 -0500 Subject: [PATCH] build: make indexation optional --- CMakeLists.txt | 9 +++++++-- configure.ac | 7 +++++++ include/opendht.h | 2 ++ src/Makefile.am | 9 ++++++--- tools/dhtnode.cpp | 19 ++++++++++++++----- tools/tools_common.h | 2 ++ 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4332712d..1a594c79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ option (OPENDHT_PROXY_SERVER "Enable DHT proxy server, use Restbed and jsoncpp" option (OPENDHT_PUSH_NOTIFICATIONS "Enable push notifications support" OFF) option (OPENDHT_PROXY_SERVER_IDENTITY "Allow clients to use the node identity" OFF) option (OPENDHT_PROXY_CLIENT "Enable DHT proxy client, use Restbed and jsoncpp" OFF) +option (OPENDHT_INDEX "Build DHT indexation feature" OFF) find_package(Doxygen) option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND}) @@ -131,7 +132,6 @@ list (APPEND opendht_SOURCES src/network_engine.cpp src/securedht.cpp src/dhtrunner.cpp - src/indexation/pht.cpp src/log.cpp ) @@ -157,9 +157,14 @@ list (APPEND opendht_HEADERS include/opendht/log.h include/opendht/log_enable.h include/opendht.h - include/opendht/indexation/pht.h ) +if (OPENDHT_INDEX) + list (APPEND opendht_SOURCES src/indexation/pht.cpp) + list (APPEND opendht_HEADERS include/opendht/indexation/pht.h) + add_definitions(-DOPENDHT_INDEXATION) +endif() + if (OPENDHT_PROXY_SERVER) add_definitions(-DOPENDHT_PROXY_SERVER=true) if (OPENDHT_PROXY_SERVER_IDENTITY) diff --git a/configure.ac b/configure.ac index 7d051d72..2890f2ab 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,13 @@ AS_IF([test "x$enable_logs" != "xno"], [ AC_DEFINE([OPENDHT_LOG], [false], [Define if DHT logs are enabled]) ]) +dnl Check for indexation +AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--enable-indexation], [Enable DHT indexation])]) +AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation == xyes) +AS_IF([test "x$enable_indexation" = "xyes"], [ + AC_DEFINE([OPENDHT_INDEXATION], [1], [Define if DHT indexation is enabled]) +]) + dnl Check for Doxygen AC_ARG_ENABLE([doc], AS_HELP_STRING([--enable-doc], [Enable documentation generation (doxygen)])) AS_IF([test "x$enable_doc" = "xyes"], [ diff --git a/include/opendht.h b/include/opendht.h index e003a216..8d0154d3 100644 --- a/include/opendht.h +++ b/include/opendht.h @@ -24,4 +24,6 @@ #endif #include "opendht/log.h" #include "opendht/default_types.h" +#ifdef OPENDHT_INDEXATION #include "opendht/indexation/pht.h" +#endif diff --git a/src/Makefile.am b/src/Makefile.am index d21212a3..0af5b396 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,6 @@ libopendht_la_SOURCES = \ securedht.cpp \ dhtrunner.cpp \ default_types.cpp \ - indexation/pht.cpp \ log.cpp if WIN32 @@ -51,8 +50,7 @@ nobase_include_HEADERS = \ ../include/opendht/default_types.h \ ../include/opendht/log.h \ ../include/opendht/log_enable.h \ - ../include/opendht/rng.h \ - ../include/opendht/indexation/pht.h + ../include/opendht/rng.h if ENABLE_PROXY_SERVER libopendht_la_SOURCES += base64.h base64.cpp dht_proxy_server.cpp @@ -64,6 +62,11 @@ libopendht_la_SOURCES += dht_proxy_client.cpp nobase_include_HEADERS += ../include/opendht/dht_proxy_client.h ../include/opendht/dht_interface.h endif +if ENABLE_INDEXATION +libopendht_la_SOURCES += indexation/pht.cpp +nobase_include_HEADERS += ../include/opendht/indexation/pht.h +endif + clean-local: rm -rf libargon2.la diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp index 3d102fb7..b5a76405 100644 --- a/tools/dhtnode.cpp +++ b/tools/dhtnode.cpp @@ -90,11 +90,13 @@ void print_help() { << " 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; +#ifdef OPENDHT_INDEXATION std::cout << std::endl << "Indexation operations on the DHT:" << 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; +#endif } void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params @@ -111,7 +113,9 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params using_history(); #endif +#ifdef OPENDHT_INDEXATION std::map<std::string, indexation::Pht> indexes; +#endif while (true) { @@ -250,7 +254,13 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params } dht::InfoHash id; - if (op == "il" or op == "ii") { + if (op == "cl") { + std::string hash, rem; + iss >> hash >> rem; + dht->cancelListen(dht::InfoHash(hash), std::stoul(rem)); + } +#ifdef OPENDHT_INDEXATION + else if (op == "il" or op == "ii") { // Pht syntax iss >> index >> keystr; auto new_index = std::find_if(indexes.begin(), indexes.end(), @@ -271,11 +281,8 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params indexes.emplace(index, Pht {index, std::move(ks), dht}); } catch (std::invalid_argument& e) { std::cout << e.what() << std::endl; } } - } else if (op == "cl") { - std::string hash, rem; - iss >> hash >> rem; - dht->cancelListen(dht::InfoHash(hash), std::stoul(rem)); } +#endif else { // Dht syntax iss >> idstr; @@ -400,6 +407,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params std::cout << "Announce: " << (ok ? "success" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl; }); } +#ifdef OPENDHT_INDEXATION else if (op == "il") { std::string exact_match; iss >> exact_match; @@ -445,6 +453,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params catch (std::invalid_argument& e) { std::cout << e.what() << std::endl; } catch (std::out_of_range& e) { } } +#endif } std::cout << std::endl << "Stopping node..." << std::endl; diff --git a/tools/tools_common.h b/tools/tools_common.h index 791a8f11..b51cb60a 100644 --- a/tools/tools_common.h +++ b/tools/tools_common.h @@ -90,6 +90,7 @@ std::map<std::string, std::string> parseStringMap(std::string mapString) { return map; } +#ifdef OPENDHT_INDEXATION dht::indexation::Pht::Key createPhtKey(std::map<std::string, std::string> pht_key_str_map) { dht::indexation::Pht::Key pht_key; for (auto f : pht_key_str_map) { @@ -98,6 +99,7 @@ dht::indexation::Pht::Key createPhtKey(std::map<std::string, std::string> pht_ke } return pht_key; } +#endif bool isInfoHash(const dht::InfoHash& h) { if (not h) { -- GitLab