make format

pull/1307/head
Thomas Winget 4 years ago
parent f58c7df54d
commit 221e9ff5de

@ -98,14 +98,13 @@ namespace llarp
bool
Proxy::SetupUnboundResolver(const std::vector<IpAddress>& 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<UnboundResolver>(m_ServerLoop, std::move(replyFunc));
if (not m_UnboundResolver->Init())

@ -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<PendingUnboundLookup> lookup{static_cast<PendingUnboundLookup*>(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

@ -17,8 +17,7 @@ namespace llarp::dns
class UnboundResolver : public std::enable_shared_from_this<UnboundResolver>
{
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

@ -816,7 +816,6 @@ struct llarp_ev_loop
virtual void
deregister_poll_fd_readable(int fd) = 0;
};
#endif

@ -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<libuv::Loop::Callback* >(handle->data);
auto func = static_cast<libuv::Loop::Callback*>(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<Callback* >(itr->second.data);
auto func = static_cast<Callback*>(itr->second.data);
delete func;
m_Polls.erase(itr);
}

Loading…
Cancel
Save