Make format

pull/1557/head
Jason Rhinelander 3 years ago
parent ccc7b5c9e9
commit c4559d158e

@ -27,7 +27,7 @@ namespace llarp
Context::CallSafe(std::function<void(void)> f)
{
if (!loop)
return false;
return false;
loop->call(std::move(f));
return true;
}
@ -86,7 +86,7 @@ namespace llarp
Context::makeRouter(const EventLoop_ptr& loop)
{
return std::static_pointer_cast<AbstractRouter>(
std::make_shared<Router>(loop, makeVPNPlatform()));
std::make_shared<Router>(loop, makeVPNPlatform()));
}
std::shared_ptr<vpn::Platform>

@ -35,8 +35,7 @@ namespace llarp::dns
unboundContext = nullptr;
}
UnboundResolver::UnboundResolver(
EventLoop_ptr loop, ReplyFunction reply, FailFunction fail)
UnboundResolver::UnboundResolver(EventLoop_ptr loop, ReplyFunction reply, FailFunction fail)
: unboundContext(nullptr)
, started(false)
, replyFunc(loop->make_caller(std::move(reply)))

@ -118,7 +118,10 @@ namespace llarp
// Calls a function/lambda/etc. If invoked from within the event loop itself this calls the
// given lambda immediately; otherwise it passes it to `call_soon()` to be queued to run at the
// next event loop iteration.
template <typename Callable> void call(Callable&& f) {
template <typename Callable>
void
call(Callable&& f)
{
if (inEventLoop())
f();
else
@ -151,21 +154,21 @@ namespace llarp
// m_keepalive = std::make_shared<int>(42);
// loop->call_every(100ms, m_keepalive, [this] { some_func(); });
//
template <typename Callable> // Templated so that the compiler can inline the call
template <typename Callable> // Templated so that the compiler can inline the call
void
call_every(llarp_time_t repeat, std::weak_ptr<void> owner, Callable f)
{
auto repeater = make_repeater();
auto& r = *repeater; // reference *before* we pass ownership into the lambda below
auto& r = *repeater; // reference *before* we pass ownership into the lambda below
r.start(
repeat,
[repeater = std::move(repeater), owner = std::move(owner), f = std::move(f)]() mutable {
if (auto ptr = owner.lock())
f();
else
repeater.reset(); // Trigger timer removal on tied object destruction (we should be the only thing holding
// the repeater; ideally it would be a unique_ptr, but
// std::function says nuh-uh).
repeater.reset(); // Trigger timer removal on tied object destruction (we should be
// the only thing holding the repeater; ideally it would be a
// unique_ptr, but std::function says nuh-uh).
});
}

@ -152,7 +152,9 @@ namespace llarp::uv
std::make_shared<llarp::uv::UDPHandle>(*m_Impl, std::move(on_recv)));
}
static void setup_oneshot_timer(uvw::Loop& loop, llarp_time_t delay, std::function<void()> callback) {
static void
setup_oneshot_timer(uvw::Loop& loop, llarp_time_t delay, std::function<void()> callback)
{
auto timer = loop.resource<uvw::TimerHandle>();
timer->on<uvw::TimerEvent>([f = std::move(callback)](const auto&, auto& timer) {
f();
@ -175,10 +177,11 @@ namespace llarp::uv
else
{
call_soon([this, f = std::move(callback), target_time = time_now() + delay_ms] {
// Recalculate delay because it may have taken some time to get ourselves into the logic thread
// Recalculate delay because it may have taken some time to get ourselves into the logic
// thread
auto updated_delay = target_time - time_now();
if (updated_delay <= 0ms)
f(); // Timer already expired!
f(); // Timer already expired!
else
setup_oneshot_timer(*m_Impl, updated_delay, std::move(f));
});

@ -837,8 +837,9 @@ namespace llarp
m_IfName = m_NetIf->IfName();
LogInfo(Name(), " got network interface ", m_IfName);
if (not Router()->loop()->add_network_interface(
m_NetIf, [this](net::IPPacket pkt) { m_PacketRouter->HandleIPPacket(std::move(pkt)); }))
if (not Router()->loop()->add_network_interface(m_NetIf, [this](net::IPPacket pkt) {
m_PacketRouter->HandleIPPacket(std::move(pkt));
}))
{
LogError(Name(), " failed to add network interface");
return false;

@ -238,7 +238,8 @@ namespace llarp
}
router->QueueWork([router, pathid, nextHop, pathKey, status] {
LR_StatusMessage::CreateAndSend(router, pathid, nextHop, pathKey, status); });
LR_StatusMessage::CreateAndSend(router, pathid, nextHop, pathKey, status);
});
}
/// this is done from logic thread

@ -223,8 +223,8 @@ namespace llarp
LR_StatusMessage::QueueSendMessage(
AbstractRouter* router, const RouterID nextHop, std::shared_ptr<LR_StatusMessage> msg)
{
router->loop()->call([router, nextHop, msg=std::move(msg)] {
SendMessage(router, nextHop, msg); });
router->loop()->call(
[router, nextHop, msg = std::move(msg)] { SendMessage(router, nextHop, msg); });
}
void

@ -229,7 +229,8 @@ namespace llarp
{
llarp::LogDebug("Path build failed for an unspecified reason");
}
r->loop()->call([r, self = shared_from_this()]() { self->EnterState(ePathFailed, r->Now()); });
r->loop()->call(
[r, self = shared_from_this()]() { self->EnterState(ePathFailed, r->Now()); });
}
// TODO: meaningful return value?
@ -436,7 +437,7 @@ namespace llarp
msg.pathid = TXID();
++idx;
}
r->loop()->call([self = shared_from_this(), data = std::move(sendmsgs), r] () mutable {
r->loop()->call([self = shared_from_this(), data = std::move(sendmsgs), r]() mutable {
self->HandleAllUpstream(std::move(data), r);
});
}
@ -506,7 +507,7 @@ namespace llarp
sendMsgs[idx].X = buf;
++idx;
}
r->loop()->call([self = shared_from_this(), msgs = std::move(sendMsgs), r] () mutable {
r->loop()->call([self = shared_from_this(), msgs = std::move(sendMsgs), r]() mutable {
self->HandleAllDownstream(std::move(msgs), r);
});
}

@ -184,8 +184,8 @@ namespace llarp
{
if (callback)
{
auto f = [f=std::move(callback), status] { f(status); };
_loop->call([this, f=std::move(f)] { m_Killer.TryAccess(f); });
auto f = [f = std::move(callback), status] { f(status); };
_loop->call([this, f = std::move(f)] { m_Killer.TryAccess(f); });
}
}

@ -157,7 +157,7 @@ namespace llarp
{
LogDebug("Adding or updating RC for ", RouterID(rc.pubkey), " to nodedb and dht.");
const RouterContact copy{rc};
_loop->call([rc, n=_nodedb] { n->PutIfNewer(rc); });
_loop->call([rc, n = _nodedb] { n->PutIfNewer(rc); });
_dht->impl->PutRCNodeAsync(rc);
}

@ -46,8 +46,7 @@ static constexpr std::chrono::milliseconds ROUTER_TICK_INTERVAL = 1s;
namespace llarp
{
Router::Router(
EventLoop_ptr loop, std::shared_ptr<vpn::Platform> vpnPlatform)
Router::Router(EventLoop_ptr loop, std::shared_ptr<vpn::Platform> vpnPlatform)
: ready(false)
, m_lmq(std::make_shared<oxenmq::OxenMQ>())
, _loop(std::move(loop))

@ -316,9 +316,7 @@ namespace llarp
void
GossipRCIfNeeded(const RouterContact rc) override;
explicit Router(
EventLoop_ptr loop,
std::shared_ptr<vpn::Platform> vpnPlatform);
explicit Router(EventLoop_ptr loop, std::shared_ptr<vpn::Platform> vpnPlatform);
~Router() override;

@ -251,7 +251,8 @@ namespace llarp
LogError("failed to parse response from lns lookup: ", ex.what());
}
}
r->loop()->call([resultHandler, maybe=std::move(maybe)]() { resultHandler(std::move(maybe)); });
r->loop()->call(
[resultHandler, maybe = std::move(maybe)]() { resultHandler(std::move(maybe)); });
},
req.dump());
}

