aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
aegis::shards::shard Class Reference

Tracks websocket shards and their connections. More...

#include <shard.hpp>

Public Types

using connection_ptr = websocketpp::client< websocketpp::config::asio_tls_client >::connection_type::ptr
 Type of a pointer to the Websocket++ TLS connection.
 

Public Member Functions

 shard (asio::io_context &_io, websocketpp::client< websocketpp::config::asio_tls_client > &_ws, int32_t id)
 Constructs a shard object for connecting to the websocket gateway and tracking timers.
 
void do_reset (shard_status _status=shard_status::closed) noexcept
 Resets connection, heartbeat, and timer related objects to allow reconnection.
 
int64_t get_sequence () const noexcept
 Get this shard's websocket message sequence counter. More...
 
int32_t get_id () const noexcept
 Gets the id of the shard in the master list. More...
 
bool is_connected () const noexcept
 Check if this shard has an active connection or is a connecting state. More...
 
bool is_online () const noexcept
 Check if this shard is ready to interact with the gateway. More...
 
void send (const std::string &payload, websocketpp::frame::opcode::value op=websocketpp::frame::opcode::text)
 Send a message to this shard's websocket connection asynchronously. More...
 
void send_now (const std::string &payload, websocketpp::frame::opcode::value op=websocketpp::frame::opcode::text)
 Send message over the websocket synchronously.
 
std::string get_transfer_str () const noexcept
 Returns a formatted string of bytes received since library start. More...
 
std::string get_transfer_u_str () const noexcept
 Returns a formatted string of uncompressed bytes received since library start. More...
 
uint64_t get_transfer () const noexcept
 
uint64_t get_transfer_u () const noexcept
 
void connect ()
 Open websocket connection.
 
std::string uptime_str () const noexcept
 Return shard uptime as {days hours minutes seconds}. More...
 
int64_t uptime () const noexcept
 Return shard uptime as {days hours minutes seconds}. More...
 
void set_heartbeat (std::function< void(const asio::error_code &, const std::chrono::milliseconds, shard *)> fnkeepalive)
 
void start_heartbeat (int32_t heartbeat) noexcept
 
void set_sequence (int64_t seq) noexcept
 
void set_id (int32_t shard_id) noexcept
 
connection_ptr get_connection () noexcept
 
const std::vector< std::string > & get_trace () const noexcept
 
void update_presence (const std::string &text, gateway::objects::activity::activity_type type=gateway::objects::activity::Game, gateway::objects::presence::user_status status=gateway::objects::presence::Online)
 Update presence on this shard. More...
 

Public Attributes

struct {
   int64_t   messages
 
   int64_t   presence_changes
 
   int64_t   reconnects
 
counters = { 0,0,0 }
 Contains counters of valued objects and events.
 
asio::steady_timer keepalivetimer
 
asio::steady_timer delayedauth
 
asio::steady_timer write_timer
 
std::queue< std::tuple
< std::string,
websocketpp::frame::opcode::value > > 
write_queue
 
int32_t heartbeattime
 
std::chrono::steady_clock::time_point heartbeat_ack
 
std::chrono::steady_clock::time_point lastheartbeat
 
std::chrono::steady_clock::time_point lastwsevent
 
std::chrono::steady_clock::time_point last_status_time
 
std::chrono::steady_clock::time_point _ready_time
 
std::chrono::steady_clock::time_point last_ws_write
 
std::chrono::steady_clock::time_point connect_time
 
std::chrono::steady_clock::time_point closing_time
 
shard_status connection_state
 
std::string session_id
 
std::function< void(const
asio::error_code &, const
std::chrono::milliseconds,
shard *)> 
keepalivefunc
 

Friends

class shard_mgr
 
class aegis::core
 

Detailed Description

Tracks websocket shards and their connections.

Member Function Documentation

int32_t aegis::shards::shard::get_id ( ) const
noexcept

Gets the id of the shard in the master list.

See also
core::shards
Returns
Shard id
int64_t aegis::shards::shard::get_sequence ( ) const
noexcept

Get this shard's websocket message sequence counter.

Returns
Sequence counter specific to this shard
uint64_t aegis::shards::shard::get_transfer ( ) const
noexcept

Returns bytes transferred pre-inflation used to with post-inflation for bandwidth saving/efficiency comparisons

Returns
uint64_t of the current bytes received since start
std::string aegis::shards::shard::get_transfer_str ( ) const
noexcept

Returns a formatted string of bytes received since library start.

Returns
std::string of the current bytes received since start
uint64_t aegis::shards::shard::get_transfer_u ( ) const
noexcept

Returns bytes transferred post-inflation used to with pre-inflation for bandwidth saving/efficiency comparisons

Returns
uint64_t of the current bytes received since start
std::string aegis::shards::shard::get_transfer_u_str ( ) const
noexcept

Returns a formatted string of uncompressed bytes received since library start.

Uncompressed as in post-inflate. This is the amount of bytes that would have been transferred without compression. To be compared with get_transfer_str() for a compression ratio.

Returns
std::string of the current bytes received since start
bool aegis::shards::shard::is_connected ( ) const
noexcept

Check if this shard has an active connection or is a connecting state.

Returns
bool
bool aegis::shards::shard::is_online ( ) const
noexcept

Check if this shard is ready to interact with the gateway.

Returns
bool
void aegis::shards::shard::send ( const std::string &  payload,
websocketpp::frame::opcode::value  op = websocketpp::frame::opcode::text 
)

Send a message to this shard's websocket connection asynchronously.

Parameters
payloadString of the payload to send
opOpcode of the message (default: text)
void aegis::shards::shard::update_presence ( const std::string &  text,
gateway::objects::activity::activity_type  type = gateway::objects::activity::Game,
gateway::objects::presence::user_status  status = gateway::objects::presence::Online 
)

Update presence on this shard.

See also
aegis::gateway::objects::activity
aegis::gateway::objects::presence
Parameters
textString of presence message
typeaegis::gateway::objects::activity::activity_type enum of the activity type
statusaegis::gateway::objects::presence::user_status enum of the status
int64_t aegis::shards::shard::uptime ( ) const
noexcept

Return shard uptime as {days hours minutes seconds}.

Returns
Time in milliseconds since shard received ready
std::string aegis::shards::shard::uptime_str ( ) const
noexcept

Return shard uptime as {days hours minutes seconds}.

Returns
std::string of hh mm ss formatted time

The documentation for this class was generated from the following files: