Radix Relay
Hybrid mesh communications with Signal Protocol encryption
Loading...
Searching...
No Matches
websocket_stream.hpp
Go to the documentation of this file.
1#pragma once
2
3
4#include <boost/asio.hpp>
5#include <boost/asio/ssl.hpp>
6#include <boost/beast/core.hpp>
7#include <boost/beast/ssl.hpp>
8#include <boost/beast/websocket.hpp>
9#include <boost/beast/websocket/ssl.hpp>
10#include <cstddef>
11#include <functional>
12#include <span>
13#include <string_view>
14
15namespace radix_relay::transport {
16
21{
22 std::string_view host;
23 std::string_view port;
24 std::string_view path;
25};
26
33{
34private:
35 static constexpr int connection_timeout_seconds = 30;
36
37 boost::asio::ssl::context ssl_context_;
38 boost::asio::ip::tcp::resolver resolver_;
39 boost::beast::websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>> ws_;
40 boost::beast::flat_buffer read_buffer_;
41
42public:
48 explicit websocket_stream(const std::shared_ptr<boost::asio::io_context> &io_context);
49
57 std::function<void(const boost::system::error_code &, std::size_t)> handler) -> void;
58
65 auto async_write(std::span<const std::byte> data,
66 std::function<void(const boost::system::error_code &, std::size_t)> handler) -> void;
67
74 auto async_read(const boost::asio::mutable_buffer &buffer,
75 std::function<void(const boost::system::error_code &, std::size_t)> handler) -> void;
76
82 auto async_close(std::function<void(const boost::system::error_code &, std::size_t)> handler) -> void;
83};
84
85
86}// namespace radix_relay::transport
WebSocket stream with TLS support.
auto async_close(std::function< void(const boost::system::error_code &, std::size_t)> handler) -> void
Asynchronously closes the WebSocket connection.
auto async_read(const boost::asio::mutable_buffer &buffer, std::function< void(const boost::system::error_code &, std::size_t)> handler) -> void
Asynchronously reads data from the WebSocket.
auto async_write(std::span< const std::byte > data, std::function< void(const boost::system::error_code &, std::size_t)> handler) -> void
Asynchronously writes data to the WebSocket.
websocket_stream(const std::shared_ptr< boost::asio::io_context > &io_context)
Constructs a WebSocket stream.
auto async_connect(websocket_connection_params params, std::function< void(const boost::system::error_code &, std::size_t)> handler) -> void
Asynchronously connects to a WebSocket endpoint.
Parameters for establishing a WebSocket connection.
std::string_view port
Port number (typically "443" for wss://)
std::string_view host
Hostname or IP address.
std::string_view path
WebSocket path (e.g., "/" or "/api/v1")