Electroneum
Loading...
Searching...
No Matches
net::socks::client Class Referenceabstract

Client support for socks connect and resolve commands. More...

#include <socks.h>

Inheritance diagram for net::socks::client:

Classes

struct  async_close
struct  completed
struct  read
struct  write

Public Types

using stream_type = boost::asio::ip::tcp

Public Member Functions

 client (stream_type::socket &&proxy, socks::version ver)
 client (const client &)=delete
virtual ~client ()
clientoperator= (const client &)=delete
stream_type::socket take_socket ()
socks::version socks_version () const noexcept
epee::span< const std::uint8_t > buffer () const noexcept
void clear_command () noexcept
bool set_connect_command (const epee::net_utils::ipv4_network_address &address)
 Try to set address as remote connection request.
bool set_connect_command (boost::string_ref domain, std::uint16_t port)
 Try to set domain + port as remote connection request.
bool set_connect_command (const net::tor_address &address)
 Try to set address as remote Tor hidden service connection request.
bool set_connect_command (const net::i2p_address &address)
 Try to set address as remote i2p hidden service connection request.
bool set_resolve_command (boost::string_ref domain)
 Try to set domain as remote DNS A record lookup request.

Static Public Member Functions

static bool connect_and_send (std::shared_ptr< client > self, const stream_type::endpoint &proxy_address)
static bool send (std::shared_ptr< client > self)

Detailed Description

Client support for socks connect and resolve commands.

Definition at line 93 of file socks.h.

Member Typedef Documentation

◆ stream_type

using net::socks::client::stream_type = boost::asio::ip::tcp

Definition at line 115 of file socks.h.

Constructor & Destructor Documentation

◆ client() [1/2]

net::socks::client::client ( stream_type::socket && proxy,
socks::version ver )
explicit
Parameters
proxyownership is passed into this. Does not have to be in connected state.
versocks version for the connection.

Definition at line 223 of file socks.cpp.

224 : proxy_(std::move(proxy)), strand_(GET_IO_SERVICE(proxy_)), buffer_size_(0), buffer_(), ver_(ver)
225 {}
#define GET_IO_SERVICE(s)
Here is the caller graph for this function:

◆ client() [2/2]

net::socks::client::client ( const client & )
delete
Here is the call graph for this function:

◆ ~client()

net::socks::client::~client ( )
virtual

Definition at line 227 of file socks.cpp.

227{}

Member Function Documentation

◆ buffer()

epee::span< const std::uint8_t > net::socks::client::buffer ( ) const
inlinenoexcept
Returns
Contents of internal buffer.

Definition at line 143 of file socks.h.

144 {
145 return {buffer_, buffer_size_};
146 }
Here is the caller graph for this function:

◆ clear_command()

void net::socks::client::clear_command ( )
inlinenoexcept
Postcondition
buffer.empty().

Definition at line 149 of file socks.h.

149{ buffer_size_ = 0; }

◆ connect_and_send()

bool net::socks::client::connect_and_send ( std::shared_ptr< client > self,
const stream_type::endpoint & proxy_address )
static

Asynchronously connect to proxy_address then issue command in buffer(). The done(...) method will be invoked upon completion with self and potential errors.

Note
Must use one of the self->set_*_command calls before using this function.
Only async_close can be invoked on self until the done callback is invoked.
Parameters
selfownership of object is given to function.
proxy_addressof the socks server.
Returns
False if self->buffer().empty() (no command set).

Definition at line 294 of file socks.cpp.

295 {
296 if (self && !self->buffer().empty())
297 {
298 client& alias = *self;
299 alias.proxy_.async_connect(proxy_address, alias.strand_.wrap(write{std::move(self)}));
300 return true;
301 }
302 return false;
303 }
client(stream_type::socket &&proxy, socks::version ver)
Definition socks.cpp:223
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

client & net::socks::client::operator= ( const client & )
delete
Here is the call graph for this function:

◆ send()

bool net::socks::client::send ( std::shared_ptr< client > self)
static

Assume existing connection to proxy server; asynchronously issue command in buffer(). The done(...) method will be invoked upon completion with self and potential errors.

