Skip to content
Snippets Groups Projects
Commit 747f86f8 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

dhtrunner: use SockAddr::resolve

parent 161769f4
No related branches found
No related tags found
No related merge requests found
...@@ -376,8 +376,6 @@ private: ...@@ -376,8 +376,6 @@ private:
void doRun(const SockAddr& sin4, const SockAddr& sin6, SecureDhtConfig config); void doRun(const SockAddr& sin4, const SockAddr& sin6, SecureDhtConfig config);
time_point loop_(); time_point loop_();
static std::vector<SockAddr> getAddrInfo(const std::string& host, const std::string& service);
NodeStatus getStatus() const { NodeStatus getStatus() const {
return std::max(status4, status6); return std::max(status4, status6);
} }
......
...@@ -70,8 +70,8 @@ DhtRunner::run(in_port_t port, DhtRunner::Config config) ...@@ -70,8 +70,8 @@ DhtRunner::run(in_port_t port, DhtRunner::Config config)
void void
DhtRunner::run(const char* ip4, const char* ip6, const char* service, DhtRunner::Config config) DhtRunner::run(const char* ip4, const char* ip6, const char* service, DhtRunner::Config config)
{ {
auto res4 = getAddrInfo(ip4, service); auto res4 = SockAddr::resolve(ip4, service);
auto res6 = getAddrInfo(ip6, service); auto res6 = SockAddr::resolve(ip6, service);
run(res4.empty() ? SockAddr() : res4.front(), run(res4.empty() ? SockAddr() : res4.front(),
res6.empty() ? SockAddr() : res6.front(), config); res6.empty() ? SockAddr() : res6.front(), config);
} }
...@@ -664,7 +664,7 @@ DhtRunner::tryBootstrapContinuously() ...@@ -664,7 +664,7 @@ DhtRunner::tryBootstrapContinuously()
for (auto it = nodes.rbegin(); it != nodes.rend(); it++) { for (auto it = nodes.rbegin(); it != nodes.rend(); it++) {
++ping_count; ++ping_count;
try { try {
bootstrap(getAddrInfo(it->first, it->second), [&](bool) { bootstrap(SockAddr::resolve(it->first, it->second), [&](bool) {
if (not running) if (not running)
return; return;
{ {
...@@ -695,30 +695,6 @@ DhtRunner::tryBootstrapContinuously() ...@@ -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 void
DhtRunner::bootstrap(const std::string& host, const std::string& service) DhtRunner::bootstrap(const std::string& host, const std::string& service)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment