mirror of https://github.com/oxen-io/lokinet
RPC: Relax token/range argument handling
- Accept empty string or `null` for token to mean "no token." - Accept `null` for range to mean "default range." - Don't use a default range (::0/0) in lokinet-vpn because this will fail if IPv6 ranges aren't supported on the platform (e.g. on Windows), and isn't necessary: if we omit it then the rpc code already uses ::0/0 or 0.0.0.0/0 by default, as needed.
This commit is contained in:
parent
8b321612da
commit
71ea4f4fa2
|
@ -74,8 +74,8 @@ main(int argc, char* argv[])
|
||||||
oxenmq::address rpcURL("tcp://127.0.0.1:1190");
|
oxenmq::address rpcURL("tcp://127.0.0.1:1190");
|
||||||
std::string exitAddress;
|
std::string exitAddress;
|
||||||
std::string endpoint = "default";
|
std::string endpoint = "default";
|
||||||
std::optional<std::string> token;
|
std::string token;
|
||||||
std::string range = "::/0";
|
std::optional<std::string> range;
|
||||||
oxenmq::LogLevel logLevel = oxenmq::LogLevel::warn;
|
oxenmq::LogLevel logLevel = oxenmq::LogLevel::warn;
|
||||||
bool goUp = false;
|
bool goUp = false;
|
||||||
bool goDown = false;
|
bool goDown = false;
|
||||||
|
@ -216,20 +216,11 @@ main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
if (goUp)
|
if (goUp)
|
||||||
{
|
{
|
||||||
std::optional<nlohmann::json> maybe_result;
|
nlohmann::json opts{{"exit", exitAddress}, {"token", token}};
|
||||||
if (token.has_value())
|
if (range)
|
||||||
{
|
opts["range"] = *range;
|
||||||
maybe_result = LMQ_Request(
|
|
||||||
lmq,
|
auto maybe_result = LMQ_Request(lmq, connID, "llarp.exit", opts);
|
||||||
connID,
|
|
||||||
"llarp.exit",
|
|
||||||
nlohmann::json{{"exit", exitAddress}, {"range", range}, {"token", *token}});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maybe_result = LMQ_Request(
|
|
||||||
lmq, connID, "llarp.exit", nlohmann::json{{"exit", exitAddress}, {"range", range}});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not maybe_result.has_value())
|
if (not maybe_result.has_value())
|
||||||
{
|
{
|
||||||
|
@ -245,7 +236,10 @@ main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
if (goDown)
|
if (goDown)
|
||||||
{
|
{
|
||||||
LMQ_Request(lmq, connID, "llarp.exit", nlohmann::json{{"range", range}, {"unmap", true}});
|
nlohmann::json opts{{"unmap", true}};
|
||||||
|
if (range)
|
||||||
|
opts["range"] = *range;
|
||||||
|
LMQ_Request(lmq, connID, "llarp.exit", std::move(opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -469,7 +469,7 @@ namespace llarp::rpc
|
||||||
map = false;
|
map = false;
|
||||||
}
|
}
|
||||||
const auto range_itr = obj.find("range");
|
const auto range_itr = obj.find("range");
|
||||||
if (range_itr == obj.end())
|
if (range_itr == obj.end() or range_itr->is_null())
|
||||||
{
|
{
|
||||||
// platforms without ipv6 support will shit themselves
|
// platforms without ipv6 support will shit themselves
|
||||||
// here if we give them an exit mapping that is ipv6
|
// here if we give them an exit mapping that is ipv6
|
||||||
|
@ -492,9 +492,9 @@ namespace llarp::rpc
|
||||||
reply(CreateJSONError("ipv6 ranges not supported on this platform"));
|
reply(CreateJSONError("ipv6 ranges not supported on this platform"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::optional<std::string> token;
|
std::string token;
|
||||||
const auto token_itr = obj.find("token");
|
const auto token_itr = obj.find("token");
|
||||||
if (token_itr != obj.end())
|
if (token_itr != obj.end() and not token_itr->is_null())
|
||||||
{
|
{
|
||||||
token = token_itr->get<std::string>();
|
token = token_itr->get<std::string>();
|
||||||
}
|
}
|
||||||
|
@ -518,10 +518,10 @@ namespace llarp::rpc
|
||||||
ep->MapExitRange(range, addr);
|
ep->MapExitRange(range, addr);
|
||||||
|
|
||||||
bool shouldSendAuth = false;
|
bool shouldSendAuth = false;
|
||||||
if (token.has_value())
|
if (not token.empty())
|
||||||
{
|
{
|
||||||
shouldSendAuth = true;
|
shouldSendAuth = true;
|
||||||
ep->SetAuthInfoForEndpoint(*exit, service::AuthInfo{*token});
|
ep->SetAuthInfoForEndpoint(*exit, service::AuthInfo{token});
|
||||||
}
|
}
|
||||||
auto onGoodResult = [r, reply](std::string reason) {
|
auto onGoodResult = [r, reply](std::string reason) {
|
||||||
if (r->HasClientExit())
|
if (r->HasClientExit())
|
||||||
|
|
Loading…
Reference in New Issue