20#ifndef ORES_COMMS_NET_CONNECTION_HPP
21#define ORES_COMMS_NET_CONNECTION_HPP
26#include <boost/asio/ip/tcp.hpp>
27#include <boost/asio/ssl.hpp>
28#include <boost/asio/awaitable.hpp>
29#include "ores.comms/messaging/frame.hpp"
30#include "ores.logging/make_logger.hpp"
42 std::expected<messaging::frame, ores::utility::serialization::error_code> frame;
60 inline static std::string_view logger_name =
"ores.comms.net.connection";
64 static auto instance = make_logger(logger_name);
69 using ssl_socket = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>;
82 boost::asio::cancellation_slot cancel_slot = {});
90 boost::asio::cancellation_slot cancel_slot = {});
105 boost::asio::awaitable<read_frame_result>
107 boost::asio::cancellation_slot cancel_slot = {});
118 boost::asio::cancellation_slot cancel_slot = {});
138 [[nodiscard]] std::uint64_t
bytes_sent()
const;
152 std::atomic<std::uint64_t> bytes_sent_{0};
153 std::atomic<std::uint64_t> bytes_received_{0};
Contains the networking elements of the comms library.
Definition client.hpp:48
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Complete frame with header and payload.
Definition frame.hpp:77
Result of a read_frame operation.
Definition connection.hpp:41
std::optional< std::uint32_t > failed_correlation_id
Correlation ID from the header when CRC validation fails.
Definition connection.hpp:50
SSL connection wrapper for frame-based communication.
Definition connection.hpp:58
std::string remote_address() const
Get the remote endpoint address.
Definition connection.cpp:158
boost::asio::awaitable< void > ssl_handshake_server(boost::asio::cancellation_slot cancel_slot={})
Perform SSL handshake as server.
Definition connection.cpp:33
bool is_open() const
Check if the connection is open.
Definition connection.cpp:147
boost::asio::awaitable< read_frame_result > read_frame(bool skip_version_check=false, boost::asio::cancellation_slot cancel_slot={})
Read a complete frame from the connection.
Definition connection.cpp:46
std::uint64_t bytes_sent() const
Get total bytes sent on this connection.
Definition connection.cpp:169
void close()
Close the connection.
Definition connection.cpp:151
boost::asio::awaitable< void > write_frame(const messaging::frame &frame, boost::asio::cancellation_slot cancel_slot={})
Write a frame to the connection.
Definition connection.cpp:130
void reset_byte_counters()
Reset byte counters to zero.
Definition connection.cpp:177
boost::asio::awaitable< void > ssl_handshake_client(boost::asio::cancellation_slot cancel_slot={})
Perform SSL handshake as client.
Definition connection.cpp:39
std::uint64_t bytes_received() const
Get total bytes received on this connection.
Definition connection.cpp:173