Implements a simple non-blocking SSL stream client. More...
#include "sslclient.h"


Public Member Functions | |
| ssl_client (const std::string &_hostname, const std::string &_port="443", bool plaintext_downgrade=false, bool reuse=false) | |
| Connect to a specified host and port. More... | |
| virtual | ~ssl_client () |
| Destroy the ssl_client object. More... | |
| virtual void | close () |
| Close socket connection. More... | |
| uint64_t | get_bytes_in () |
| Get total bytes received. More... | |
| uint64_t | get_bytes_out () |
| Get the bytes out objectGet total bytes sent. More... | |
| std::string | get_cipher () |
| Get SSL cipher name. More... | |
| virtual bool | handle_buffer (std::string &buffer) |
| Handle input from the input buffer. More... | |
| virtual void | log (dpp::loglevel severity, const std::string &msg) const |
| Log a message. More... | |
| void | read_loop () |
| Nonblocking I/O loop. More... | |
| virtual void | write (const std::string &data) |
| Write to the output buffer. More... | |
Public Attributes | |
| socket_callback_t | custom_readable_fd |
| Attaching an additional file descriptor to this function will send notifications when there is data to read. More... | |
| socket_notification_t | custom_readable_ready |
| This event will be called when you can read from the custom fd. More... | |
| socket_callback_t | custom_writeable_fd |
| Attaching an additional file descriptor to this function will send notifications when you are able to write to the socket. More... | |
| socket_notification_t | custom_writeable_ready |
| This event will be called when you can write to a custom fd. More... | |
| bool | keepalive |
| True if we are keeping the connection alive after it has finished. More... | |
Protected Member Functions | |
| virtual void | connect () |
| Start SSL connection and connect to TCP endpoint. More... | |
| virtual void | one_second_timer () |
| Called every second. More... | |
Protected Attributes | |
| std::string | buffer |
| Input buffer received from socket. More... | |
| uint64_t | bytes_in |
| Bytes in. More... | |
| uint64_t | bytes_out |
| Bytes out. More... | |
| std::string | cipher |
| SSL cipher in use. More... | |
| std::string | hostname |
| Hostname connected to. More... | |
| time_t | last_tick |
| For timers. More... | |
| bool | make_new |
| True if we are establishing a new connection, false if otherwise. More... | |
| bool | nonblocking |
| True if in nonblocking mode. More... | |
| std::string | obuffer |
| Output buffer for sending to socket. More... | |
| bool | plaintext |
| True for a plain text connection. More... | |
| std::string | port |
| Port connected to. More... | |
| dpp::socket | sfd |
| Raw file descriptor of connection. More... | |
| openssl_connection * | ssl |
| Openssl opaque contexts. More... | |
Implements a simple non-blocking SSL stream client.
| dpp::ssl_client::ssl_client | ( | const std::string & | _hostname, |
| const std::string & | _port = "443", |
||
| bool | plaintext_downgrade = false, |
||
| bool | reuse = false |
||
| ) |
Connect to a specified host and port.
Throws std::runtime_error on fatal error.
| _hostname | The hostname to connect to |
| _port | the Port number to connect to |
| plaintext_downgrade | Set to true to connect using plaintext only, without initialising SSL. |
| reuse | Attempt to reuse previous connections for this hostname and port, if available Note that no Discord endpoints will function when downgraded. This option is provided only for connection to non-Discord addresses such as within dpp::cluster::request(). |
| dpp::exception | Failed to initialise connection |
References dpp::close_socket(), connect(), dpp::err_connect_failure, hostname, INVALID_SOCKET, keepalive, dpp::keepalives, make_new, plaintext, port, dpp::set_signal_handler(), sfd, dpp::openssl_connection::ssl, and ssl.

|
virtual |
Destroy the ssl_client object.
|
virtual |
Close socket connection.
Reimplemented in dpp::https_client, and dpp::websocket_client.
References buffer, dpp::close_socket(), dpp::keepalive_cache_t::created, hostname, INVALID_SOCKET, keepalive, dpp::keepalives, obuffer, plaintext, port, dpp::keepalive_cache_t::sfd, sfd, dpp::openssl_connection::ssl, dpp::keepalive_cache_t::ssl, and ssl.
Referenced by dpp::https_client::get_status(), and dpp::websocket_client::send_close_packet().


|
protectedvirtual |
Start SSL connection and connect to TCP endpoint.
| dpp::exception | Failed to initialise connection |
Reimplemented in dpp::https_client, and dpp::websocket_client.
References dpp::dns_cache_entry::addr, dpp::dns_cache_entry::ai_addr, cipher, dpp::close_socket(), dpp::connect_with_timeout(), dpp::err_connect_failure, dpp::err_ssl_connect, dpp::err_ssl_context, dpp::err_ssl_new, dpp::err_ssl_version, dpp::ERROR_STATUS, hostname, make_new, nonblocking, dpp::openssl_context, plaintext, port, dpp::resolve_hostname(), sfd, SOCKET_OP_TIMEOUT, dpp::openssl_connection::ssl, ssl, and dpp::unicode_emoji::tv.
Referenced by ssl_client().


