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
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" 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)
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()};
173 if (proxies.back().max_connections == 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);
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>
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)
308 boost::unique_future<client_result> socks_result{};
310 boost::promise<client_result> socks_promise{};
311 socks_result = socks_promise.get_future();
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();
339 MERROR(
"Failed to make socks connection to " << remote.
str() <<
" (via " <<
proxy <<
"): " << result.first.message());
341 catch (boost::broken_promise
const&)
static bool connect_and_send(std::shared_ptr< client > self, const stream_type::endpoint &proxy_address)
uint16_t const P2P_DEFAULT_PORT
uint16_t const P2P_DEFAULT_PORT
zone zone_from_string(boost::string_ref value) noexcept
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
#define P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT
static i2p_address unknown() noexcept
std::unique_ptr< void, close > socket
Unique ZMQ socket handle, calls zmq_close on destruction.
const command_line::arg_descriptor< bool, false > arg_stagenet_on
static tor_address unknown() noexcept
uint16_t const P2P_DEFAULT_PORT
std::shared_ptr< client > make_connect_client(client::stream_type::socket &&proxy, socks::version ver, Handler handler)
std::error_code error() const noexcept
#define P2P_DEFAULT_LIMIT_RATE_DOWN
address_type get_type_id() const
const command_line::arg_descriptor< bool, false > arg_testnet_on
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
const char * zone_to_string(zone value) noexcept
cryptonote::account_public_address get_address(const var_addr_t &inp)
static constexpr epee::net_utils::address_type get_type_id() noexcept
boost::endian::big_uint32_t ip
boost::endian::big_uint16_t port
const T & move(const T &t)
const GenericPointer< typename T::ValueType > T2 value
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
std::string to_string(t_connection_type type)
static constexpr epee::net_utils::address_type get_type_id() noexcept
#define P2P_DEFAULT_LIMIT_RATE_UP
error
Tracks LMDB error codes.