From 747f86f8f4348d022cae47b6ef5e9dc28d10bfa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Fri, 10 Nov 2017 17:59:05 -0500 Subject: [PATCH] dhtrunner: use SockAddr::resolve --- include/opendht/dhtrunner.h | 2 -- src/dhtrunner.cpp | 30 +++--------------------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index fb78f1af..c95c2eb8 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -376,8 +376,6 @@ private: void doRun(const SockAddr& sin4, const SockAddr& sin6, SecureDhtConfig config); time_point loop_(); - static std::vector<SockAddr> getAddrInfo(const std::string& host, const std::string& service); - NodeStatus getStatus() const { return std::max(status4, status6); } diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index dc7c7ede..d9816200 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -70,8 +70,8 @@ DhtRunner::run(in_port_t port, DhtRunner::Config config) void DhtRunner::run(const char* ip4, const char* ip6, const char* service, DhtRunner::Config config) { - auto res4 = getAddrInfo(ip4, service); - auto res6 = getAddrInfo(ip6, service); + auto res4 = SockAddr::resolve(ip4, service); + auto res6 = SockAddr::resolve(ip6, service); run(res4.empty() ? SockAddr() : res4.front(), res6.empty() ? SockAddr() : res6.front(), config); } @@ -664,7 +664,7 @@ DhtRunner::tryBootstrapContinuously() for (auto it = nodes.rbegin(); it != nodes.rend(); it++) { ++ping_count; try { - bootstrap(getAddrInfo(it->first, it->second), [&](bool) { + bootstrap(SockAddr::resolve(it->first, it->second), [&](bool) { if (not running) return; { @@ -695,30 +695,6 @@ DhtRunner::tryBootstrapContinuously() }); } -std::vector<SockAddr> -DhtRunner::getAddrInfo(const std::string& host, const std::string& service) -{ - std::vector<SockAddr> ips {}; - if (host.empty()) - return ips; - - addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; - addrinfo* info = nullptr; - int rc = getaddrinfo(host.c_str(), service.c_str(), &hints, &info); - if(rc != 0) - throw std::invalid_argument(std::string("Error: `") + host + ":" + service + "`: " + gai_strerror(rc)); - - addrinfo* infop = info; - while (infop) { - ips.emplace_back(infop->ai_addr, infop->ai_addrlen); - infop = infop->ai_next; - } - freeaddrinfo(info); - return ips; -} - void DhtRunner::bootstrap(const std::string& host, const std::string& service) { -- GitLab