From 144e254c40f4084f726d33bb9e35759fa20532ce Mon Sep 17 00:00:00 2001 From: Seva Date: Tue, 13 Aug 2019 17:17:32 -0400 Subject: [PATCH] build: add flag for http_parser fork --- CMakeLists.txt | 4 ++++ configure.ac | 8 ++++++++ include/opendht/http.h | 3 ++- src/dht_proxy_server.cpp | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1205447f..b9d7d52c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ 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 Restinio and jsoncpp" OFF) option (OPENDHT_PROXY_OPENSSL "Build DHT proxy with OpenSSL" ON) +option (OPENDHT_PROXY_HTTP_PARSER_FORK "Build DHT proxy with custom http_parser to support old API" OFF) option (OPENDHT_INDEX "Build DHT indexation feature" OFF) option (OPENDHT_TESTS "Add unit tests executable" OFF) @@ -79,6 +80,9 @@ if (OPENDHT_PROXY_SERVER OR OPENDHT_PROXY_CLIENT) message(SEND_ERROR "OpenSSL is required for DHT proxy as specified") endif() endif() + if (OPENDHT_PROXY_HTTP_PARSER_FORK) + add_definitions(-DOPENDHT_PROXY_HTTP_PARSER_FORK) + endif() endif() # Build flags diff --git a/configure.ac b/configure.ac index 8e5452e1..6dc1fd1a 100644 --- a/configure.ac +++ b/configure.ac @@ -151,6 +151,14 @@ AS_IF([test "x$have_openssl" = "xyes"], [ AC_MSG_NOTICE([Not using OpenSSL]) ]) +AC_ARG_WITH([http_parser_fork], AS_HELP_STRING([--with-http-parser-fork], [Build with http_parser fork to support old API])) +AS_IF([test "x$with_http_parser_fork" != "xno"],[ + AC_MSG_NOTICE([Using http_parser fork]) + CPPFLAGS+=" -DOPENDHT_PROXY_HTTP_PARSER_FORK" +], [ + AC_MSG_NOTICE([Not using http_parser fork]) +]) + AM_COND_IF([PROXY_CLIENT_OR_SERVER], [ PKG_CHECK_MODULES([Asio], [fmt >= 1.12.2]) PKG_CHECK_MODULES([Fmt], [fmt >= 5.3.0]) diff --git a/include/opendht/http.h b/include/opendht/http.h index f48e65c5..975463f2 100644 --- a/include/opendht/http.h +++ b/include/opendht/http.h @@ -337,6 +337,7 @@ private: std::shared_ptr m_logger; }; +#ifdef OPENDHT_PROXY_HTTP_PARSER_FORK /* Custom HTTP-methods for RESTinio > 0.5.0. * https://github.com/Stiffstream/restinio/issues/26 */ @@ -360,5 +361,5 @@ struct custom_http_methods_t return restinio::default_http_methods_t::from_nodejs(m); } }; - +#endif } // namespace restinio diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp index 72646a1e..979281c0 100644 --- a/src/dht_proxy_server.cpp +++ b/src/dht_proxy_server.cpp @@ -247,9 +247,11 @@ DhtProxyServer::createRestRouter() // **************************** LEGACY ROUTES **************************** // node.info router->http_get("/", std::bind(&DhtProxyServer::getNodeInfo, this, _1, _2)); +#ifdef OPENDHT_PROXY_HTTP_PARSER_FORK // node.stats router->add_handler(restinio::custom_http_methods_t::from_nodejs(restinio::method_stats.raw_id()), "/", std::bind(&DhtProxyServer::getStats, this, _1, _2)); +#endif // key.options router->add_handler(restinio::http_method_options(), "/:hash", std::bind(&DhtProxyServer::options, this, _1, _2)); @@ -257,9 +259,11 @@ DhtProxyServer::createRestRouter() router->http_get("/:hash", std::bind(&DhtProxyServer::get, this, _1, _2)); // key.post router->http_post("/:hash", std::bind(&DhtProxyServer::put, this, _1, _2)); +#ifdef OPENDHT_PROXY_HTTP_PARSER_FORK // key.listen router->add_handler(restinio::custom_http_methods_t::from_nodejs(restinio::method_listen.raw_id()), "/:hash", std::bind(&DhtProxyServer::listen, this, _1, _2)); +#endif #ifdef OPENDHT_PUSH_NOTIFICATIONS // key.subscribe router->add_handler(restinio::http_method_subscribe(), @@ -269,12 +273,14 @@ DhtProxyServer::createRestRouter() "/:hash", std::bind(&DhtProxyServer::unsubscribe, this, _1, _2)); #endif //OPENDHT_PUSH_NOTIFICATIONS #ifdef OPENDHT_PROXY_SERVER_IDENTITY +#ifdef OPENDHT_PROXY_HTTP_PARSER_FORK // key.sign router->add_handler(restinio::custom_http_methods_t::from_nodejs(restinio::method_sign.raw_id()), "/:hash", std::bind(&DhtProxyServer::putSigned, this, _1, _2)); // key.encrypt router->add_handler(restinio::custom_http_methods_t::from_nodejs(restinio::method_encrypt.raw_id()), "/:hash", std::bind(&DhtProxyServer::putEncrypted, this, _1, _2)); +#endif #endif // OPENDHT_PROXY_SERVER_IDENTITY // **************************** NEW ROUTES ****************************