From 38ad5b9ef2a9ae707b0546d18da44c4f56ec0015 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 6 Nov 2017 16:49:46 -0500
Subject: [PATCH] add --proxyserver option for dhtnode

---
 tools/dhtnode.cpp    |  5 ++++-
 tools/tools_common.h | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp
index 0c18af27..d8c81a9a 100644
--- a/tools/dhtnode.cpp
+++ b/tools/dhtnode.cpp
@@ -29,7 +29,7 @@ extern "C" {
 using namespace dht;
 
 void print_usage() {
-    std::cout << "Usage: dhtnode [-v [-l logfile]] [-i] [-d] [-n network_id] [-p local_port] [-b bootstrap_host[:port]]" << std::endl << std::endl;
+    std::cout << "Usage: dhtnode [-v [-l logfile]] [-i] [-d] [-n network_id] [-p local_port] [-b bootstrap_host[:port]] [--proxyserver local_port]" << std::endl << std::endl;
     std::cout << "dhtnode, a simple OpenDHT command line node runner." << std::endl;
     std::cout << "Report bugs to: http://opendht.net" << std::endl;
 }
@@ -92,6 +92,9 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params)
     std::map<std::string, indexation::Pht> indexes;
 #if OPENDHT_PROXY_SERVER
     std::map<in_port_t, std::unique_ptr<DhtProxyServer>> proxies;
+    if (params.proxyserver != 0) {
+        proxies.emplace(params.proxyserver, new DhtProxyServer(dht, params.proxyserver));
+    }
 #endif //OPENDHT_PROXY_SERVER
 
     while (true)
diff --git a/tools/tools_common.h b/tools/tools_common.h
index 933cc7e2..cd3e1970 100644
--- a/tools/tools_common.h
+++ b/tools/tools_common.h
@@ -121,6 +121,7 @@ struct dht_params {
     bool daemonize {false};
     bool service {false};
     std::pair<std::string, std::string> bootstrap {};
+    in_port_t proxyserver {0};
 };
 
 static const constexpr struct option long_options[] = {
@@ -134,6 +135,7 @@ static const constexpr struct option long_options[] = {
    {"service",    no_argument      , nullptr, 's'},
    {"logfile",    required_argument, nullptr, 'l'},
    {"syslog",     no_argument      , nullptr, 'L'},
+   {"proxyserver",required_argument, nullptr, 'S'},
    {nullptr,      0                , nullptr,  0}
 };
 
@@ -151,6 +153,14 @@ parseArgs(int argc, char **argv) {
                     std::cout << "Invalid port: " << port_arg << std::endl;
             }
             break;
+        case 'S': {
+                int port_arg = atoi(optarg);
+                if (port_arg >= 0 && port_arg < 0x10000)
+                    params.proxyserver = port_arg;
+                else
+                    std::cout << "Invalid port: " << port_arg << std::endl;
+            }
+            break;
         case 'n':
             params.network = strtoul(optarg, nullptr, 0);
             break;
-- 
GitLab