aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
authorLee *!* Clagett <code@leeclagett.com>2024-08-17 18:37:10 -0400
committerlschomaker1 <lucas.schomaker12@gmail.com>2026-04-16 15:52:05 -0500
commitce5437f0677966c15d2946bc7c068975aa6bfd83 (patch)
treefe34f64934e00f27f4308f6747a0c32efd2edfcd /src/p2p
parent54b803603cf0fb450a9b9436b9fe85452e75966f (diff)
downloadmonzero-core-ce5437f0677966c15d2946bc7c068975aa6bfd83.tar.gz
monzero-core-ce5437f0677966c15d2946bc7c068975aa6bfd83.tar.xz
monzero-core-ce5437f0677966c15d2946bc7c068975aa6bfd83.zip
Add Socks v5 support to daemon and wallet
(cherry picked from commit 23e29a5074f01cbb781f7e76b0c17ad2b6797af0)
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/net_node.cpp41
-rw-r--r--src/p2p/net_node.h8
-rw-r--r--src/p2p/net_node.inl4
3 files changed, 30 insertions, 23 deletions
diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp
index 4111b0b71..a06511785 100644
--- a/src/p2p/net_node.cpp
+++ b/src/p2p/net_node.cpp
@@ -81,7 +81,7 @@ namespace
return {std::move(*address)};
}
- bool start_socks(std::shared_ptr<net::socks::client> client, const boost::asio::ip::tcp::endpoint& proxy, const epee::net_utils::network_address& remote)
+ bool start_socks(std::shared_ptr<net::socks::client> client, const net::socks::endpoint& proxy, const epee::net_utils::network_address& remote)
{
CHECK_AND_ASSERT_MES(client != nullptr, false, "Unexpected null client");
@@ -89,21 +89,28 @@ namespace
switch (remote.get_type_id())
{
case net::tor_address::get_type_id():
- set = client->set_connect_command(remote.as<net::tor_address>());
+ set = client->set_connect_command(remote.as<net::tor_address>(), std::addressof(proxy.userinfo));
break;
case net::i2p_address::get_type_id():
- set = client->set_connect_command(remote.as<net::i2p_address>());
+ set = client->set_connect_command(remote.as<net::i2p_address>(), std::addressof(proxy.userinfo));
break;
case epee::net_utils::ipv4_network_address::get_type_id():
- set = client->set_connect_command(remote.as<epee::net_utils::ipv4_network_address>());
+ set = client->set_connect_command(remote.as<epee::net_utils::ipv4_network_address>(), std::addressof(proxy.userinfo));
break;
+ case epee::net_utils::ipv6_network_address::get_type_id():
+ if (client->socks_version() == net::socks::version::v5)
+ {
+ set = client->set_connect_command(remote.as<epee::net_utils::ipv6_network_address>(), std::addressof(proxy.userinfo));
+ break;
+ }
+ /* fallthrough */
default:
- MERROR("Unsupported network address in socks_connect");
+ MERROR("Unsupported network address in socks_connect. Try socks5://");
return false;
}
const bool sent =
- set && net::socks::client::connect_and_send(std::move(client), proxy);
+ set && net::socks::client::connect_and_send(std::move(client), proxy.address);
CHECK_AND_ASSERT_MES(sent, false, "Unexpected failure to init socks client");
return true;
}
@@ -147,7 +154,7 @@ namespace nodetool
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_exclusive_node = {"add-exclusive-node", "Specify list of peers to connect to only."
" If this option is given the options add-priority-node and seed-node are ignored"};
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_seed_node = {"seed-node", "Connect to a node to retrieve peer addresses, and disconnect"};
- const command_line::arg_descriptor<std::vector<std::string> > arg_tx_proxy = {"tx-proxy", "Send local txes through proxy: <network-type>,<socks-ip:port>[,max_connections][,disable_noise] i.e. \"tor,127.0.0.1:9050,100,disable_noise\""};
+ const command_line::arg_descriptor<std::vector<std::string> > arg_tx_proxy = {"tx-proxy", "Send local txes through proxy: <network-type>,[socks5://[user:pass@]]<socks-ip:port>[,max_connections][,disable_noise] i.e. \"tor,127.0.0.1:9050,100,disable_noise\""};
const command_line::arg_descriptor<std::vector<std::string> > arg_anonymous_inbound = {"anonymous-inbound", "<hidden-service-address>,<[bind-ip:]port>[,max_connections] i.e. \"x.onion,127.0.0.1:18083,100\""};
const command_line::arg_descriptor<std::string> arg_ban_list = {"ban-list", "Specify ban list file, one IP address per line"};
const command_line::arg_descriptor<bool> arg_p2p_hide_my_port = {"hide-my-port", "Do not announce yourself as peerlist candidate", false, true};
@@ -189,7 +196,7 @@ namespace nodetool
const boost::string_ref zone{next->begin(), next->size()};
++next;
- CHECK_AND_ASSERT_MES(!next.eof() && !next->empty(), boost::none, "No ipv4:port given for --" << arg_tx_proxy.name);
+ CHECK_AND_ASSERT_MES(!next.eof() && !next->empty(), boost::none, "No ip:port given for --" << arg_tx_proxy.name);
const boost::string_ref proxy{next->begin(), next->size()};
++next;
@@ -227,14 +234,14 @@ namespace nodetool
return boost::none;
}
- std::uint32_t ip = 0;
- std::uint16_t port = 0;
- if (!epee::string_tools::parse_peer_from_string(ip, port, std::string{proxy}) || port == 0)
+ auto endpoint = net::socks::endpoint::get(proxy);
+ if (!endpoint)
{
- MERROR("Invalid ipv4:port given for --" << arg_tx_proxy.name);
+ MERROR("Invalid --" << arg_tx_proxy.name << " value: " << endpoint.error().message());
return boost::none;
}
- proxies.back().address = ip::tcp::endpoint{ip::address_v4{boost::endian::native_to_big(ip)}, port};
+
+ proxies.back().address = std::move(*endpoint);
}
return proxies;
@@ -327,7 +334,7 @@ namespace nodetool
}
boost::optional<boost::asio::ip::tcp::socket>
- socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_context& service, const boost::asio::ip::tcp::endpoint& proxy, const epee::net_utils::network_address& remote)
+ socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_context& service, const net::socks::endpoint& proxy, const epee::net_utils::network_address& remote)
{
using socket_type = net::socks::client::stream_type::socket;
using client_result = std::pair<boost::system::error_code, socket_type>;
@@ -349,7 +356,7 @@ namespace nodetool
socks_result = socks_promise.get_future();
auto client = net::socks::make_connect_client(
- boost::asio::ip::tcp::socket{service}, net::socks::version::v4a, notify{std::move(socks_promise)}
+ boost::asio::ip::tcp::socket{service}, proxy.ver, notify{std::move(socks_promise)}
);
close_client.self = client;
if (!start_socks(std::move(client), proxy, remote))
@@ -361,7 +368,7 @@ namespace nodetool
{
if (socks_connect_timeout < std::chrono::steady_clock::now() - start)
{
- MERROR("Timeout on socks connect (" << proxy << " to " << remote.str() << ")");
+ MERROR("Timeout on socks connect (" << proxy.address << " to " << remote.str() << ")");
return boost::none;
}
@@ -378,7 +385,7 @@ namespace nodetool
return {std::move(result.second)};
}
- MERROR("Failed to make socks connection to " << remote.str() << " (via " << proxy << "): " << result.first.message());
+ MERROR("Failed to make socks connection to " << remote.str() << " (via " << proxy.address << "): " << result.first.message());
}
catch (boost::broken_promise const&)
{}
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 423e2607e..edd3e31fa 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -56,7 +56,7 @@
#include "math_helper.h"
#include "net_node_common.h"
#include "net/enums.h"
-#include "net/fwd.h"
+#include "net/parse.h"
#include "common/command_line.h"
PUSH_WARNINGS
@@ -74,7 +74,7 @@ namespace nodetool
{}
std::int64_t max_connections;
- boost::asio::ip::tcp::endpoint address;
+ net::socks::endpoint address;
epee::net_utils::zone zone;
bool noise;
};
@@ -104,7 +104,7 @@ namespace nodetool
// hides boost::future and chrono stuff from mondo template file
boost::optional<boost::asio::ip::tcp::socket>
- socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_context& service, const boost::asio::ip::tcp::endpoint& proxy, const epee::net_utils::network_address& remote);
+ socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_context& service, const net::socks::endpoint& proxy, const epee::net_utils::network_address& remote);
template<class base_type>
@@ -216,7 +216,7 @@ namespace nodetool
epee::net_utils::network_address m_our_address; // in anonymity networks
peerlist_manager m_peerlist;
config m_config;
- boost::asio::ip::tcp::endpoint m_proxy_address;
+ net::socks::endpoint m_proxy_address;
std::atomic<unsigned int> m_current_number_of_out_peers;
std::atomic<unsigned int> m_current_number_of_in_peers;
boost::shared_mutex m_seed_nodes_lock;
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index bca8a52af..d22e7f9e5 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -928,8 +928,8 @@ namespace nodetool
CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line");
if (proxy.size())
{
- const auto endpoint = net::get_tcp_endpoint(proxy);
- CHECK_AND_ASSERT_MES(endpoint, false, "Failed to parse proxy: " << proxy << " - " << endpoint.error());
+ const auto endpoint = net::socks::endpoint::get(proxy);
+ CHECK_AND_ASSERT_MES(endpoint, false, "Failed to parse proxy: " << proxy << " - " << endpoint.error().message());
network_zone& public_zone = m_network_zones[epee::net_utils::zone::public_];
public_zone.m_connect = &socks_connect;
public_zone.m_proxy_address = *endpoint;