From 3fccb3ab0c12cbaa04ea289166895466e86dc77e Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 19 May 2022 09:41:43 -0400 Subject: [PATCH] fixup edge case on windows * add platform detection constexprs * add quark for platforms without native ipv6 like windows, exit mapping cannot work with ipv6 yet --- llarp/constants/platform.hpp | 65 ++++++++++++++++++++++++++++++++++++ llarp/rpc/rpc_server.cpp | 17 +++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 llarp/constants/platform.hpp diff --git a/llarp/constants/platform.hpp b/llarp/constants/platform.hpp new file mode 100644 index 000000000..eaaf14084 --- /dev/null +++ b/llarp/constants/platform.hpp @@ -0,0 +1,65 @@ +#pragma once + +/// namespace for platform feature detection constexprs +namespace llarp::platform +{ + /// are we linux ? + inline constexpr bool is_linux = +#ifdef __linux__ + true +#else + false +#endif + ; + + /// are we freebsd ? + inline constexpr bool is_freebsd = +#ifdef __FreeBSD__ + true +#else + false +#endif + ; + + /// are we windows ? + inline constexpr bool is_windows = +#ifdef _WIN32 + true +#else + false +#endif + ; + + /// are we an apple platform ? + inline constexpr bool is_apple = +#ifdef __apple__ + true +#else + false +#endif + ; + + /// are we an android platform ? + inline constexpr bool is_android = +#ifdef ANDROID + true +#else + false +#endif + ; + + /// are we an iphone ? + inline constexpr bool is_iphone = +#ifdef IOS + true +#else + false +#endif + ; + + /// are we a mobile phone ? + inline constexpr bool is_mobile = is_android or is_iphone; + + /// does this platform support native ipv6 ? + inline constexpr bool supports_ipv6 = not is_windows; +} // namespace llarp::platform diff --git a/llarp/rpc/rpc_server.cpp b/llarp/rpc/rpc_server.cpp index b85751a27..7bc2f3f42 100644 --- a/llarp/rpc/rpc_server.cpp +++ b/llarp/rpc/rpc_server.cpp @@ -1,5 +1,6 @@ #include "rpc_server.hpp" #include +#include #include #include #include @@ -432,13 +433,27 @@ namespace llarp::rpc const auto range_itr = obj.find("range"); if (range_itr == obj.end()) { - range.FromString("::/0"); + // platforms without ipv6 support will shit themselves + // here if we give them an exit mapping that is ipv6 + if constexpr (platform::supports_ipv6) + { + range.FromString("::/0"); + } + else + { + range.FromString("0.0.0.0/0"); + } } else if (not range.FromString(range_itr->get())) { reply(CreateJSONError("invalid ip range")); return; } + if (not platform::supports_ipv6 and not range.IsV4()) + { + reply(CreateJSONError("ipv6 ranges not supported on this platform")); + return; + } std::optional token; const auto token_itr = obj.find("token"); if (token_itr != obj.end())