#pragma once #include #include #include #include #include #include #include "message.hpp" #ifdef _WIN32 #include #else #include #endif extern "C" { struct ub_ctx; struct ub_result; } namespace llarp::dns { using ReplyFunction = std::function; using FailFunction = std::function; class UnboundResolver : public std::enable_shared_from_this { private: ub_ctx* unboundContext; std::atomic started; #ifdef _WIN32 std::thread runner; #else std::weak_ptr loop; std::shared_ptr udp; #endif ReplyFunction replyFunc; FailFunction failFunc; void Reset(); public: UnboundResolver(EventLoop_ptr loop, ReplyFunction replyFunc, FailFunction failFunc); static void Callback(void* data, int err, ub_result* result); // stop resolver thread void Stop(); // upstream resolver IP can be IPv4 or IPv6 bool Init(); bool AddUpstreamResolver(const SockAddr& upstreamResolverIP); void AddHostsFile(const fs::path& file); void Lookup(SockAddr to, SockAddr from, Message msg); }; } // namespace llarp::dns