| uint64_t dpp::ssl_client::get_bytes_in | ( | ) |
| uint64_t dpp::ssl_client::get_bytes_out | ( | ) |
| std::string dpp::ssl_client::get_cipher | ( | ) |
|
virtual |
Handle input from the input buffer.
This function will be called until all data in the buffer has been processed and the buffer is empty.
| buffer | the buffer content. Will be modified removing any processed front elements |
Reimplemented in dpp::https_client, and dpp::websocket_client.
Referenced by read_loop().

|
virtual |
Log a message.
| severity | severity of log message |
| msg | Log message to send |
Reimplemented in dpp::discord_voice_client, and dpp::discord_client.
Referenced by read_loop().

|
protectedvirtual |
Called every second.
Reimplemented in dpp::discord_voice_client, dpp::discord_client, dpp::https_client, and dpp::websocket_client.
Referenced by read_loop().

| void dpp::ssl_client::read_loop | ( | ) |
Nonblocking I/O loop.
| std::exception | Any std::exception (or derivative) thrown from read_loop() causes reconnection of the shard |
References buffer, bytes_in, bytes_out, custom_readable_fd, custom_readable_ready, custom_writeable_fd, custom_writeable_ready, DPP_BUFSIZE, dpp::err_invalid_socket, dpp::err_nonblocking_failure, dpp::err_socket_error, handle_buffer(), INVALID_SOCKET, last_tick, dpp::ll_warning, log(), nonblocking, obuffer, one_second_timer(), plaintext, dpp::set_nonblocking(), sfd, dpp::openssl_connection::ssl, and ssl.

|
virtual |
Write to the output buffer.
| data | Data to be written to the buffer |
Reimplemented in dpp::websocket_client.
References dpp::err_ssl_write, dpp::err_write, INVALID_SOCKET, nonblocking, obuffer, plaintext, sfd, dpp::openssl_connection::ssl, and ssl.
|
protected |
Input buffer received from socket.
Referenced by close(), dpp::discord_client::handle_frame(), and read_loop().
|
protected |
Bytes in.
Referenced by get_bytes_in(), and read_loop().
|
protected |
Bytes out.
Referenced by get_bytes_out(), and read_loop().
|
protected |
SSL cipher in use.
Referenced by connect(), and get_cipher().
| socket_callback_t dpp::ssl_client::custom_readable_fd |
Attaching an additional file descriptor to this function will send notifications when there is data to read.
NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread! Returning -1 means that you don't want to be notified.
Referenced by dpp::discord_voice_client::handle_frame(), and read_loop().
| socket_notification_t dpp::ssl_client::custom_readable_ready |
This event will be called when you can read from the custom fd.
Referenced by dpp::discord_voice_client::handle_frame(), and read_loop().
| socket_callback_t dpp::ssl_client::custom_writeable_fd |
Attaching an additional file descriptor to this function will send notifications when you are able to write to the socket.
NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread! You should toggle this to -1 when you do not have anything to write otherwise it'll keep triggering repeatedly (it is level triggered).
Referenced by dpp::discord_voice_client::handle_frame(), and read_loop().
| socket_notification_t dpp::ssl_client::custom_writeable_ready |
This event will be called when you can write to a custom fd.
Referenced by dpp::discord_voice_client::handle_frame(), and read_loop().
|
protected |
Hostname connected to.
Referenced by close(), connect(), and ssl_client().
| bool dpp::ssl_client::keepalive |
True if we are keeping the connection alive after it has finished.
Referenced by close(), and ssl_client().
|
protected |
For timers.
Referenced by read_loop().
|
protected |
True if we are establishing a new connection, false if otherwise.
Referenced by connect(), and ssl_client().
|
protected |
True if in nonblocking mode.
The socket switches to nonblocking mode once ReadLoop is called.
Referenced by connect(), read_loop(), and write().
|
protected |
Output buffer for sending to socket.
Referenced by close(), read_loop(), and write().
|
protected |
True for a plain text connection.
Referenced by close(), connect(), read_loop(), ssl_client(), and write().
|
protected |
Port connected to.
Referenced by close(), connect(), and ssl_client().
|
protected |
Raw file descriptor of connection.
Referenced by close(), connect(), dpp::discord_client::one_second_timer(), read_loop(), ssl_client(), and write().
|
protected |
Openssl opaque contexts.
Referenced by close(), connect(), read_loop(), ssl_client(), and write().