Electroneum
Loading...
Searching...
No Matches
net::socks::connector Struct Reference

Primarily for use with epee::net_utils::http_client. More...

#include <socks_connect.h>

Public Member Functions

boost::unique_future< boost::asio::ip::tcp::socket > operator() (const std::string &remote_host, const std::string &remote_port, boost::asio::steady_timer &timeout) const

Public Attributes

boost::asio::ip::tcp::endpoint proxy_address

Detailed Description

Primarily for use with epee::net_utils::http_client.

Definition at line 41 of file socks_connect.h.

Member Function Documentation

◆ operator()()

boost::unique_future< boost::asio::ip::tcp::socket > net::socks::connector::operator() ( const std::string & remote_host,
const std::string & remote_port,
boost::asio::steady_timer & timeout ) const

Creates a new socket, asynchronously connects to proxy_address, and requests a connection to remote_host on remote_port. Sets socket as closed if timeout is reached.

Returns
The socket if successful, and exception in the future with error otherwise.

Definition at line 47 of file socks_connect.cpp.

48 {
49 struct future_socket
50 {
51 boost::promise<boost::asio::ip::tcp::socket> result_;
52
53 void operator()(boost::system::error_code error, boost::asio::ip::tcp::socket&& socket)
54 {
55 if (error)
56 result_.set_exception(boost::system::system_error{error});
57 else
58 result_.set_value(std::move(socket));
59 }
60 };
61
62 boost::unique_future<boost::asio::ip::tcp::socket> out{};
63 {
64 std::uint16_t port = 0;
65 if (!epee::string_tools::get_xtype_from_string(port, remote_port))
66 throw std::system_error{net::error::invalid_port, "Remote port for socks proxy"};
67
68 bool is_set = false;
69 std::uint32_t ip_address = 0;
70 boost::promise<boost::asio::ip::tcp::socket> result{};
71 out = result.get_future();
72 const auto proxy = net::socks::make_connect_client(
73 boost::asio::ip::tcp::socket{GET_IO_SERVICE(timeout)}, net::socks::version::v4a, future_socket{std::move(result)}
74 );
75
76 if (epee::string_tools::get_ip_int32_from_string(ip_address, remote_host))
77 is_set = proxy->set_connect_command(epee::net_utils::ipv4_network_address{ip_address, port});
78 else
79 is_set = proxy->set_connect_command(remote_host, port);
80
82 throw std::system_error{net::error::invalid_host, "Address for socks proxy"};
83
84 timeout.async_wait(net::socks::client::async_close{std::move(proxy)});
85 }
86
87 return out;
88 }
static bool connect_and_send(std::shared_ptr< client > self, const stream_type::endpoint &proxy_address)
Definition socks.cpp:294
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
error
Tracks LMDB error codes.
Definition error.h:45
std::shared_ptr< client > make_connect_client(client::stream_type::socket &&proxy, socks::version ver, Handler handler)
Definition socks.h:226
@ invalid_port
Outside of 0-65535 range.
Definition error.h:43
@ invalid_host
Hostname is not valid.
Definition error.h:41
#define GET_IO_SERVICE(s)
boost::asio::ip::tcp::endpoint proxy_address
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ proxy_address

boost::asio::ip::tcp::endpoint net::socks::connector::proxy_address

Definition at line 43 of file socks_connect.h.


The documentation for this struct was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/net/socks_connect.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/net/socks_connect.cpp