Kagome
Polkadot Runtime Engine in C++17
kagome::telemetry::TelemetryConnectionImpl Class Reference

#include <connection_impl.hpp>

Inheritance diagram for kagome::telemetry::TelemetryConnectionImpl:
Collaboration diagram for kagome::telemetry::TelemetryConnectionImpl:

Public Member Functions

 TelemetryConnectionImpl (std::shared_ptr< boost::asio::io_context > io_context, const TelemetryEndpoint &endpoint, OnConnectedCallback callback, std::shared_ptr< MessagePool > message_pool, std::shared_ptr< libp2p::basic::Scheduler > scheduler)
 
 TelemetryConnectionImpl (const TelemetryConnectionImpl &)=delete
 
 TelemetryConnectionImpl (TelemetryConnectionImpl &&)=delete
 
void connect () override
 Initiate connection process. More...
 
const TelemetryEndpointendpoint () const override
 To remind what was the endpoint ;) More...
 
void send (const std::string &data) override
 
void send (MessageHandle message_handle) override
 
bool isConnected () const override
 Reports connection status. More...
 
void shutdown () override
 Request graceful connection shutdown. More...
 
- Public Member Functions inherited from kagome::telemetry::TelemetryConnection
virtual ~TelemetryConnection ()=default
 

Private Types

using TcpStream = boost::beast::tcp_stream
 
using SslStream = boost::beast::ssl_stream< TcpStream >
 
template<typename T >
using WsStream = boost::beast::websocket::stream< T >
 
using WsTcpStream = WsStream< TcpStream >
 
using WsSslStream = WsStream< SslStream >
 
using WsTcpStreamPtr = std::unique_ptr< WsTcpStream >
 
using WsSslStreamPtr = std::unique_ptr< WsSslStream >
 

Private Member Functions

boost::beast::lowest_layer_type< SslStream > & stream_lowest_layer ()
 
template<typename WsStreamT >
void write (WsStreamT &ws, MessageHandle message_handle)
 
void onResolve (boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results)
 
void onConnect (boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type endpoint)
 
template<typename WsStreamT >
void setOptionsAndRunWsHandshake (WsStreamT &ws)
 
void onSslHandshake (boost::beast::error_code ec)
 
void onHandshake (boost::beast::error_code ec)
 
void releaseQueue ()
 
void close ()
 
void reconnect ()
 

Private Attributes

std::shared_ptr< boost::asio::io_context > io_context_
 
const TelemetryEndpoint endpoint_
 
OnConnectedCallback callback_
 
std::shared_ptr< MessagePoolmessage_pool_
 
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
 
bool is_connected_ = false
 
bool shutdown_requested_ = false
 
log::Logger log_
 
std::chrono::seconds reconnect_timeout_ = kInitialReconnectTimeout
 
uint16_t port_ = 80
 
bool secure_ = false
 
std::string path_
 
std::string ws_handshake_hostname_
 
boost::asio::ssl::context ssl_ctx_
 
boost::asio::ip::tcp::resolver resolver_
 
boost::variant< WsTcpStreamPtr, WsSslStreamPtrws_
 
volatile bool busy_ = false
 
boost::circular_buffer< MessageHandlequeue_
 

Static Private Attributes

static std::size_t instance_ = 0
 

Additional Inherited Members

- Public Types inherited from kagome::telemetry::TelemetryConnection
using OnConnectedCallback = std::function< void(std::shared_ptr< TelemetryConnection >)>
 

Detailed Description

Telemetry connection class implementation.

Definition at line 43 of file connection_impl.hpp.

Member Typedef Documentation

using kagome::telemetry::TelemetryConnectionImpl::SslStream = boost::beast::ssl_stream<TcpStream>
private

Definition at line 90 of file connection_impl.hpp.

using kagome::telemetry::TelemetryConnectionImpl::TcpStream = boost::beast::tcp_stream
private

Definition at line 89 of file connection_impl.hpp.

Definition at line 96 of file connection_impl.hpp.

template<typename T >
using kagome::telemetry::TelemetryConnectionImpl::WsStream = boost::beast::websocket::stream<T>
private

Definition at line 92 of file connection_impl.hpp.

Definition at line 95 of file connection_impl.hpp.

Constructor & Destructor Documentation

kagome::telemetry::TelemetryConnectionImpl::TelemetryConnectionImpl ( std::shared_ptr< boost::asio::io_context >  io_context,
const TelemetryEndpoint endpoint,
OnConnectedCallback  callback,
std::shared_ptr< MessagePool message_pool,
std::shared_ptr< libp2p::basic::Scheduler >  scheduler 
)

Initializes the connection instance

Parameters
io_context- io_context to serve the network events
endpoint- telemetry endpoint to connect to
callback- callback to notify when connection gets established
message_pool- the pool to read messages passed by handle
scheduler- scheduler for reconnecting in case of line failure

Definition at line 14 of file connection_impl.cpp.

kagome::telemetry::TelemetryConnectionImpl::TelemetryConnectionImpl ( const TelemetryConnectionImpl )
delete
kagome::telemetry::TelemetryConnectionImpl::TelemetryConnectionImpl ( TelemetryConnectionImpl &&  )
delete

Member Function Documentation

void kagome::telemetry::TelemetryConnectionImpl::close ( )
private

Definition at line 290 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::connect ( )
overridevirtual

Initiate connection process.

Implements kagome::telemetry::TelemetryConnection.

Definition at line 36 of file connection_impl.cpp.

