aboutsummaryrefslogtreecommitdiff
path: root/src/net/parse.cpp
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-16 12:52:21 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-16 12:52:21 -0700
commit01b512f3a91f2080f4fae0abfd19f3e0e1dc53e9 (patch)
treea8e7137064dd618b38bee9e35e6d989c77582001 /src/net/parse.cpp
parentMerge pull request #6715 (diff)
parentwallet2_api: implement runtime proxy configuration (diff)
downloadmonero-01b512f3a91f2080f4fae0abfd19f3e0e1dc53e9.tar.xz
Merge pull request #6716
76c16822d wallet2_api: implement runtime proxy configuration (xiphon)
Diffstat (limited to 'src/net/parse.cpp')
-rw-r--r--src/net/parse.cpp35
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;
+ }
}