|
|
|
@ -402,7 +402,7 @@ namespace llarp::rpc
|
|
|
|
|
{
|
|
|
|
|
service::Address addr;
|
|
|
|
|
const auto exit_str = exit_itr->get<std::string>();
|
|
|
|
|
if (service::NameIsValid(exit_str))
|
|
|
|
|
if (service::NameIsValid(exit_str) or exit_str == "null")
|
|
|
|
|
{
|
|
|
|
|
lnsExit = exit_str;
|
|
|
|
|
}
|
|
|
|
@ -456,39 +456,54 @@ namespace llarp::rpc
|
|
|
|
|
{
|
|
|
|
|
auto mapExit = [=](service::Address addr) mutable {
|
|
|
|
|
ep->MapExitRange(range, addr);
|
|
|
|
|
r->routePoker().Enable();
|
|
|
|
|
r->routePoker().Up();
|
|
|
|
|
bool shouldSendAuth = false;
|
|
|
|
|
if (token.has_value())
|
|
|
|
|
{
|
|
|
|
|
shouldSendAuth = true;
|
|
|
|
|
ep->SetAuthInfoForEndpoint(*exit, service::AuthInfo{*token});
|
|
|
|
|
}
|
|
|
|
|
auto onGoodResult = [r, reply](std::string reason) {
|
|
|
|
|
if (r->HasClientExit())
|
|
|
|
|
reply(CreateJSONResponse(reason));
|
|
|
|
|
else
|
|
|
|
|
reply(CreateJSONError("we dont have an exit?"));
|
|
|
|
|
};
|
|
|
|
|
auto onBadResult = [r, reply, ep, range](std::string reason) {
|
|
|
|
|
r->routePoker().Down();
|
|
|
|
|
ep->UnmapExitRange(range);
|
|
|
|
|
reply(CreateJSONError(reason));
|
|
|
|
|
};
|
|
|
|
|
if (addr.IsZero())
|
|
|
|
|
{
|
|
|
|
|
onGoodResult("added null exit");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ep->EnsurePathToService(
|
|
|
|
|
addr,
|
|
|
|
|
[reply, r, shouldSendAuth](auto, service::OutboundContext* ctx) {
|
|
|
|
|
[onBadResult, onGoodResult, shouldSendAuth, addrStr = addr.ToString()](
|
|
|
|
|
auto, service::OutboundContext* ctx) {
|
|
|
|
|
if (ctx == nullptr)
|
|
|
|
|
{
|
|
|
|
|
reply(CreateJSONError("could not find exit"));
|
|
|
|
|
onBadResult("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");
|
|
|
|
|
onGoodResult("OK: connected to " + addrStr);
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
ctx->AsyncSendAuth(
|
|
|
|
|
[onGoodResult, onBadResult](service::AuthResult result) {
|
|
|
|
|
// TODO: refactor this code. We are 5 lambdas deep here!
|
|
|
|
|
if (result.code != service::AuthResultCode::eAuthAccepted)
|
|
|
|
|
{
|
|
|
|
|
onBadResult(result.reason);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
onGoodResult(result.reason);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
5s);
|
|
|
|
|
};
|
|
|
|
@ -521,7 +536,6 @@ namespace llarp::rpc
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reply(CreateJSONError("lns name resolved to a snode"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|