Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
StreamData.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "util/requests/Types.hpp"
23#include "util/requests/impl/SslContext.hpp"
24
25#include <boost/asio/associated_executor.hpp>
26#include <boost/asio/spawn.hpp>
27#include <boost/asio/ssl/context.hpp>
28#include <boost/asio/ssl/stream.hpp>
29#include <boost/beast/core/error.hpp>
30#include <boost/beast/core/tcp_stream.hpp>
31#include <boost/beast/ssl/ssl_stream.hpp>
32#include <boost/beast/websocket.hpp>
33#include <boost/beast/websocket/stream.hpp>
34
35#include <expected>
36#include <utility>
37
38namespace util::requests::impl {
39
40template <typename StreamType>
42 static constexpr bool kSSL_ENABLED = false;
43
44 explicit PlainStreamData(boost::asio::yield_context yield) : stream(boost::asio::get_associated_executor(yield))
45 {
46 }
47
48 StreamType stream;
49};
50
53
54template <typename StreamType>
56 boost::asio::ssl::context sslContext_;
57
58public:
59 static constexpr bool kSSL_ENABLED = true;
60
61 static std::expected<SslStreamData, RequestError>
62 create(boost::asio::yield_context yield)
63 {
64 auto sslContext = makeClientSslContext();
65 if (not sslContext.has_value()) {
66 return std::unexpected{std::move(sslContext.error())};
67 }
68 return SslStreamData{std::move(sslContext).value(), yield};
69 }
70
71 StreamType stream;
72
73private:
74 SslStreamData(boost::asio::ssl::context sslContext, boost::asio::yield_context yield)
75 : sslContext_(std::move(sslContext)), stream(boost::asio::get_associated_executor(yield), sslContext_)
76
77 {
78 }
79};
80
82using SslWsStreamData =
84
85} // namespace util::requests::impl
Definition StreamData.hpp:55
Definition StreamData.hpp:41