diff --git a/cmake/win32_installer_deps.cmake b/cmake/win32_installer_deps.cmake index 07d0ed39f..ab59ef540 100644 --- a/cmake/win32_installer_deps.cmake +++ b/cmake/win32_installer_deps.cmake @@ -43,4 +43,3 @@ set(CPACK_NSIS_DELETE_ICONS_EXTRA get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) list(REMOVE_ITEM CPACK_COMPONENTS_ALL "Unspecified") -list(APPEND CPACK_COMPONENTS_ALL liblokinet) diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 2f114a280..9e9043b87 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -292,6 +292,13 @@ namespace llarp virtual bool ConnectionToRouterAllowed(const RouterID& router) const = 0; + /// return true if we have an exit as a client + virtual bool + HasClientExit() const + { + return false; + }; + virtual path::BuildLimiter& pathBuildLimiter() = 0; diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 188f2c0ee..b1277ed69 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -402,7 +402,7 @@ namespace llarp /// return true if we are a client with an exit configured bool - HasClientExit() const; + HasClientExit() const override; const byte_t* pubkey() const override diff --git a/llarp/rpc/rpc_server.cpp b/llarp/rpc/rpc_server.cpp index 7e7ed9eba..ef5977dbc 100644 --- a/llarp/rpc/rpc_server.cpp +++ b/llarp/rpc/rpc_server.cpp @@ -456,38 +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(); - 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); }; @@ -520,7 +536,6 @@ namespace llarp::rpc else { reply(CreateJSONError("lns name resolved to a snode")); - return; } }); }