diff options
author | xiphon <xiphon@protonmail.com> | 2020-07-20 04:31:58 +0000 |
---|---|---|
committer | xiphon <xiphon@protonmail.com> | 2020-07-20 13:45:12 +0000 |
commit | 76c16822d09fbebbc792dc999ea2d3432a63253a (patch) | |
tree | e7b5e168f20c2f9a7b8a8e1e3dddd849e2f396f8 /src/net/parse.cpp | |
parent | Merge pull request #6586 (diff) | |
download | monero-76c16822d09fbebbc792dc999ea2d3432a63253a.tar.xz |
wallet2_api: implement runtime proxy configuration
Diffstat (limited to 'src/net/parse.cpp')
-rw-r--r-- | src/net/parse.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/net/parse.cpp b/src/net/parse.cpp index ce580afe7..95b22cd44 100644 --- a/src/net/parse.cpp +++ b/src/net/parse.cpp @@ -122,4 +122,39 @@ namespace net return {epee::net_utils::ipv4_network_subnet{ip, (uint8_t)mask}}; } + + expect<boost::asio::ip::tcp::endpoint> get_tcp_endpoint(const boost::string_ref address) + { + uint16_t port = 0; + expect<epee::net_utils::network_address> parsed = get_network_address(address, port); + if (!parsed) + { + return parsed.error(); + } + + boost::asio::ip::tcp::endpoint result; + switch (parsed->get_type_id()) + { + case epee::net_utils::ipv4_network_address::get_type_id(): + { + const auto &ipv4 = parsed->as<epee::net_utils::ipv4_network_address>(); + result = boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4(ipv4.ip()), ipv4.port()); + break; + } + case epee::net_utils::ipv6_network_address::get_type_id(): + { + const auto &ipv6 = parsed->as<epee::net_utils::ipv6_network_address>(); + result = boost::asio::ip::tcp::endpoint(ipv6.ip(), ipv6.port()); + break; + } + default: + return make_error_code(net::error::unsupported_address); + } + if (result.port() == 0) + { + return make_error_code(net::error::invalid_port); + } + + return result; + } } |