From 166b5e352c4bac7c69715af5870f3decfd1837cc Mon Sep 17 00:00:00 2001 From: Seva <seva@binarytrails.net> Date: Wed, 18 Sep 2019 13:49:58 -0400 Subject: [PATCH] proxyserver: default push to localhost if empty host --- include/opendht/dht_proxy_server.h | 2 +- src/dht_proxy_server.cpp | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/opendht/dht_proxy_server.h b/include/opendht/dht_proxy_server.h index 627335c9..8ffd9ac8 100644 --- a/include/opendht/dht_proxy_server.h +++ b/include/opendht/dht_proxy_server.h @@ -360,7 +360,7 @@ private: mutable std::atomic<size_t> requestNum_ {0}; mutable std::atomic<time_point> lastStatsReset_ {time_point::min()}; - const std::string pushServer_; + std::string pushServer_; #ifdef OPENDHT_PUSH_NOTIFICATIONS struct Listener { diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp index 22177e88..00ed8796 100644 --- a/src/dht_proxy_server.cpp +++ b/src/dht_proxy_server.cpp @@ -222,6 +222,16 @@ DhtProxyServer::DhtProxyServer( jsonBuilder_["commentStyle"] = "None"; jsonBuilder_["indentation"] = ""; + if (!pushServer.empty()){ + // no host delim, assume port only + if (pushServer.find(":") == std::string::npos) + pushServer_ = "localhost:" + pushServer_; + // define http request destination for push notifications + pushHostPort_ = splitPort(pushServer_); + if (logger_) + logger_->d("Using push server for notifications: %s:%s", pushHostPort_.first.c_str(), + pushHostPort_.second.c_str()); + } if (identity.first and identity.second) { asio::error_code ec; // define tls context @@ -258,8 +268,6 @@ DhtProxyServer::DhtProxyServer( restinio::own_io_context(), std::forward<restinio::run_on_this_thread_settings_t<RestRouterTraitsTls>>(std::move(settings)) ); - // define http request destination - pushHostPort_ = splitPort(pushServer_); // run http server serverThread_ = std::thread([this]{ httpsServer_->open_async([]{/*ok*/}, [](std::exception_ptr ex){ @@ -276,8 +284,6 @@ DhtProxyServer::DhtProxyServer( restinio::own_io_context(), std::forward<restinio::run_on_this_thread_settings_t<RestRouterTraits>>(std::move(settings)) ); - // define http request destination - pushHostPort_ = splitPort(pushServer_); // run http server serverThread_ = std::thread([this](){ httpServer_->open_async([]{/*ok*/}, [](std::exception_ptr ex){ -- GitLab