Note
Must use one of the self->set_*_command calls before using the function.
Only async_close can be invoked on self until the done callback is invoked.
Parameters
selfownership of object is given to function.
Returns
False if self->buffer().empty() (no command set).

Definition at line 305 of file socks.cpp.

306 {
307 if (self && !self->buffer().empty())
308 {
309 client& alias = *self;
310 boost::asio::async_write(alias.proxy_, write::get_buffer(alias), alias.strand_.wrap(read{std::move(self)}));
311 return true;
312 }
313 return false;
314 }
static boost::asio::const_buffers_1 get_buffer(client const &self) noexcept
Definition socks.cpp:205
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_connect_command() [1/4]

bool net::socks::client::set_connect_command ( boost::string_ref domain,
std::uint16_t port )

Try to set domain + port as remote connection request.

Definition at line 253 of file socks.cpp.

254 {
255 switch (socks_version())
256 {
257 case version::v4a:
258 case version::v4a_tor:
259 break;
260
261 default:
262 return false;
263 }
264
265 const std::size_t buf_used = write_domain_header(buffer_, v4_connect_command, port, domain);
266 buffer_size_ = buf_used;
267 return buf_used != 0;
268 }
socks::version socks_version() const noexcept
Definition socks.h:140
@ v4a_tor
Extensions defined in Tor codebase.
Definition socks.h:61
Here is the call graph for this function:

◆ set_connect_command() [2/4]

bool net::socks::client::set_connect_command ( const epee::net_utils::ipv4_network_address & address)

Try to set address as remote connection request.

Definition at line 229 of file socks.cpp.

230 {
231 switch (socks_version())
232 {
233 case version::v4:
234 case version::v4a:
235 case version::v4a_tor:
236 break;
237 default:
238 return false;
239 }
240
241 static_assert(sizeof(v4_header) < sizeof(buffer_), "buffer size too small for request");
242 static_assert(0 < sizeof(buffer_), "buffer size too small for null termination");
243
244 // version 4
245 const v4_header temp{4, v4_connect_command, address.port(), boost::endian::big_to_native(address.ip())};
246 std::memcpy(std::addressof(buffer_), std::addressof(temp), sizeof(temp));
247 buffer_[sizeof(temp)] = 0;
248 buffer_size_ = sizeof(temp) + 1;
249
250 return true;
251 }
const char * address
Definition multisig.cpp:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_connect_command() [3/4]

bool net::socks::client::set_connect_command ( const net::i2p_address & address)

Try to set address as remote i2p hidden service connection request.

Definition at line 277 of file socks.cpp.

278 {
279 if (!address.is_unknown())
280 return set_connect_command(address.host_str(), address.port());
281 return false;
282 }
bool set_connect_command(const epee::net_utils::ipv4_network_address &address)
Try to set address as remote connection request.
Definition socks.cpp:229
Here is the call graph for this function:

◆ set_connect_command() [4/4]

bool net::socks::client::set_connect_command ( const net::tor_address & address)

Try to set address as remote Tor hidden service connection request.

Definition at line 270 of file socks.cpp.

271 {
272 if (!address.is_unknown())
273 return set_connect_command(address.host_str(), address.port());
274 return false;
275 }
Here is the call graph for this function:

◆ set_resolve_command()

bool net::socks::client::set_resolve_command ( boost::string_ref domain)

Try to set domain as remote DNS A record lookup request.

Definition at line 284 of file socks.cpp.

285 {
287 return false;
288
289 const std::size_t buf_used = write_domain_header(buffer_, v4tor_resolve_command, 0, domain);
290 buffer_size_ = buf_used;
291 return buf_used != 0;
292 }
Here is the call graph for this function:

◆ socks_version()

socks::version net::socks::client::socks_version ( ) const
inlinenoexcept
Returns
Socks version.

Definition at line 140 of file socks.h.

140{ return ver_; }
Here is the caller graph for this function:

◆ take_socket()

stream_type::socket net::socks::client::take_socket ( )
inline
Returns
Ownership of socks client socket object.

Definition at line 134 of file socks.h.

135 {
136 return stream_type::socket{std::move(proxy_)};
137 }

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