From 5c4a68ccb2e4b601da93e9bd061b076336f659ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Mon, 8 Dec 2014 11:53:19 -0500
Subject: [PATCH] dhtnode: fix error message

---
 tools/dhtnode.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp
index c45063cf..0610c52d 100644
--- a/tools/dhtnode.cpp
+++ b/tools/dhtnode.cpp
@@ -41,6 +41,7 @@ extern "C" {
 #include <string>
 #include <sstream>
 #include <chrono>
+#include <set>
 
 using namespace dht;
 
@@ -196,7 +197,16 @@ main(int argc, char **argv)
             continue;
         }
 
+        if (op.empty())
+            continue;
+
         dht::InfoHash id {idstr};
+        static const std::set<std::string> VALID_OPS {"g", "l", "p", "s", "e", "a"};
+        if (VALID_OPS.find(op) == VALID_OPS.cend()) {
+            std::cout << "Unknown command: " << op << std::endl;
+            std::cout << " (type 'h' or 'help' for a list of possible commands)" << std::endl;
+            continue;
+        }
         static constexpr dht::InfoHash INVALID_ID {};
         if (id == INVALID_ID) {
             std::cout << "Syntax error: invalid InfoHash." << std::endl;
@@ -261,9 +271,6 @@ main(int argc, char **argv)
             dht.put(id, dht::Value {dht::ServiceAnnouncement::TYPE.id, dht::ServiceAnnouncement(port)}, [](bool ok) {
                 std::cout << "Announce done !" << ok << std::endl;
             });
-        } else if (op != "") {
-            std::cout << "Unknown command: " << op << std::endl;
-            std::cout << " (type 'h' or 'help' for a list of possible commands)" << std::endl;
         }
     }
 
-- 
GitLab