From d872c2b49214c0a4db40a9e2d860802d9eedc563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 15 Nov 2016 00:23:19 +0100 Subject: Support the ident protocol fix #3211 --- louloulibs/network/resolver.hpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'louloulibs/network/resolver.hpp') diff --git a/louloulibs/network/resolver.hpp b/louloulibs/network/resolver.hpp index 29e6f3a..7365f93 100644 --- a/louloulibs/network/resolver.hpp +++ b/louloulibs/network/resolver.hpp @@ -125,5 +125,3 @@ private: }; std::string addr_to_string(const struct addrinfo* rp); - - -- cgit v1.2.3 From 5b56007828f20c763df3f36ceed809188880663e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 6 Jan 2017 22:58:18 +0100 Subject: Use udns instead of c-ares fix #3226 --- louloulibs/network/resolver.hpp | 45 ++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'louloulibs/network/resolver.hpp') diff --git a/louloulibs/network/resolver.hpp b/louloulibs/network/resolver.hpp index 7365f93..f516da5 100644 --- a/louloulibs/network/resolver.hpp +++ b/louloulibs/network/resolver.hpp @@ -1,38 +1,31 @@ #pragma once - #include "louloulibs.h" #include +#include #include #include #include #include #include +#include class AddrinfoDeleter { public: void operator()(struct addrinfo* addr) { -#ifdef CARES_FOUND - while (addr) - { - delete addr->ai_addr; - auto next = addr->ai_next; - delete addr; - addr = next; - } -#else freeaddrinfo(addr); -#endif } }; + class Resolver { public: + using ErrorCallbackType = std::function; using SuccessCallbackType = std::function; @@ -45,7 +38,7 @@ public: bool is_resolving() const { -#ifdef CARES_FOUND +#ifdef UDNS_FOUND return this->resolving; #else return false; @@ -68,11 +61,10 @@ public: void clear() { -#ifdef CARES_FOUND +#ifdef UDNS_FOUND this->resolved6 = false; this->resolved4 = false; this->resolving = false; - this->cares_addrinfo = nullptr; this->port.clear(); #endif this->resolved = false; @@ -85,12 +77,18 @@ public: private: void start_resolving(const std::string& hostname, const std::string& port); -#ifdef CARES_FOUND - void on_hostname4_resolved(int status, struct hostent* hostent); - void on_hostname6_resolved(int status, struct hostent* hostent); + std::vector look_in_etc_hosts(const std::string& hostname); + /** + * Call getaddrinfo() on the given hostname or IP, and append the result + * to our internal addrinfo list. Return getaddrinfo()’s return value. + */ + int call_getaddrinfo(const char* name, const char* port, int flags); + +#ifdef UDNS_FOUND + void on_hostname4_resolved(dns_rr_a4 *result); + void on_hostname6_resolved(dns_rr_a6 *result); - void fill_ares_addrinfo4(const struct hostent* hostent); - void fill_ares_addrinfo6(const struct hostent* hostent); + void start_timer(); void on_resolved(); @@ -99,14 +97,6 @@ private: bool resolving; - /** - * When using c-ares to resolve the host asynchronously, we need the - * c-ares callbacks to fill a structure (a struct addrinfo, for - * compatibility with getaddrinfo and the rest of the code that works when - * c-ares is not used) with all returned values (for example an IPv6 and - * an IPv4). The pointer is given to the unique_ptr to manage its lifetime. - */ - struct addrinfo* cares_addrinfo; std::string port; #endif @@ -117,7 +107,6 @@ private: bool resolved; std::string error_msg; - std::unique_ptr addr; ErrorCallbackType error_cb; -- cgit v1.2.3 From a5d35c2455d9e3e5724c9a906deb1b58e5a5f87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 31 Jan 2017 23:47:45 +0100 Subject: Add some missing ifndef for udns --- louloulibs/network/resolver.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'louloulibs/network/resolver.hpp') diff --git a/louloulibs/network/resolver.hpp b/louloulibs/network/resolver.hpp index f516da5..800c7ec 100644 --- a/louloulibs/network/resolver.hpp +++ b/louloulibs/network/resolver.hpp @@ -10,7 +10,9 @@ #include #include #include -#include +#ifdef UDNS_FOUND +# include +#endif class AddrinfoDeleter { -- cgit v1.2.3 From 6cb7787512a5e02ad2100dbdef734b36d8a8f0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 7 Mar 2017 17:47:10 +0100 Subject: Small resolver refactor Makes the codecoverage deterministic (it does not depend on the order of v4/v6 resolution) --- louloulibs/network/resolver.hpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'louloulibs/network/resolver.hpp') diff --git a/louloulibs/network/resolver.hpp b/louloulibs/network/resolver.hpp index 800c7ec..a560819 100644 --- a/louloulibs/network/resolver.hpp +++ b/louloulibs/network/resolver.hpp @@ -89,6 +89,10 @@ private: #ifdef UDNS_FOUND void on_hostname4_resolved(dns_rr_a4 *result); void on_hostname6_resolved(dns_rr_a6 *result); + /** + * Called after one record (4 or 6) has been resolved. + */ + void after_resolved(); void start_timer(); -- cgit v1.2.3 From 0ab40dc1ab4e689921da54080b135e1d22b1c586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 14 Mar 2017 21:45:23 +0100 Subject: Refactoring louloulibs and cmake Use OBJECT libraries Remove the louloulibs directory Write FOUND variables in the cache --- louloulibs/network/resolver.hpp | 122 ---------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 louloulibs/network/resolver.hpp (limited to 'louloulibs/network/resolver.hpp') diff --git a/louloulibs/network/resolver.hpp b/louloulibs/network/resolver.hpp deleted file mode 100644 index a560819..0000000 --- a/louloulibs/network/resolver.hpp +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once - -#include "louloulibs.h" - -#include -#include -#include -#include - -#include -#include -#include -#ifdef UDNS_FOUND -# include -#endif - -class AddrinfoDeleter -{ - public: - void operator()(struct addrinfo* addr) - { - freeaddrinfo(addr); - } -}; - - -class Resolver -{ -public: - - using ErrorCallbackType = std::function; - using SuccessCallbackType = std::function; - - Resolver(); - ~Resolver() = default; - Resolver(const Resolver&) = delete; - Resolver(Resolver&&) = delete; - Resolver& operator=(const Resolver&) = delete; - Resolver& operator=(Resolver&&) = delete; - - bool is_resolving() const - { -#ifdef UDNS_FOUND - return this->resolving; -#else - return false; -#endif - } - - bool is_resolved() const - { - return this->resolved; - } - - const auto& get_result() const - { - return this->addr; - } - std::string get_error_message() const - { - return this->error_msg; - } - - void clear() - { -#ifdef UDNS_FOUND - this->resolved6 = false; - this->resolved4 = false; - this->resolving = false; - this->port.clear(); -#endif - this->resolved = false; - this->addr.reset(); - this->error_msg.clear(); - } - - void resolve(const std::string& hostname, const std::string& port, - SuccessCallbackType success_cb, ErrorCallbackType error_cb); - -private: - void start_resolving(const std::string& hostname, const std::string& port); - std::vector look_in_etc_hosts(const std::string& hostname); - /** - * Call getaddrinfo() on the given hostname or IP, and append the result - * to our internal addrinfo list. Return getaddrinfo()’s return value. - */ - int call_getaddrinfo(const char* name, const char* port, int flags); - -#ifdef UDNS_FOUND - void on_hostname4_resolved(dns_rr_a4 *result); - void on_hostname6_resolved(dns_rr_a6 *result); - /** - * Called after one record (4 or 6) has been resolved. - */ - void after_resolved(); - - void start_timer(); - - void on_resolved(); - - bool resolved4; - bool resolved6; - - bool resolving; - - std::string port; - -#endif - /** - * Tells if we finished the resolution process. It doesn't indicate if it - * was successful (it is true even if the result is an error). - */ - bool resolved; - std::string error_msg; - - std::unique_ptr addr; - - ErrorCallbackType error_cb; - SuccessCallbackType success_cb; -}; - -std::string addr_to_string(const struct addrinfo* rp); -- cgit v1.2.3