added unmapexit and listexit endpoints

This commit is contained in:
dan 2023-01-24 09:44:02 -08:00
parent d37398a915
commit d3e69fe3c5
6 changed files with 120 additions and 35 deletions

View File

@ -223,11 +223,11 @@ main(int argc, char* argv[])
}
if (options.vpnUp)
{
nlohmann::json opts{{"exit", options.exitAddress}, {"token", options.token}};
nlohmann::json opts{{"address", options.exitAddress}, {"token", options.token}};
if (options.range)
opts["range"] = *options.range;
opts["IP_range"] = *options.range;
auto maybe_result = OMQ_Request(omq, connectionID, "llarp.exit", std::move(opts));
auto maybe_result = OMQ_Request(omq, connectionID, "llarp.map_exit", std::move(opts));
if (not maybe_result)
return exit_error("could not add exit");

View File

@ -13,6 +13,7 @@
#include <oxenmq/address.h>
#include <oxen/log/omq_logger.hpp>
#include <unordered_map>
#include <vector>
namespace llarp::rpc
{
@ -158,29 +159,25 @@ namespace llarp::rpc
} request;
};
// RPC: exit
// Seems like this adds an exit node?
//
// Note: ask Jason about the internals of this
// RPC: map_exit
// Map a new connection to an exit node
//
// Inputs:
// "endpoint" :
// "unmap" : if true, unmaps connection to exit node (bool)
// "address" : ID of endpoint to map
// "range" : IP range to map to exit node
// "token" :
// "token" : auth token
//
// Returns:
//
struct Exit : RPCRequest
struct MapExit : RPCRequest
{
static constexpr auto name = "exit"sv;
static constexpr auto name = "map_exit"sv;
struct request_parameters
{
std::string address;
std::string ip_range;
std::vector<std::string> ip_range;
std::string token;
bool unmap;
} request;
void
@ -246,6 +243,38 @@ namespace llarp::rpc
}
};
// RPC: list_exits
// List all currently mapped exit node connections
//
// Inputs: none
//
// Returns:
//
struct ListExits : NoArgs
{
static constexpr auto name = "list_exits"sv;
};
// RPC: unmap_exit
// Unmap a connection to an exit node
//
// Inputs:
// "endpoint" : ID of endpoint to map
// "range" : IP range to map to exit node
// "token" : auth token
//
// Returns:
//
struct UnmapExit : RPCRequest
{
static constexpr auto name = "unmap_exit"sv;
struct request_parameters
{
std::vector<std::string> ip_range;
} request;
};
// RPC: dns_query
// Attempts to query endpoint by domain name
//
@ -301,7 +330,9 @@ namespace llarp::rpc
QuicConnect,
QuicListener,
LookupSnode,
Exit,
MapExit,
ListExits,
UnmapExit,
DNSQuery,
Config>;

View File

@ -1,4 +1,5 @@
#include "rpc_request_parser.hpp"
#include "llarp/rpc/rpc_request_definitions.hpp"
#include "param_parser.hpp"
#include <string_view>
#include <llarp/config/config.hpp>
@ -51,18 +52,25 @@ namespace llarp::rpc
}
void
parse_request(Exit& exit, rpc_input input)
parse_request(MapExit& mapexit, rpc_input input)
{
get_values(
input,
"address",
exit.request.address,
mapexit.request.address,
"IP_range",
exit.request.ip_range,
mapexit.request.ip_range,
"token",
exit.request.token,
"unmap",
exit.request.unmap);
mapexit.request.token);
}
void
parse_request(UnmapExit& unmapexit, rpc_input input)
{
get_values(
input,
"IP_range",
unmapexit.request.ip_range);
}
void

View File

@ -22,7 +22,9 @@ namespace llarp::rpc
void
parse_request(LookupSnode& lookupsnode, rpc_input input);
void
parse_request(Exit& exit, rpc_input input);
parse_request(MapExit& mapexit, rpc_input input);
void
parse_request(UnmapExit& unmapexit, rpc_input input);
void
parse_request(DNSQuery& dnsquery, rpc_input input);
void

View File

@ -1,6 +1,8 @@
#include "rpc_server.hpp"
#include "llarp/rpc/rpc_request_definitions.hpp"
#include "rpc_request.hpp"
#include "llarp/service/address.hpp"
#include <exception>
#include <llarp/router/route_poker.hpp>
#include <llarp/config/config.hpp>
#include <llarp/config/ini.hpp>
@ -16,6 +18,7 @@
#include <llarp/service/name.hpp>
#include <llarp/router/abstractrouter.hpp>
#include <llarp/dns/dns.hpp>
#include <vector>
#include <oxenmq/fmt.h>
namespace llarp::rpc
@ -346,22 +349,59 @@ namespace llarp::rpc
});
}
// get a ptr/ref to something in the lokinet service endpoint
// call some fxn like "obtain_exit_to" and pass exit info
// plus optional additional info on how to map
// plus callback to report when this happens
// callback is called much later (1-2s) when exit node flow is secured
// exit is now ready to use
//
void
RPCServer::invoke(Exit& exit)
RPCServer::invoke(MapExit& mapexit)
{
Exit exit_request;
MapExit exit_request;
// steal replier from exit RPC endpoint
exit_request.replier.emplace(std::move(*exit.replier));
exit_request.replier.emplace(std::move(*mapexit.replier));
//
//
//
//
//
}
IPRange range = IPRange::StringInit(exit.request.ip_range);
service::Address exitAddr{exit.request.address};
void
RPCServer::invoke(ListExits& listexits)
{
if (not m_Router.hiddenServiceContext().hasEndpoints())
listexits.response = CreateJSONError("No mapped endpoints found");
else
listexits.response = CreateJSONResponse(
m_Router.hiddenServiceContext().GetDefault()->ExtractStatus()["m_ExitMap"]);
}
void
RPCServer::invoke(UnmapExit& unmapexit)
{
if (unmapexit.request.ip_range.empty())
{
unmapexit.response = CreateJSONError("No IP range provided");
return;
}
std::vector<IPRange> range{};
for (auto& ip : unmapexit.request.ip_range)
{
try {
range.push_back(IPRange::StringInit(ip));
} catch (std::exception& e) {
unmapexit.response = CreateJSONError(e.what());
}
}
try {
m_Router.routePoker()->Down();
for (auto& ip : range)
m_Router.hiddenServiceContext().GetDefault()->UnmapExitRange(ip);
} catch (std::exception& e) {
unmapexit.response = CreateJSONError("Unable to unmap to given range");
}
unmapexit.response = CreateJSONResponse("OK");
}
void

View File

@ -103,7 +103,11 @@ namespace llarp::rpc
void
invoke(LookupSnode& lookupsnode);
void
invoke(Exit& exit);
invoke(MapExit& mapexit);
void
invoke(ListExits& listexits);
void
invoke(UnmapExit& unmapexit);
void
invoke(DNSQuery& dnsquery);
void