diff --git a/llarp/dns/server.cpp b/llarp/dns/server.cpp index 948cace0a..0a0faf701 100644 --- a/llarp/dns/server.cpp +++ b/llarp/dns/server.cpp @@ -98,14 +98,13 @@ namespace llarp bool Proxy::SetupUnboundResolver(const std::vector& resolvers) { - auto replyFunc = [self=weak_from_this()](const SockAddr& to, Message msg) - { - auto this_ptr = self.lock(); - if (this_ptr) - { - this_ptr->SendServerMessageTo(to, msg); - } - }; + auto replyFunc = [self = weak_from_this()](const SockAddr& to, Message msg) { + auto this_ptr = self.lock(); + if (this_ptr) + { + this_ptr->SendServerMessageTo(to, msg); + } + }; m_UnboundResolver = std::make_shared(m_ServerLoop, std::move(replyFunc)); if (not m_UnboundResolver->Init()) diff --git a/llarp/dns/unbound_resolver.cpp b/llarp/dns/unbound_resolver.cpp index bafd3b2f0..7e61f5242 100644 --- a/llarp/dns/unbound_resolver.cpp +++ b/llarp/dns/unbound_resolver.cpp @@ -12,7 +12,8 @@ namespace llarp::dns SockAddr source; }; - void UnboundResolver::Reset() + void + UnboundResolver::Reset() { started = false; if (unboundContext) @@ -23,30 +24,33 @@ namespace llarp::dns unboundContext = nullptr; } - void UnboundResolver::DeregisterPollFD() + void + UnboundResolver::DeregisterPollFD() { eventLoop->deregister_poll_fd_readable(ub_fd(unboundContext)); } - void UnboundResolver::RegisterPollFD() + void + UnboundResolver::RegisterPollFD() { - eventLoop->register_poll_fd_readable(ub_fd(unboundContext), [=](){ ub_process(unboundContext); }); + eventLoop->register_poll_fd_readable( + ub_fd(unboundContext), [=]() { ub_process(unboundContext); }); } - UnboundResolver::UnboundResolver( - llarp_ev_loop_ptr eventLoop, - ReplyFunction replyFunc) - : unboundContext(nullptr), started(false), eventLoop(eventLoop), replyFunc(replyFunc) + UnboundResolver::UnboundResolver(llarp_ev_loop_ptr eventLoop, ReplyFunction replyFunc) + : unboundContext(nullptr), started(false), eventLoop(eventLoop), replyFunc(replyFunc) { } // static callback - void UnboundResolver::Callback(void* data, int err, ub_result* result) + void + UnboundResolver::Callback(void* data, int err, ub_result* result) { std::unique_ptr lookup{static_cast(data)}; auto this_ptr = lookup->resolver.lock(); - if (not this_ptr) return; // resolver is gone, so we don't reply. + if (not this_ptr) + return; // resolver is gone, so we don't reply. if (err != 0) { @@ -73,7 +77,8 @@ namespace llarp::dns ub_resolve_free(result); } - bool UnboundResolver::Init() + bool + UnboundResolver::Init() { if (started) { @@ -92,7 +97,8 @@ namespace llarp::dns return true; } - bool UnboundResolver::AddUpstreamResolver(const std::string& upstreamResolverIP) + bool + UnboundResolver::AddUpstreamResolver(const std::string& upstreamResolverIP) { if (ub_ctx_set_fwd(unboundContext, upstreamResolverIP.c_str()) != 0) { @@ -102,7 +108,8 @@ namespace llarp::dns return true; } - void UnboundResolver::Lookup(const SockAddr& source, Message& msg) + void + UnboundResolver::Lookup(const SockAddr& source, Message& msg) { if (not unboundContext) { @@ -115,7 +122,14 @@ namespace llarp::dns const auto& q = msg.questions[0]; auto* lookup = new PendingUnboundLookup{weak_from_this(), msg, source}; - int err = ub_resolve_async(unboundContext, q.Name().c_str(), q.qtype, q.qclass, (void*)lookup, &UnboundResolver::Callback, nullptr); + int err = ub_resolve_async( + unboundContext, + q.Name().c_str(), + q.qtype, + q.qclass, + (void*)lookup, + &UnboundResolver::Callback, + nullptr); if (err != 0) { @@ -125,4 +139,4 @@ namespace llarp::dns } } -} // namespace llarp::dns +} // namespace llarp::dns diff --git a/llarp/dns/unbound_resolver.hpp b/llarp/dns/unbound_resolver.hpp index 9d980f8b9..7db878b24 100644 --- a/llarp/dns/unbound_resolver.hpp +++ b/llarp/dns/unbound_resolver.hpp @@ -17,8 +17,7 @@ namespace llarp::dns class UnboundResolver : public std::enable_shared_from_this { - - private: + private: ub_ctx* unboundContext; bool started; @@ -26,27 +25,29 @@ namespace llarp::dns llarp_ev_loop_ptr eventLoop; ReplyFunction replyFunc; - void Reset(); - - void DeregisterPollFD(); - void RegisterPollFD(); + void + Reset(); - public: + void + DeregisterPollFD(); + void + RegisterPollFD(); + public: + UnboundResolver(llarp_ev_loop_ptr eventLoop, ReplyFunction replyFunc); - UnboundResolver( - llarp_ev_loop_ptr eventLoop, - ReplyFunction replyFunc); - - static void Callback(void* data, int err, ub_result* result); + static void + Callback(void* data, int err, ub_result* result); // upstream resolver IP can be IPv4 or IPv6 - bool Init(); + bool + Init(); - bool AddUpstreamResolver(const std::string& upstreamResolverIP); + bool + AddUpstreamResolver(const std::string& upstreamResolverIP); - void Lookup(const SockAddr& source, Message& msg); + void + Lookup(const SockAddr& source, Message& msg); }; -} // namespace llarp::dns - +} // namespace llarp::dns diff --git a/llarp/ev/ev.hpp b/llarp/ev/ev.hpp index be43c471d..defd231e5 100644 --- a/llarp/ev/ev.hpp +++ b/llarp/ev/ev.hpp @@ -816,7 +816,6 @@ struct llarp_ev_loop virtual void deregister_poll_fd_readable(int fd) = 0; - }; #endif diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index 3ecf5b37f..78fa8f3e2 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -1059,9 +1059,10 @@ namespace libuv void OnUVPollFDReadable(uv_poll_t* handle, int status, [[maybe_unused]] int events) { - if (status < 0) return; // probably fd was closed + if (status < 0) + return; // probably fd was closed - auto func = static_cast(handle->data); + auto func = static_cast(handle->data); (*func)(); } @@ -1071,7 +1072,10 @@ namespace libuv { if (m_Polls.count(fd)) { - llarp::LogError("Attempting to create event loop poll on fd ", fd, ", but an event loop poll for that fd already exists."); + llarp::LogError( + "Attempting to create event loop poll on fd ", + fd, + ", but an event loop poll for that fd already exists."); return; } @@ -1081,9 +1085,8 @@ namespace libuv auto& new_poll = m_Polls[fd]; uv_poll_init(&m_Impl, &new_poll, fd); - new_poll.data = (void *) function_ptr; + new_poll.data = (void*)function_ptr; uv_poll_start(&new_poll, UV_READABLE, &OnUVPollFDReadable); - } void @@ -1094,7 +1097,7 @@ namespace libuv if (itr != m_Polls.end()) { uv_poll_stop(&(itr->second)); - auto func = static_cast(itr->second.data); + auto func = static_cast(itr->second.data); delete func; m_Polls.erase(itr); }