#include <net_helper.h>
|
| using | connect_func = boost::unique_future< boost::asio::ip::tcp::socket >(const std::string &, const std::string &, boost::asio::steady_timer &) |
| |
|
| | blocked_mode_client () |
| |
| | ~blocked_mode_client () |
| |
| void | set_ssl (ssl_options_t ssl_options) |
| |
| bool | connect (const std::string &addr, int port, std::chrono::milliseconds timeout) |
| |
| try_connect_result_t | try_connect (const std::string &addr, const std::string &port, std::chrono::milliseconds timeout, epee::net_utils::ssl_support_t ssl_support) |
| |
| bool | connect (const std::string &addr, const std::string &port, std::chrono::milliseconds timeout) |
| |
| void | set_connector (std::function< connect_func > connector) |
| | Change the connection routine (proxy, etc.) More...
|
| |
| bool | disconnect () |
| |
| bool | send (const std::string &buff, std::chrono::milliseconds timeout) |
| |
| bool | send (const void *data, size_t sz) |
| |
| bool | is_connected (bool *ssl=NULL) |
| |
| bool | recv (std::string &buff, std::chrono::milliseconds timeout) |
| |
| bool | recv_n (std::string &buff, int64_t sz, std::chrono::milliseconds timeout) |
| |
| bool | shutdown () |
| |
| boost::asio::io_service & | get_io_service () |
| |
| boost::asio::ip::tcp::socket & | get_socket () |
| |
| uint64_t | get_bytes_sent () const |
| |
| uint64_t | get_bytes_received () const |
| |
|
| bool | write (const void *data, size_t sz, boost::system::error_code &ec) |
| |
| void | async_write (const void *data, size_t sz, boost::system::error_code &ec) |
| |
| void | async_read (char *buff, size_t sz, boost::asio::detail::transfer_at_least_t transfer_at_least, handler_obj &hndlr) |
| |
Definition at line 70 of file net_helper.h.
◆ connect_func
The first/second parameters are host/port respectively. The third parameter is for setting the timeout callback - the timer is already set by the caller, the callee only needs to set the behavior.
Additional asynchronous operations should be queued using the io_service from the timer. The implementation should assume multi-threaded I/O processing.
If the callee cannot start an asynchronous operation, an exception should be thrown to signal an immediate failure.
The return value is a future to a connected socket. Asynchronous failures should use the set_exception method.
Definition at line 131 of file net_helper.h.
◆ blocked_mode_client()
| epee::net_utils::blocked_mode_client::blocked_mode_client |
( |
| ) |
|
|
inline |
Definition at line 102 of file net_helper.h.
104 m_ctx(boost::asio::ssl::context::tlsv12),
boost::asio::ssl::context m_ctx
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
boost::asio::io_service m_io_service
ssl_options_t m_ssl_options
boost::asio::steady_timer m_deadline
std::function< connect_func > m_connector
volatile uint32_t m_shutdowned
std::atomic< uint64_t > m_bytes_received
std::atomic< uint64_t > m_bytes_sent
◆ ~blocked_mode_client()
| epee::net_utils::blocked_mode_client::~blocked_mode_client |
( |
| ) |
|
|
inline |
◆ async_read()
| void epee::net_utils::blocked_mode_client::async_read |
( |
char * |
buff, |
|
|
size_t |
sz, |
|
|
boost::asio::detail::transfer_at_least_t |
transfer_at_least, |
|
|
handler_obj & |
hndlr |
|
) |
| |
|
inlineprotected |
Definition at line 667 of file net_helper.h.
670 boost::asio::async_read(
m_ssl_socket->next_layer(), boost::asio::buffer(buff, sz), transfer_at_least, hndlr);
672 boost::asio::async_read(*
m_ssl_socket, boost::asio::buffer(buff, sz), transfer_at_least, hndlr);
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
ssl_options_t m_ssl_options
◆ async_write()
| void epee::net_utils::blocked_mode_client::async_write |
( |
const void * |
data, |
|
|
size_t |
sz, |
|
|
boost::system::error_code & |
ec |
|
) |
| |
|
inlineprotected |
Definition at line 659 of file net_helper.h.
662 boost::asio::async_write(*
m_ssl_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
664 boost::asio::async_write(
m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
ssl_options_t m_ssl_options
◆ connect() [1/2]
| bool epee::net_utils::blocked_mode_client::connect |
( |
const std::string & |
addr, |
|
|
int |
port, |
|
|
std::chrono::milliseconds |
timeout |
|
) |
| |
|
inline |
Definition at line 151 of file net_helper.h.
bool connect(const std::string &addr, int port, std::chrono::milliseconds timeout)
boost::endian::big_uint16_t port
std::string to_string(t_connection_type type)
◆ connect() [2/2]
| bool epee::net_utils::blocked_mode_client::connect |
( |
const std::string & |
addr, |
|
|
const std::string & |
port, |
|
|
std::chrono::milliseconds |
timeout |
|
) |
| |
|
inline |
Definition at line 207 of file net_helper.h.
221 if (try_connect_result == CONNECT_FAILURE)
225 if (try_connect_result == CONNECT_NO_SSL)
227 MERROR(
"SSL handshake failed on an autodetect connection, reconnecting without SSL");
234 catch(
const boost::system::system_error& er)
236 MDEBUG(
"Some problems at connect, message: " << er.what());
241 MDEBUG(
"Some fatal problems.");
boost::asio::ssl::context m_ctx
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
boost::asio::io_service m_io_service
ssl_options_t m_ssl_options
try_connect_result_t try_connect(const std::string &addr, const std::string &port, std::chrono::milliseconds timeout, epee::net_utils::ssl_support_t ssl_support)
boost::endian::big_uint16_t port
◆ disconnect()
| bool epee::net_utils::blocked_mode_client::disconnect |
( |
| ) |
|
|
inline |
Definition at line 254 of file net_helper.h.
263 m_ssl_socket->next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both);
266 catch(
const boost::system::system_error& )
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
ssl_options_t m_ssl_options
◆ get_bytes_received()
| uint64_t epee::net_utils::blocked_mode_client::get_bytes_received |
( |
| ) |
const |
|
inline |
Definition at line 596 of file net_helper.h.
std::atomic< uint64_t > m_bytes_received
◆ get_bytes_sent()
| uint64_t epee::net_utils::blocked_mode_client::get_bytes_sent |
( |
| ) |
const |
|
inline |
Definition at line 591 of file net_helper.h.
std::atomic< uint64_t > m_bytes_sent
◆ get_io_service()
| boost::asio::io_service& epee::net_utils::blocked_mode_client::get_io_service |
( |
| ) |
|
|
inline |
Definition at line 581 of file net_helper.h.
boost::asio::io_service m_io_service
◆ get_socket()
| boost::asio::ip::tcp::socket& epee::net_utils::blocked_mode_client::get_socket |
( |
| ) |
|
|
inline |
Definition at line 586 of file net_helper.h.
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
◆ is_connected()
| bool epee::net_utils::blocked_mode_client::is_connected |
( |
bool * |
ssl = NULL | ) |
|
|
inline |
Definition at line 392 of file net_helper.h.
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
ssl_options_t m_ssl_options
◆ recv()
| bool epee::net_utils::blocked_mode_client::recv |
( |
std::string & |
buff, |
|
|
std::chrono::milliseconds |
timeout |
|
) |
| |
|
inline |
Definition at line 402 of file net_helper.h.
424 boost::system::error_code ec = boost::asio::error::would_block;
425 size_t bytes_transfered = 0;
427 handler_obj hndlr(ec, bytes_transfered);
429 static const size_t max_size = 16384;
430 buff.resize(max_size);
432 async_read(&buff[0], max_size, boost::asio::transfer_at_least(1), hndlr);
435 while (ec == boost::asio::error::would_block && !boost::interprocess::ipcdetail::atomic_read32(&
m_shutdowned))
444 MTRACE(
"READ ENDS: Connection err_code " << ec.value());
445 if(ec == boost::asio::error::eof)
447 MTRACE(
"Connection err_code eof.");
453 MDEBUG(
"Problems at read: " << ec.message());
458 MTRACE(
"READ ENDS: Success. bytes_tr: " << bytes_transfered);
459 m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
466 buff.resize(bytes_transfered);
470 catch(
const boost::system::system_error& er)
472 LOG_ERROR(
"Some problems at read, message: " << er.what());
478 LOG_ERROR(
"Some fatal problems at read.");
boost::asio::io_service m_io_service
boost::asio::steady_timer m_deadline
volatile uint32_t m_shutdowned
void async_read(char *buff, size_t sz, boost::asio::detail::transfer_at_least_t transfer_at_least, handler_obj &hndlr)
std::atomic< uint64_t > m_bytes_received
◆ recv_n()
| bool epee::net_utils::blocked_mode_client::recv_n |
( |
std::string & |
buff, |
|
|
int64_t |
sz, |
|
|
std::chrono::milliseconds |
timeout |
|
) |
| |
|
inline |
Definition at line 488 of file net_helper.h.
510 buff.resize(static_cast<size_t>(sz));
511 boost::system::error_code ec = boost::asio::error::would_block;
512 size_t bytes_transfered = 0;
515 handler_obj hndlr(ec, bytes_transfered);
516 async_read((
char*)buff.data(), buff.size(), boost::asio::transfer_at_least(buff.size()), hndlr);
519 while (ec == boost::asio::error::would_block && !boost::interprocess::ipcdetail::atomic_read32(&
m_shutdowned))
531 m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
535 if(bytes_transfered != buff.size())
537 LOG_ERROR(
"Transferred mismatch with transfer_at_least value: m_bytes_transferred=" << bytes_transfered <<
" at_least value=" << buff.size());
544 catch(
const boost::system::system_error& er)
546 LOG_ERROR(
"Some problems at read, message: " << er.what());
552 LOG_ERROR(
"Some fatal problems at read.");
boost::asio::io_service m_io_service
boost::asio::steady_timer m_deadline
volatile uint32_t m_shutdowned
void async_read(char *buff, size_t sz, boost::asio::detail::transfer_at_least_t transfer_at_least, handler_obj &hndlr)
std::atomic< uint64_t > m_bytes_received
◆ send() [1/2]
| bool epee::net_utils::blocked_mode_client::send |
( |
const std::string & |
buff, |
|
|
std::chrono::milliseconds |
timeout |
|
) |
| |
|
inline |
Definition at line 281 of file net_helper.h.
293 boost::system::error_code ec = boost::asio::error::would_block;
302 while (ec == boost::asio::error::would_block)
315 m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
320 catch(
const boost::system::system_error& er)
322 LOG_ERROR(
"Some problems at connect, message: " << er.what());
void async_write(const void *data, size_t sz, boost::system::error_code &ec)
boost::asio::io_service m_io_service
boost::asio::steady_timer m_deadline
std::atomic< uint64_t > m_bytes_sent
◆ send() [2/2]
| bool epee::net_utils::blocked_mode_client::send |
( |
const void * |
data, |
|
|
size_t |
sz |
|
) |
| |
|
inline |
Definition at line 335 of file net_helper.h.
361 boost::system::error_code ec;
363 size_t writen =
write(data, sz, ec);
372 m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
377 catch(
const boost::system::system_error& er)
379 LOG_ERROR(
"Some problems at send, message: " << er.what());
boost::asio::steady_timer m_deadline
bool write(const void *data, size_t sz, boost::system::error_code &ec)
std::atomic< uint64_t > m_bytes_sent
◆ set_connector()
| void epee::net_utils::blocked_mode_client::set_connector |
( |
std::function< connect_func > |
connector | ) |
|
|
inline |
Change the connection routine (proxy, etc.)
Definition at line 248 of file net_helper.h.
const T & move(const T &t)
std::function< connect_func > m_connector
◆ set_ssl()
| void epee::net_utils::blocked_mode_client::set_ssl |
( |
ssl_options_t |
ssl_options | ) |
|
|
inline |
Definition at line 141 of file net_helper.h.
144 m_ctx = ssl_options.create_context();
boost::asio::ssl::context m_ctx
ssl_options_t m_ssl_options
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
const T & move(const T &t)
◆ shutdown()
| bool epee::net_utils::blocked_mode_client::shutdown |
( |
| ) |
|
|
inline |
Definition at line 561 of file net_helper.h.
564 boost::system::error_code ec;
569 MDEBUG(
"Problems at cancel: " << ec.message());
570 m_ssl_socket->next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
572 MDEBUG(
"Problems at shutdown: " << ec.message());
575 MDEBUG(
"Problems at close: " << ec.message());
576 boost::interprocess::ipcdetail::atomic_write32(&
m_shutdowned, 1);
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
ssl_options_t m_ssl_options
boost::asio::steady_timer m_deadline
volatile uint32_t m_shutdowned
◆ try_connect()
| try_connect_result_t epee::net_utils::blocked_mode_client::try_connect |
( |
const std::string & |
addr, |
|
|
const std::string & |
port, |
|
|
std::chrono::milliseconds |
timeout, |
|
|
epee::net_utils::ssl_support_t |
ssl_support |
|
) |
| |
|
inline |
Definition at line 157 of file net_helper.h.
175 m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
183 boost::system::error_code ignored_ec;
184 m_ssl_socket->next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
187 return CONNECT_NO_SSL;
191 MWARNING(
"Failed to establish SSL connection");
193 return CONNECT_FAILURE;
197 return CONNECT_SUCCESS;
200 MWARNING(
"Some problems at connect, expected open socket");
201 return CONNECT_FAILURE;
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
connection(typename TProtocol::config_type &ref_config)
boost::asio::io_service m_io_service
ssl_options_t m_ssl_options
bool handshake(boost::asio::ssl::stream< boost::asio::ip::tcp::socket > &socket, boost::asio::ssl::stream_base::handshake_type type, const std::string &host={}) const
boost::asio::steady_timer m_deadline
boost::endian::big_uint16_t port
std::function< connect_func > m_connector
◆ write()
| bool epee::net_utils::blocked_mode_client::write |
( |
const void * |
data, |
|
|
size_t |
sz, |
|
|
boost::system::error_code & |
ec |
|
) |
| |
|
inlineprotected |
Definition at line 649 of file net_helper.h.
655 success = boost::asio::write(
m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), ec);
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
ssl_options_t m_ssl_options
expect< void > success() noexcept
◆ m_bytes_received
| std::atomic<uint64_t> epee::net_utils::blocked_mode_client::m_bytes_received |
|
protected |
◆ m_bytes_sent
| std::atomic<uint64_t> epee::net_utils::blocked_mode_client::m_bytes_sent |
|
protected |
◆ m_connected
| bool epee::net_utils::blocked_mode_client::m_connected |
|
protected |
◆ m_connector
| std::function<connect_func> epee::net_utils::blocked_mode_client::m_connector |
|
protected |
◆ m_ctx
| boost::asio::ssl::context epee::net_utils::blocked_mode_client::m_ctx |
|
protected |
◆ m_deadline
| boost::asio::steady_timer epee::net_utils::blocked_mode_client::m_deadline |
|
protected |
◆ m_initialized
| bool epee::net_utils::blocked_mode_client::m_initialized |
|
protected |
◆ m_io_service
| boost::asio::io_service epee::net_utils::blocked_mode_client::m_io_service |
|
protected |
◆ m_shutdowned
| volatile uint32_t epee::net_utils::blocked_mode_client::m_shutdowned |
|
protected |
◆ m_ssl_options
| ssl_options_t epee::net_utils::blocked_mode_client::m_ssl_options |
|
protected |
◆ m_ssl_socket
| std::shared_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> > epee::net_utils::blocked_mode_client::m_ssl_socket |
|
protected |
The documentation for this class was generated from the following file:
- /home/abuild/rpmbuild/BUILD/electroneum-5.0.0.4/contrib/epee/include/net/net_helper.h