31#include <boost/algorithm/string/find_iterator.hpp>
32#include <boost/algorithm/string/finder.hpp>
33#include <boost/chrono/duration.hpp>
34#include <boost/endian/conversion.hpp>
35#include <boost/optional/optional.hpp>
36#include <boost/thread/future.hpp>
37#include <boost/utility/string_ref.hpp>
55 constexpr const boost::chrono::milliseconds future_poll_interval{500};
58 std::int64_t get_max_connections(
const boost::iterator_range<boost::string_ref::const_iterator>
value)
noexcept
64 std::uint32_t
out = 0;
92 set = client->set_connect_command(remote.as<
net::tor_address>());
95 set = client->set_connect_command(remote.as<
net::i2p_address>());
98 MERROR(
"Unsupported network address in socks_connect");
114 ,
"Port for p2p network protocol"
117 , [](std::array<bool, 2> testnet_stagenet,
bool defaulted, std::string val)->std::string {
118 if (testnet_stagenet[0] && defaulted)
120 else if (testnet_stagenet[1] && defaulted)
130 " If this option is given the options add-priority-node and seed-node are ignored"};
148 boost::optional<std::vector<proxy>>
get_proxies(boost::program_options::variables_map
const& vm)
150 namespace ip = boost::asio::ip;
152 std::vector<proxy> proxies{};
155 proxies.reserve(args.size());
157 for (
const boost::string_ref arg : args)
159 proxies.emplace_back();
161 auto next = boost::algorithm::make_split_iterator(arg, boost::algorithm::first_finder(
","));
163 const boost::string_ref zone{next->begin(), next->size()};
167 const boost::string_ref
proxy{next->begin(), next->size()};
172 proxies.back().max_connections = get_max_connections(*next);
173 if (proxies.back().max_connections == 0)
193 std::uint32_t ip = 0;
194 std::uint16_t port = 0;
200 proxies.back().address = ip::tcp::endpoint{ip::address_v4{boost::endian::native_to_big(ip)}, port};
208 std::vector<anonymous_inbound> inbounds{};
211 inbounds.reserve(args.size());
213 for (
const boost::string_ref arg : args)
215 inbounds.emplace_back();
217 auto next = boost::algorithm::make_split_iterator(arg, boost::algorithm::first_finder(
","));
219 const boost::string_ref
address{next->begin(), next->size()};
223 const boost::string_ref bind{next->begin(), next->size()};
225 const std::size_t colon = bind.find_first_of(
':');
231 inbounds.back().max_connections = get_max_connections(*next);
232 if (inbounds.back().max_connections == 0)
243 inbounds.back().our_address = std::move(*our_address);
247 inbounds.back().our_address = std::move(*our_address);
259 std::uint32_t ip = 0;
260 std::uint16_t port = 0;
266 inbounds.back().local_ip = std::string{bind.substr(0, colon)};
267 inbounds.back().local_port = std::string{bind.substr(colon + 1)};
288 MWARNING(
"Filtered command (#" << command <<
") to/from " <<
address.str());
292 boost::optional<boost::asio::ip::tcp::socket>
295 using socket_type = net::socks::client::stream_type::socket;
296 using client_result = std::pair<boost::system::error_code, socket_type>;
300 boost::promise<client_result> socks_promise;
302 void operator()(boost::system::error_code error, socket_type&& sock)
304 socks_promise.set_value(std::make_pair(error, std::move(sock)));
308 boost::unique_future<client_result> socks_result{};
310 boost::promise<client_result> socks_promise{};
311 socks_result = socks_promise.get_future();
316 if (!start_socks(std::move(client),
proxy, remote))
320 const auto start = std::chrono::steady_clock::now();
321 while (socks_result.wait_for(future_poll_interval) == boost::future_status::timeout)
323 if (socks_connect_timeout < std::chrono::steady_clock::now() - start)
325 MERROR(
"Timeout on socks connect (" <<
proxy <<
" to " << remote.
str() <<
")");
335 auto result = socks_result.get();
337 return {std::move(result.second)};
339 MERROR(
"Failed to make socks connection to " << remote.
str() <<
" (via " <<
proxy <<
"): " << result.first.message());
341 catch (boost::broken_promise
const&)
cryptonote::account_public_address get_address(const var_addr_t &inp)
address_type get_type_id() const
*return False if otherwise error()
static i2p_address unknown() noexcept
static constexpr epee::net_utils::address_type get_type_id() noexcept
static bool connect_and_send(std::shared_ptr< client > self, const stream_type::endpoint &proxy_address)
static constexpr epee::net_utils::address_type get_type_id() noexcept
static tor_address unknown() noexcept
#define P2P_DEFAULT_LIMIT_RATE_DOWN
#define P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT
#define P2P_DEFAULT_LIMIT_RATE_UP
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
uint16_t const P2P_DEFAULT_PORT
uint16_t const P2P_DEFAULT_PORT
uint16_t const P2P_DEFAULT_PORT
const command_line::arg_descriptor< bool, false > arg_testnet_on
const command_line::arg_descriptor< bool, false > arg_stagenet_on
zone zone_from_string(boost::string_ref value) noexcept
const char * zone_to_string(zone value) noexcept
std::shared_ptr< client > make_connect_client(client::stream_type::socket &&proxy, socks::version ver, Handler handler)
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
const GenericPointer< typename T::ValueType > T2 value