@ -236,93 +236,92 @@ namespace llarp::rpc
endpoint = endpoint_itr->get<std::string>();
}
r->loop()->call([map, exit, lnsExit, range, token, endpoint, r, reply]() mutable {
auto ep = r->hiddenServiceContext().GetEndpointByName(endpoint);
if (ep == nullptr)
auto ep = r->hiddenServiceContext().GetEndpointByName(endpoint);
if (ep == nullptr)
{
reply(CreateJSONError("no endpoint with name " + endpoint));
return;
}
if (map and (exit.has_value() or lnsExit.has_value()))
{
auto mapExit = [=](service::Address addr) mutable {
ep->MapExitRange(range, addr);
bool shouldSendAuth = false;
if (token.has_value())
{
reply(CreateJSONError("no endpoint with name " + endpoint));
return;
shouldSendAuth = true;
ep->SetAuthInfoForEndpoint(*exit, service::AuthInfo{*token});
}
if (map and (exit.has_value() or lnsExit.has_value()))
{
auto mapExit = [=](service::Address addr) mutable {
ep->MapExitRange(range, addr);
bool shouldSendAuth = false;
if (token.has_value())
{
shouldSendAuth = true;
ep->SetAuthInfoForEndpoint(*exit, service::AuthInfo{*token});
}
ep->EnsurePathToService(
addr,
[reply, r, shouldSendAuth](auto, service::OutboundContext* ctx) {
if (ctx == nullptr)
{
reply(CreateJSONError("could not find exit"));
return;
}
auto onGoodResult = [r, reply](std::string reason) {
r->routePoker().Enable();
r->routePoker().Up();
reply(CreateJSONResponse(reason));
};
if (not shouldSendAuth)
{
onGoodResult("OK");
return;
}
ctx->AsyncSendAuth(
[onGoodResult, reply](service::AuthResult result) {
// TODO: refactor this code. We are 5 lambdas deep here!
if (result.code != service::AuthResultCode::eAuthAccepted)
{
reply(CreateJSONError(result.reason));
return;
}
onGoodResult(result.reason);
});
},
5s);
};
if (exit.has_value())
{
mapExit(*exit);
}
else if (lnsExit.has_value())
{
ep->LookupNameAsync(*lnsExit, [reply, mapExit](auto maybe) mutable {
if (not maybe.has_value())
ep->EnsurePathToService(
addr,
[reply, r, shouldSendAuth](auto, service::OutboundContext* ctx) {
if (ctx == nullptr)
{
reply(CreateJSONError("we could not find an exit with that name"));
reply(CreateJSONError("could not find exit"));
return;
}
if (maybe->IsZero())
auto onGoodResult = [r, reply](std::string reason) {
r->routePoker().Enable();
r->routePoker().Up();
reply(CreateJSONResponse(reason));
};
if (not shouldSendAuth)
{
reply(CreateJSONError("lokinet exit does not exist"));
onGoodResult("OK");
return;
}
mapExit(*maybe);
});
ctx->AsyncSendAuth([onGoodResult, reply](service::AuthResult result) {
// TODO: refactor this code. We are 5 lambdas deep here!
if (result.code != service::AuthResultCode::eAuthAccepted)
{
reply(CreateJSONError(result.reason));
return;
}
onGoodResult(result.reason);
});
},
5s);
};
if (exit.has_value())
{
mapExit(*exit);
}
else if (lnsExit.has_value())
{
ep->LookupNameAsync(*lnsExit, [reply, mapExit](auto maybe) mutable {
if (not maybe.has_value())
{
reply(CreateJSONError("we could not find an exit with that name"));
return;
}
else
if (maybe->IsZero())
{
reply(
CreateJSONError("WTF inconsistent request, no exit address or lns "
"name provided?"));
reply(CreateJSONError("lokinet exit does not exist"));
return;
}
return;
}
else if (map and not exit.has_value())
{
reply(CreateJSONError("no exit address provided"));
return;
}
else if (not map)
{
r->routePoker().Down();
ep->UnmapExitRange(range);
}
reply(CreateJSONResponse("OK"));
});
mapExit(*maybe);
});
}
else
{
reply(
CreateJSONError("WTF inconsistent request, no exit address or lns "
"name provided?"));
}
return;
}
else if (map and not exit.has_value())
{
reply(CreateJSONError("no exit address provided"));
return;
}
else if (not map)
{
r->routePoker().Down();
ep->UnmapExitRange(range);
}
reply(CreateJSONResponse("OK"));
});
});
})
.add_request_command("config", [&](oxenmq::Message& msg) {

@ -10,7 +10,7 @@ namespace llarp
namespace service
{
AsyncKeyExchange::AsyncKeyExchange(
EventLoop_ptr l,
EventLoop_ptr l,
ServiceInfo r,
const Identity& localident,
const PQPubKey& introsetPubKey,

@ -11,7 +11,7 @@ namespace llarp
{
struct AsyncKeyExchange : public std::enable_shared_from_this<AsyncKeyExchange>
{
EventLoop_ptr loop;
EventLoop_ptr loop;
SharedSecret sharedKey;
ServiceInfo m_remote;
const Identity& m_LocalIdentity;
@ -24,7 +24,7 @@ namespace llarp
ConvoTag tag;
AsyncKeyExchange(
EventLoop_ptr l,
EventLoop_ptr l,
ServiceInfo r,
const Identity& localident,
const PQPubKey& introsetPubKey,

@ -988,9 +988,7 @@ namespace llarp
}
else
{
Router()->loop()->call([h = std::move(hook)] {
h({AuthResultCode::eAuthAccepted, "OK"});
});
Router()->loop()->call([h = std::move(hook)] { h({AuthResultCode::eAuthAccepted, "OK"}); });
}
}

@ -24,7 +24,8 @@ namespace llarp
auto msg = BuildRequestMessage();
if (!msg)
return false;
r->loop()->call([path=std::move(path), msg=std::move(msg), r] { path->SendRoutingMessage(*msg, r); });
r->loop()->call(
[path = std::move(path), msg = std::move(msg), r] { path->SendRoutingMessage(*msg, r); });
return true;
}
} // namespace service

@ -211,7 +211,9 @@ namespace llarp
currentConvoTag,
t);
ex->hook = [self = shared_from_this(), path](auto frame) { self->Send(std::move(frame), path); };
ex->hook = [self = shared_from_this(), path](auto frame) {
self->Send(std::move(frame), path);
};
ex->msg.PutBuffer(payload);
ex->msg.introReply = path->intro;

@ -278,7 +278,7 @@ namespace llarp
const Introduction fromIntro;
AsyncFrameDecrypt(
EventLoop_ptr l,
EventLoop_ptr l,
const Identity& localIdent,
Endpoint* h,
std::shared_ptr<ProtocolMessage> m,
@ -402,7 +402,7 @@ namespace llarp
bool
ProtocolFrame::AsyncDecryptAndVerify(
EventLoop_ptr loop,
EventLoop_ptr loop,
path::Path_ptr recvPath,
const Identity& localIdent,
Endpoint* handler,
@ -438,7 +438,7 @@ namespace llarp
auto callback = [loop, hook](std::shared_ptr<ProtocolMessage> msg) {
if (hook)
{
loop->call([msg, hook]() { hook(msg); });
loop->call([msg, hook]() { hook(msg); });
}
};
handler->Router()->QueueWork(

@ -125,7 +125,7 @@ namespace llarp
bool
AsyncDecryptAndVerify(
EventLoop_ptr loop,
EventLoop_ptr loop,
path::Path_ptr fromPath,
const Identity& localIdent,
Endpoint* handler,

@ -5,9 +5,7 @@
namespace tooling
{
HiveRouter::HiveRouter(
llarp::EventLoop_ptr loop,
std::shared_ptr<llarp::vpn::Platform> plat,
RouterHive* hive)
llarp::EventLoop_ptr loop, std::shared_ptr<llarp::vpn::Platform> plat, RouterHive* hive)
: Router(loop, plat), m_hive(hive)
{}

@ -74,11 +74,11 @@ namespace tooling
llarp::LogInfo("Signalling all routers to stop");
for (auto& [routerId, ctx] : relays)
{
ctx->mainloop->call([ctx=ctx]() { ctx->HandleSignal(SIGINT); });
ctx->mainloop->call([ctx = ctx]() { ctx->HandleSignal(SIGINT); });
}
for (auto& [routerId, ctx] : clients)
{
ctx->mainloop->call([ctx=ctx]() { ctx->HandleSignal(SIGINT); });
ctx->mainloop->call([ctx = ctx]() { ctx->HandleSignal(SIGINT); });
}
llarp::LogInfo("Waiting on routers to be stopped");
@ -180,7 +180,7 @@ namespace tooling
size_t done_count = 0;
for (auto& [routerId, ctx] : relays)
{
ctx->mainloop->call([&, i, ctx=ctx]() {
ctx->mainloop->call([&, i, ctx = ctx]() {
size_t count = ctx->router->NumberOfConnectedRouters();
std::lock_guard guard{results_lock};
results[i] = count;

Loading…
Cancel
Save