const TelemetryEndpoint & kagome::telemetry::TelemetryConnectionImpl::endpoint ( ) const
overridevirtual

To remind what was the endpoint ;)

Implements kagome::telemetry::TelemetryConnection.

Definition at line 101 of file connection_impl.cpp.

bool kagome::telemetry::TelemetryConnectionImpl::isConnected ( ) const
overridevirtual

Reports connection status.

Implements kagome::telemetry::TelemetryConnection.

Definition at line 137 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::onConnect ( boost::beast::error_code  ec,
boost::asio::ip::tcp::resolver::results_type::endpoint_type  endpoint 
)
private

Definition at line 202 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::onHandshake ( boost::beast::error_code  ec)
private

Definition at line 267 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::onResolve ( boost::beast::error_code  ec,
boost::asio::ip::tcp::resolver::results_type  results 
)
private

Definition at line 186 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::onSslHandshake ( boost::beast::error_code  ec)
private

Definition at line 257 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::reconnect ( )
private

Definition at line 301 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::releaseQueue ( )
private

Definition at line 283 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::send ( const std::string &  data)
overridevirtual

Send the line over the connection

Parameters
data- data to send, can be disposed immediately after returning

Implements kagome::telemetry::TelemetryConnection.

Definition at line 105 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::send ( MessageHandle  message_handle)
overridevirtual

Send the record from the message pool

Parameters
message_handle- handle to the record to send

Implements kagome::telemetry::TelemetryConnection.

Definition at line 116 of file connection_impl.cpp.

template<typename WsStreamT >
void kagome::telemetry::TelemetryConnectionImpl::setOptionsAndRunWsHandshake ( WsStreamT &  ws)
private

Definition at line 237 of file connection_impl.cpp.

void kagome::telemetry::TelemetryConnectionImpl::shutdown ( )
overridevirtual

Request graceful connection shutdown.

Implements kagome::telemetry::TelemetryConnection.

Definition at line 141 of file connection_impl.cpp.

boost::beast::lowest_layer_type< TelemetryConnectionImpl::SslStream > & kagome::telemetry::TelemetryConnectionImpl::stream_lowest_layer ( )
private

Definition at line 149 of file connection_impl.cpp.

template<typename WsStreamT >
void kagome::telemetry::TelemetryConnectionImpl::write ( WsStreamT &  ws,
MessageHandle  message_handle 
)
private

Definition at line 157 of file connection_impl.cpp.

Member Data Documentation

volatile bool kagome::telemetry::TelemetryConnectionImpl::busy_ = false
private

Definition at line 143 of file connection_impl.hpp.

OnConnectedCallback kagome::telemetry::TelemetryConnectionImpl::callback_
private

Definition at line 125 of file connection_impl.hpp.

const TelemetryEndpoint kagome::telemetry::TelemetryConnectionImpl::endpoint_
private

Definition at line 124 of file connection_impl.hpp.

std::size_t kagome::telemetry::TelemetryConnectionImpl::instance_ = 0
staticprivate

Definition at line 142 of file connection_impl.hpp.

std::shared_ptr<boost::asio::io_context> kagome::telemetry::TelemetryConnectionImpl::io_context_
private

Definition at line 123 of file connection_impl.hpp.

bool kagome::telemetry::TelemetryConnectionImpl::is_connected_ = false
private

Definition at line 128 of file connection_impl.hpp.

log::Logger kagome::telemetry::TelemetryConnectionImpl::log_
private

Definition at line 130 of file connection_impl.hpp.

std::shared_ptr<MessagePool> kagome::telemetry::TelemetryConnectionImpl::message_pool_
private

Definition at line 126 of file connection_impl.hpp.

std::string kagome::telemetry::TelemetryConnectionImpl::path_
private

Definition at line 135 of file connection_impl.hpp.

uint16_t kagome::telemetry::TelemetryConnectionImpl::port_ = 80
private

Definition at line 133 of file connection_impl.hpp.

boost::circular_buffer<MessageHandle> kagome::telemetry::TelemetryConnectionImpl::queue_
private

Definition at line 144 of file connection_impl.hpp.

std::chrono::seconds kagome::telemetry::TelemetryConnectionImpl::reconnect_timeout_ = kInitialReconnectTimeout
private

Definition at line 132 of file connection_impl.hpp.

boost::asio::ip::tcp::resolver kagome::telemetry::TelemetryConnectionImpl::resolver_
private

Definition at line 139 of file connection_impl.hpp.

std::shared_ptr<libp2p::basic::Scheduler> kagome::telemetry::TelemetryConnectionImpl::scheduler_
private

Definition at line 127 of file connection_impl.hpp.

bool kagome::telemetry::TelemetryConnectionImpl::secure_ = false
private

Definition at line 134 of file connection_impl.hpp.

bool kagome::telemetry::TelemetryConnectionImpl::shutdown_requested_ = false
private

Definition at line 129 of file connection_impl.hpp.

boost::asio::ssl::context kagome::telemetry::TelemetryConnectionImpl::ssl_ctx_
private

Definition at line 138 of file connection_impl.hpp.

boost::variant<WsTcpStreamPtr, WsSslStreamPtr> kagome::telemetry::TelemetryConnectionImpl::ws_
private

Definition at line 140 of file connection_impl.hpp.

std::string kagome::telemetry::TelemetryConnectionImpl::ws_handshake_hostname_
private

Definition at line 136 of file connection_impl.hpp.


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