Electroneum
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;
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(
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
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
std::unique_ptr< void, close > socket
Unique ZMQ socket handle, calls zmq_close on destruction.
Definition: zmq.h:101
unsigned short uint16_t
Definition: stdint.h:125
std::shared_ptr< client > make_connect_client(client::stream_type::socket &&proxy, socks::version ver, Handler handler)
Definition: socks.h:226
Hostname is not valid.
unsigned int uint32_t
Definition: stdint.h:126
boost::endian::big_uint16_t port
Definition: socks.cpp:60
#define GET_IO_SERVICE(s)
error
Possible errors with socks communication. Defined in https://www.openssh.com/txt/socks4.protocol.
Definition: socks.h:65
const T & move(const T &t)
Definition: gtest-port.h:1317
Outside of 0-65535 range.
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
Definition: string_tools.h:125
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
boost::asio::ip::tcp::endpoint proxy_address
Definition: socks_connect.h:43
Here is the call 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: