Kagome
Polkadot Runtime Engine in C++17
|
#include <ws_session.hpp>
Classes | |
struct | Configuration |
Public Member Functions | |
~WsSession () override=default | |
WsSession (Context &context, Configuration config, SessionId id) | |
constructor More... | |
Socket & | socket () override |
void | start () override |
starts session More... | |
Session::SessionId | id () const override |
method to get id of the session More... | |
SessionType | type () const override |
method to get type of the session More... | |
void | respond (std::string_view response) override |
sends response wrapped by websocket frame More... | |
void | reject () |
Closes the incoming connection with "try again later" response. More... | |
void | connectOnWsSessionCloseHandler (OnWsSessionCloseHandler &&handler) |
connects on websocket close callback. Used to maintain the maximum number of simultaneous sessions More... | |
Public Member Functions inherited from kagome::api::Session | |
virtual | ~Session ()=default |
void | connectOnRequest (std::function< OnRequestSignature > callback) |
connects on request callback More... | |
void | connectOnCloseHandler (OnCloseHandler &&handler) |
connects on close callback More... | |
void | processRequest (std::string_view request, std::shared_ptr< Session > session) |
process request message More... | |
void | notifyOnClose (SessionId id, SessionType type) |
makes on close notification to listener More... | |
Private Types | |
using | WsError = boost::beast::websocket::error |
using | OnWsSessionCloseHandler = std::function< void()> |
Private Member Functions | |
void | stop () |
stops session More... | |
void | stop (boost::beast::websocket::close_code code) |
stops session specifying the reason More... | |
void | handleRequest (std::string_view data) |
process received websocket frame, compose and execute response More... | |
void | asyncRead () |
asynchronously read More... | |
void | asyncWrite () |
asynchronously write More... | |
void | onRun () |
connected callback More... | |
void | onAccept (boost::system::error_code ec) |
handshake completion callback More... | |
void | onRead (boost::system::error_code ec, std::size_t size) |
read completion callback More... | |
void | onWrite (boost::system::error_code ec, std::size_t bytes_transferred) |
write completion callback More... | |
void | reportError (boost::system::error_code ec, std::string_view message) |
reports error code and message More... | |
Private Attributes | |
boost::asio::strand< boost::asio::io_context::executor_type > | strand_ |
Strand to ensure the connection's handlers are not called concurrently. More... | |
boost::asio::ip::tcp::socket | socket_ |
Socket for the connection. More... | |
Configuration | config_ |
session configuration More... | |
boost::beast::websocket::stream< boost::asio::ip::tcp::socket & > | stream_ |
boost::beast::flat_buffer | rbuffer_ |
read buffer More... | |
boost::beast::flat_buffer | wbuffer_ |
write buffer More... | |
std::mutex | cs_ |
std::queue< std::string > | pending_responses_ |
std::atomic_bool | writing_in_progress_ = false |
std::atomic_bool | stopped_ = false |
SessionId const | id_ |
OnWsSessionCloseHandler | on_ws_close_ |
log::Logger | logger_ = log::createLogger("WsSession", "rpc_transport") |
Additional Inherited Members | |
Public Types inherited from kagome::api::Session | |
using | Context = RpcContext |
using | Socket = boost::asio::ip::tcp::socket |
using | ErrorCode = boost::system::error_code |
using | Streambuf = boost::asio::streambuf |
using | Timer = boost::asio::steady_timer |
using | Connection = boost::signals2::connection |
using | Duration = Timer::duration |
using | SessionId = uint64_t |
using | OnCloseHandler = std::function< void(SessionId, SessionType)> |
Event handlers. More... | |
Definition at line 24 of file ws_session.hpp.
|
private |
Definition at line 27 of file ws_session.hpp.
|
private |
Definition at line 26 of file ws_session.hpp.
|
overridedefault |
kagome::api::WsSession::WsSession | ( | Context & | context, |
Configuration | config, | ||
SessionId | id | ||
) |
constructor
socket | socket instance |
config | session configuration |
id | session id |
Definition at line 15 of file ws_session.cpp.
|
private |
asynchronously read
Definition at line 69 of file ws_session.cpp.
|
private |
asynchronously write
Definition at line 88 of file ws_session.cpp.
void kagome::api::WsSession::connectOnWsSessionCloseHandler | ( | WsSession::OnWsSessionCloseHandler && | handler | ) |
connects on websocket close
callback. Used to maintain the maximum number of simultaneous sessions
handler | on close event handler |
Definition at line 59 of file ws_session.cpp.
|
private |
process received websocket frame, compose and execute response
Body | request body type |
request | request |
Definition at line 64 of file ws_session.cpp.
|
overridevirtual |
method to get id of the session
Implements kagome::api::Session.
Definition at line 75 of file ws_session.cpp.
|
private |
handshake completion callback
Definition at line 125 of file ws_session.cpp.
|
private |
read completion callback
Definition at line 137 of file ws_session.cpp.
|
private |
connected callback
Definition at line 108 of file ws_session.cpp.
|
private |
write completion callback
Definition at line 155 of file ws_session.cpp.
void kagome::api::WsSession::reject | ( | ) |
Closes the incoming connection with "try again later" response.
Definition at line 29 of file ws_session.cpp.
|
private |
reports error code and message
ec | error code |
message | error message |
Definition at line 188 of file ws_session.cpp.
|
overridevirtual |
sends response wrapped by websocket frame
response | message to send |
Implements kagome::api::Session.
Definition at line 79 of file ws_session.cpp.
|
inlineoverridevirtual |
Implements kagome::api::Session.
Definition at line 48 of file ws_session.hpp.
|
overridevirtual |
|
private |
stops session
Definition at line 34 of file ws_session.cpp.
|
private |
stops session specifying the reason
code | for close reason |
Definition at line 39 of file ws_session.cpp.
|
inlineoverridevirtual |
method to get type of the session
Implements kagome::api::Session.
Definition at line 67 of file ws_session.hpp.
|
private |
session configuration
Definition at line 151 of file ws_session.hpp.
|
private |
Definition at line 156 of file ws_session.hpp.
|
private |
Definition at line 162 of file ws_session.hpp.
|
private |
Definition at line 164 of file ws_session.hpp.
|
private |
Definition at line 163 of file ws_session.hpp.
|
private |
Definition at line 157 of file ws_session.hpp.
|
private |
read buffer
Definition at line 153 of file ws_session.hpp.
|
private |
Socket for the connection.
Definition at line 149 of file ws_session.hpp.
|
private |
Definition at line 160 of file ws_session.hpp.
|
private |
Strand to ensure the connection's handlers are not called concurrently.
Definition at line 146 of file ws_session.hpp.
|
private |
Definition at line 152 of file ws_session.hpp.
|
private |
write buffer
Definition at line 154 of file ws_session.hpp.
|
private |
Definition at line 159 of file ws_session.hpp.