#pragma once #include #include #include #include #include #include #include #include #ifdef _WIN32 #include #endif namespace llarp::dns { using ReplyFunction = std::function buf)>; using FailFunction = std::function; class UnboundResolver : public std::enable_shared_from_this { private: ub_ctx* unboundContext; #ifdef _WIN32 /// windows needs to run as blocking in another thread to work at all becuase LOL windows std::unique_ptr runnerThread; #endif std::atomic started; llarp_ev_loop_ptr eventLoop; ReplyFunction replyFunc; FailFunction failFunc; void Reset(); void DeregisterPollFD(); void RegisterPollFD(); public: UnboundResolver(llarp_ev_loop_ptr eventLoop, ReplyFunction replyFunc, FailFunction failFunc); static void Callback(void* data, int err, ub_result* result); // upstream resolver IP can be IPv4 or IPv6 bool Init(); bool AddUpstreamResolver(const std::string& upstreamResolverIP); void Lookup(const SockAddr& source, Message msg); }; } // namespace llarp::dns