A class that represents a TCP/IP connection to the wesnothd server. More...
#include <wesnothd_connection.hpp>
Public Types | |
using | error = wesnothd_connection_error |
Public Member Functions | |
wesnothd_connection (const wesnothd_connection &)=delete | |
wesnothd_connection & | operator= (const wesnothd_connection &)=delete |
~wesnothd_connection () | |
wesnothd_connection (const std::string &host, const std::string &service) | |
Constructor. More... | |
void | send_data (const configr_of &request) |
Queues the given data to be sent to the server. More... | |
bool | receive_data (config &result) |
Receives the next pending data pack from the server, if available. More... | |
bool | wait_and_receive_data (config &data) |
Unlike receive_data, waits until data is available instead of returning immediately. More... | |
void | wait_for_handshake () |
Waits until the server handshake is complete. More... | |
bool | using_tls () const |
True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens. More... | |
void | cancel () |
void | stop () |
std::size_t | bytes_to_write () const |
std::size_t | bytes_written () const |
std::size_t | bytes_to_read () const |
std::size_t | bytes_read () const |
bool | has_data_received () const |
bool | is_sending_data () const |
Private Types | |
typedef boost::asio::ip::tcp::resolver | resolver |
typedef std::unique_ptr< boost::asio::ip::tcp::socket > | raw_socket |
typedef std::unique_ptr< boost::asio::ssl::stream< raw_socket::element_type > > | tls_socket |
typedef utils::variant< raw_socket, tls_socket > | any_socket |
using | results_type = resolver::results_type |
using | endpoint = const boost::asio::ip::tcp::endpoint & |
template<typename T > | |
using | data_queue = std::queue< T, std::list< T > > |
Private Member Functions | |
void | handle_resolve (const boost::system::error_code &ec, results_type results) |
void | handle_connect (const boost::system::error_code &ec, endpoint endpoint) |
void | handshake () |
void | handle_handshake (const boost::system::error_code &ec) |
void | fallback_to_unencrypted () |
std::size_t | is_write_complete (const boost::system::error_code &error, std::size_t bytes_transferred) |
void | handle_write (const boost::system::error_code &ec, std::size_t bytes_transferred) |
std::size_t | is_read_complete (const boost::system::error_code &error, std::size_t bytes_transferred) |
void | handle_read (const boost::system::error_code &ec, std::size_t bytes_transferred) |
void | send () |
void | recv () |
void | set_keepalive (int seconds) |
Private Attributes | |
std::thread | worker_thread_ |
boost::asio::io_context | io_context_ |
resolver | resolver_ |
boost::asio::ssl::context | tls_context_ |
std::string | host_ |
std::string | service_ |
bool | use_tls_ |
any_socket | socket_ |
boost::system::error_code | last_error_ |
std::mutex | last_error_mutex_ |
std::promise< void > | handshake_finished_ |
boost::asio::streambuf | read_buf_ |
uint32_t | handshake_response_ |
data_queue< std::unique_ptr< boost::asio::streambuf > > | send_queue_ |
data_queue< config > | recv_queue_ |
std::mutex | recv_queue_mutex_ |
std::condition_variable | recv_queue_lock_ |
uint32_t | payload_size_ |
std::size_t | bytes_to_write_ |
std::size_t | bytes_written_ |
std::size_t | bytes_to_read_ |
std::size_t | bytes_read_ |
A class that represents a TCP/IP connection to the wesnothd server.
Definition at line 51 of file wesnothd_connection.hpp.
|
private |
Definition at line 149 of file wesnothd_connection.hpp.
|
private |
Definition at line 186 of file wesnothd_connection.hpp.
|
private |
Definition at line 162 of file wesnothd_connection.hpp.
Definition at line 54 of file wesnothd_connection.hpp.
|
private |
Definition at line 147 of file wesnothd_connection.hpp.
|
private |
Definition at line 140 of file wesnothd_connection.hpp.
|
private |
Definition at line 161 of file wesnothd_connection.hpp.
|
private |
Definition at line 148 of file wesnothd_connection.hpp.
|
delete |
wesnothd_connection::~wesnothd_connection | ( | ) |
Definition at line 120 of file wesnothd_connection.cpp.
References MPTEST_LOG, socket_, stop(), worker_thread_, and write().
wesnothd_connection::wesnothd_connection | ( | const std::string & | host, |
const std::string & | service | ||
) |
Constructor.
host | Name of the host to connect to |
service | Service identifier such as "80" or "http" |
Definition at line 64 of file wesnothd_connection.cpp.
References DBG_NW, utils::get_unknown_exception_type(), handle_resolve(), handshake_finished_, io_context_, LOG_NW, MPTEST_LOG, resolver_, use_tls_, and worker_thread_.
|
inline |
Definition at line 120 of file wesnothd_connection.hpp.
References bytes_read_.
|
inline |
Definition at line 115 of file wesnothd_connection.hpp.
References bytes_to_read_.
|
inline |
Definition at line 105 of file wesnothd_connection.hpp.
References bytes_to_write_.
|
inline |
Definition at line 110 of file wesnothd_connection.hpp.
References bytes_written_.
void wesnothd_connection::cancel | ( | ) |
Definition at line 343 of file wesnothd_connection.cpp.
References MPTEST_LOG.
|
private |
Definition at line 265 of file wesnothd_connection.cpp.
References handle_connect(), socket_, and use_tls_.
Referenced by handle_handshake().
|
private |
Definition at line 151 of file wesnothd_connection.cpp.
References ERR_NW, handshake(), LOG_NW, MPTEST_LOG, and use_tls_.
Referenced by fallback_to_unencrypted(), and handle_resolve().
|
private |
Definition at line 206 of file wesnothd_connection.cpp.
References fallback_to_unencrypted(), handshake_finished_, handshake_response_, host_, network_asio::load_tls_root_certs(), LOG_NW, MPTEST_LOG, recv(), s, socket_, tls_context_, use_tls_, and verbose_verify().
Referenced by handshake().
|
private |
Definition at line 461 of file wesnothd_connection.cpp.
References bytes_to_read_, data, DBG_NW, io_context_, last_error_, last_error_mutex_, LOG_NW, MPTEST_LOG, read_buf_, read_gz(), recv(), recv_queue_, recv_queue_lock_, and recv_queue_mutex_.
Referenced by recv().
|
private |
Definition at line 138 of file wesnothd_connection.cpp.
References handle_connect(), LOG_NW, MPTEST_LOG, and socket_.
Referenced by wesnothd_connection().
|
private |
Definition at line 397 of file wesnothd_connection.cpp.
References DBG_NW, io_context_, last_error_, last_error_mutex_, LOG_NW, MPTEST_LOG, send(), and send_queue_.
Referenced by send().
|
private |
Definition at line 168 of file wesnothd_connection.cpp.
References DBG_NW, prefs::get(), handle_handshake(), handshake_response_, prefs::keepalive_timeout(), MPTEST_LOG, set_keepalive(), socket_, and use_tls_.
Referenced by handle_connect().
|
inline |
Definition at line 125 of file wesnothd_connection.hpp.
References recv_queue_.
|
private |
Definition at line 422 of file wesnothd_connection.cpp.
References bytes_read_, bytes_to_read_, io_context_, last_error_, last_error_mutex_, LOG_NW, MPTEST_LOG, and read_buf_.
Referenced by recv().
|
inline |
Definition at line 130 of file wesnothd_connection.hpp.
References send_queue_.
|
private |
Definition at line 377 of file wesnothd_connection.cpp.
References bytes_to_write_, bytes_written_, io_context_, last_error_, last_error_mutex_, LOG_NW, and MPTEST_LOG.
Referenced by send().
|
delete |
bool wesnothd_connection::receive_data | ( | config & | result | ) |
Receives the next pending data pack from the server, if available.
result | The object to which the received data will be written. |
Definition at line 529 of file wesnothd_connection.cpp.
References _(), last_error_, last_error_mutex_, MPTEST_LOG, recv_queue_, recv_queue_mutex_, and config::swap().
Referenced by gui2::dialogs::mp_lobby::network_handler(), gui2::dialogs::mp_join_game::network_handler(), gui2::dialogs::mp_staging::network_handler(), playmp_controller::receive_from_wesnothd(), and wait_and_receive_data().
|
private |
Definition at line 517 of file wesnothd_connection.cpp.
References handle_read(), is_read_complete(), MPTEST_LOG, read_buf_, and socket_.
Referenced by handle_handshake(), and handle_read().
|
private |
Definition at line 494 of file wesnothd_connection.cpp.
References bytes_to_write_, bytes_written_, handle_write(), is_write_complete(), MPTEST_LOG, payload_size_, send_queue_, and socket_.
Referenced by handle_write().
void wesnothd_connection::send_data | ( | const configr_of & | request | ) |
Queues the given data to be sent to the server.
request | The data to send |
Definition at line 322 of file wesnothd_connection.cpp.
References DBG_NW, io_context_, MPTEST_LOG, send_queue_, and write_gz().
Referenced by playmp_controller::send_to_wesnothd().
|
private |
Definition at line 572 of file wesnothd_connection.cpp.
References socket_.
Referenced by handshake().
void wesnothd_connection::stop | ( | ) |
Definition at line 369 of file wesnothd_connection.cpp.
References io_context_, and MPTEST_LOG.
Referenced by ~wesnothd_connection().
|
inline |
True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens.
Definition at line 96 of file wesnothd_connection.hpp.
References socket_.
bool wesnothd_connection::wait_and_receive_data | ( | config & | data | ) |
Unlike receive_data, waits until data is available instead of returning immediately.
data | Config object passed to receive_data |
Definition at line 558 of file wesnothd_connection.cpp.
References data, receive_data(), recv_queue_lock_, recv_queue_mutex_, and gui2::dialogs::loading_screen::spin().
Referenced by gui2::dialogs::mp_join_game::fetch_game_config().
void wesnothd_connection::wait_for_handshake | ( | ) |
Waits until the server handshake is complete.
Definition at line 278 of file wesnothd_connection.cpp.
References e, lg::err(), handshake_finished_, LOG_NW, MPTEST_LOG, s, gui2::dialogs::loading_screen::spin(), and WRN_NW.
|
private |
Definition at line 201 of file wesnothd_connection.hpp.
Referenced by bytes_read(), and is_read_complete().
|
private |
Definition at line 200 of file wesnothd_connection.hpp.
Referenced by bytes_to_read(), handle_read(), and is_read_complete().
|
private |
Definition at line 198 of file wesnothd_connection.hpp.
Referenced by bytes_to_write(), is_write_complete(), and send().
|
private |
Definition at line 199 of file wesnothd_connection.hpp.
Referenced by bytes_written(), is_write_complete(), and send().
|
private |
Definition at line 157 of file wesnothd_connection.hpp.
Referenced by handle_handshake(), wait_for_handshake(), and wesnothd_connection().
|
private |
Definition at line 170 of file wesnothd_connection.hpp.
Referenced by handle_handshake(), and handshake().
|
private |
Definition at line 145 of file wesnothd_connection.hpp.
Referenced by handle_handshake().
|
private |
Definition at line 138 of file wesnothd_connection.hpp.
Referenced by handle_read(), handle_write(), is_read_complete(), is_write_complete(), send_data(), stop(), and wesnothd_connection().
|
private |
Definition at line 153 of file wesnothd_connection.hpp.
Referenced by handle_read(), handle_write(), is_read_complete(), is_write_complete(), and receive_data().
|
private |
Definition at line 155 of file wesnothd_connection.hpp.
Referenced by handle_read(), handle_write(), is_read_complete(), is_write_complete(), and receive_data().
|
private |
Definition at line 195 of file wesnothd_connection.hpp.
Referenced by send().
|
private |
Definition at line 159 of file wesnothd_connection.hpp.
Referenced by handle_read(), is_read_complete(), and recv().
|
private |
Definition at line 189 of file wesnothd_connection.hpp.
Referenced by handle_read(), has_data_received(), and receive_data().
|
private |
Definition at line 193 of file wesnothd_connection.hpp.
Referenced by handle_read(), and wait_and_receive_data().
|
private |
Definition at line 191 of file wesnothd_connection.hpp.
Referenced by handle_read(), receive_data(), and wait_and_receive_data().
|
private |
Definition at line 141 of file wesnothd_connection.hpp.
Referenced by wesnothd_connection().
|
private |
Definition at line 188 of file wesnothd_connection.hpp.
Referenced by handle_write(), is_sending_data(), send(), and send_data().
|
private |
Definition at line 146 of file wesnothd_connection.hpp.
|
private |
Definition at line 151 of file wesnothd_connection.hpp.
Referenced by fallback_to_unencrypted(), handle_handshake(), handle_resolve(), handshake(), recv(), send(), set_keepalive(), using_tls(), and ~wesnothd_connection().
|
private |
Definition at line 143 of file wesnothd_connection.hpp.
Referenced by handle_handshake().
|
private |
Definition at line 150 of file wesnothd_connection.hpp.
Referenced by fallback_to_unencrypted(), handle_connect(), handle_handshake(), handshake(), and wesnothd_connection().
|
private |
Definition at line 136 of file wesnothd_connection.hpp.
Referenced by wesnothd_connection(), and ~wesnothd_connection().