From 7d7410b472bceca736c22b50275c9fee3ec3c674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Wed, 8 Nov 2017 15:10:23 -0500 Subject: [PATCH] dhtnode: allow to use arbitrary string as key Key will be h(key). --- tools/dhtnode.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp index efad9767..b0bc35d9 100644 --- a/tools/dhtnode.cpp +++ b/tools/dhtnode.cpp @@ -201,6 +201,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params) std::cout << " (type 'h' or 'help' for a list of possible commands)" << std::endl; continue; } + dht::InfoHash id; if (op == "il" or op == "ii") { // Pht syntax @@ -227,12 +228,17 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params) else { // Dht syntax iss >> idstr; - InfoHash h {idstr}; - if (not isInfoHash(h)) - continue; + id = dht::InfoHash(idstr); + if (not id) { + if (idstr.empty()) { + std::cerr << "Syntax error: invalid InfoHash." << std::endl; + continue; + } + id = InfoHash::get(idstr); + std::cout << "Using h(" << idstr << ") = " << id << std::endl; + } } - dht::InfoHash id {idstr}; // Dht auto start = std::chrono::high_resolution_clock::now(); if (op == "g") { -- GitLab