review comments

pull/2121/head
dan 1 year ago
parent f6aa58482a
commit d37398a915

@ -29,7 +29,7 @@ namespace llarp
{
IPRange range{};
range.FromString(_range);
return range;
return range;
}
static constexpr IPRange

@ -43,15 +43,15 @@ namespace llarp::rpc
response_hex.format = llarp::rpc::json_binary_proxy::fmt::bt;
}
// Invoked if this.replier is still present. If it is "stolen" by endpoint (moved from
// Invoked if this.replier is still present. If it is "stolen" by endpoint (moved from
// RPC struct), then endpoint handles sending reply
void
send_response()
{
replier->reply(is_bt() ? oxenc::bt_serialize(json_to_bt(std::move(response)))
: response.dump());
replier->reply(
is_bt() ? oxenc::bt_serialize(json_to_bt(std::move(response))) : response.dump());
}
void
send_response(nlohmann::json _response)
{
@ -97,9 +97,9 @@ namespace llarp::rpc
// The oxenmq deferred send object into which the response will be set. If this optional is
// still set when the `invoke` call returns then the response is sent at that point; if it has
// been moved out (i.e. either just this instance or the whole request struct is stolen/moved by
// the invoke function) then it is the invoke function's job to send a reply. Typically this is
// done when a response cannot be sent immediately
// been moved out (i.e. either just this instance or the whole request struct is stolen/moved
// by the invoke function) then it is the invoke function's job to send a reply. Typically
// this is done when a response cannot be sent immediately
std::optional<oxenmq::Message::DeferredSend> replier;
};

@ -1,12 +1,12 @@
#pragma once
#include "rpc_request_decorators.hpp"
#include "net/ip_range.hpp"
#include "router/abstractrouter.hpp"
#include "router/route_poker.hpp"
#include "service/address.hpp"
#include "service/endpoint.hpp"
#include "service/outbound_context.hpp"
#include "llarp/net/ip_range.hpp"
#include "llarp/router/abstractrouter.hpp"
#include "llarp/router/route_poker.hpp"
#include "llarp/service/address.hpp"
#include "llarp/service/endpoint.hpp"
#include "llarp/service/outbound_context.hpp"
#include <string_view>
#include <llarp/config/config.hpp>
#include <oxenmq/oxenmq.h>
@ -164,10 +164,10 @@ namespace llarp::rpc
// Note: ask Jason about the internals of this
//
// Inputs:
// "endpoint" :
// "endpoint" :
// "unmap" : if true, unmaps connection to exit node (bool)
// "range" : IP range to map to exit node
// "token" :
// "token" :
//
// Returns:
//
@ -186,21 +186,26 @@ namespace llarp::rpc
void
onGoodResult(std::string reason, bool hasClient)
{
response = (hasClient) ?
nlohmann::json{{"result", reason}}.dump() :
nlohmann::json{{"error", "We don't have an exit?"}}.dump();
response = (hasClient) ? nlohmann::json{{"result", reason}}.dump()
: nlohmann::json{{"error", "We don't have an exit?"}}.dump();
}
void
onBadResult(std::string reason, AbstractRouter& abs, llarp::service::Endpoint_ptr eptr, IPRange range)
onBadResult(
std::string reason, AbstractRouter& abs, llarp::service::Endpoint_ptr eptr, IPRange range)
{
abs.routePoker()->Down();
eptr->UnmapExitRange(range);
response = nlohmann::json{{"result", reason}}.dump();
}
void
mapExit(service::Address addr, AbstractRouter& router, llarp::service::Endpoint_ptr eptr, IPRange range, service::Address exitAddr)
void
mapExit(
service::Address addr,
AbstractRouter& router,
llarp::service::Endpoint_ptr eptr,
IPRange range,
service::Address exitAddr)
{
eptr->MapExitRange(range, addr);

@ -1,6 +1,6 @@
#include "rpc_server.hpp"
#include "rpc_request.hpp"
#include "service/address.hpp"
#include "llarp/service/address.hpp"
#include <llarp/router/route_poker.hpp>
#include <llarp/config/config.hpp>
#include <llarp/config/ini.hpp>
@ -85,7 +85,7 @@ namespace llarp::rpc
template <typename RPC>
void
register_rpc_command(std::unordered_map<std::string, std::shared_ptr<const rpc_callback>>& regs)
register_rpc_command(std::unordered_map<std::string, rpc_callback>& regs)
{
static_assert(std::is_base_of_v<RPCRequest, RPC>);
auto cback = std::make_shared<rpc_callback>();
@ -109,17 +109,17 @@ namespace llarp::rpc
}
template <typename... RPC>
std::unordered_map<std::string, std::shared_ptr<const rpc_callback>>
std::unordered_map<std::string, rpc_callback>
register_rpc_requests(tools::type_list<RPC...>)
{
std::unordered_map<std::string, std::shared_ptr<const rpc_callback>> regs;
std::unordered_map<std::string, rpc_callback> regs;
(register_rpc_command<RPC>(regs), ...);
return regs;
}
const std::unordered_map<std::string, std::shared_ptr<const rpc_callback>> rpc_request_map =
const std::unordered_map<std::string, rpc_callback> rpc_request_map =
register_rpc_requests(rpc::rpc_request_types{});
void
@ -133,7 +133,7 @@ namespace llarp::rpc
m_LMQ->add_request_command(
"llarp",
req.first,
[name = std::string_view{req.first}, &call = *req.second, this](oxenmq::Message& m) {
[name = std::string_view{req.first}, &call = req.second, this](oxenmq::Message& m) {
call.invoke(m, *this);
});
}
@ -352,7 +352,7 @@ namespace llarp::rpc
// 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)
{
@ -362,9 +362,6 @@ namespace llarp::rpc
IPRange range = IPRange::StringInit(exit.request.ip_range);
service::Address exitAddr{exit.request.address};
m_Router.hiddenServiceContext().GetDefault()->MapExitRange(range, exitAddr);
}
void

@ -38,7 +38,7 @@ namespace llarp::rpc
// Stores references to RPC requests in a unordered map for ease of reference
// when adding to server. To add endpoints, define in rpc_request_definitions.hpp
// and register in rpc_server.cpp
extern const std::unordered_map<std::string, std::shared_ptr<const rpc_callback>> rpc_request_map;
extern const std::unordered_map<std::string, rpc_callback> rpc_request_map;
// Exception used to signal various types of errors with a request back to the caller. This
// exception indicates that the caller did something wrong: bad data, invalid value, etc., but
@ -121,8 +121,7 @@ namespace llarp::rpc
RPCServer& server;
RPC rpc{};
EndpointHandler(RPCServer& _server, DeferredSend _replier)
: server{_server}
EndpointHandler(RPCServer& _server, DeferredSend _replier) : server{_server}
{
rpc.replier.emplace(std::move(_replier));
}
@ -145,7 +144,7 @@ namespace llarp::rpc
log::info(logcat, "RPC request 'rpc.{}' raised an exception: {}", rpc.name, e.what());
rpc.response = CreateJSONError(
fmt::format("RPC request 'rpc.{}' raised an exception: {}", rpc.name, e.what()));
};
}
// check if std::optional in rpc is present
// then rpc.send_response

Loading…
Cancel
Save