rippled
Loading...
Searching...
No Matches
SSLWSPeer.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or 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#ifndef RIPPLE_SERVER_SSLWSPEER_H_INCLUDED
21#define RIPPLE_SERVER_SSLWSPEER_H_INCLUDED
22
23#include <xrpl/server/WSSession.h>
24#include <xrpl/server/detail/BaseHTTPPeer.h>
25
26#include <boost/asio/ip/tcp.hpp>
27#include <boost/asio/ssl/context.hpp>
28#include <boost/asio/ssl/stream.hpp>
29#include <boost/beast/core/tcp_stream.hpp>
30#include <boost/beast/ssl/ssl_stream.hpp>
31#include <boost/beast/websocket/ssl.hpp>
32
33#include <memory>
34
35namespace ripple {
36
37template <class Handler>
38class SSLWSPeer : public BaseWSPeer<Handler, SSLWSPeer<Handler>>,
39 public std::enable_shared_from_this<SSLWSPeer<Handler>>
40{
41 friend class BasePeer<Handler, SSLWSPeer>;
42 friend class BaseWSPeer<Handler, SSLWSPeer>;
43
45 using error_code = boost::system::error_code;
46 using endpoint_type = boost::asio::ip::tcp::endpoint;
47 using socket_type = boost::beast::tcp_stream;
48 using stream_type = boost::beast::ssl_stream<socket_type>;
49 using waitable_timer = boost::asio::basic_waitable_timer<clock_type>;
50
52 boost::beast::websocket::stream<stream_type&> ws_;
53
54public:
55 template <class Body, class Headers>
57 Port const& port,
58 Handler& handler,
60 boost::beast::http::request<Body, Headers>&& request,
62 beast::Journal journal);
63};
64
65//------------------------------------------------------------------------------
66
67template <class Handler>
68template <class Body, class Headers>
70 Port const& port,
71 Handler& handler,
72 endpoint_type remote_endpoint,
73 boost::beast::http::request<Body, Headers>&& request,
75 beast::Journal journal)
76 : BaseWSPeer<Handler, SSLWSPeer>(
77 port,
78 handler,
79 stream_ptr->get_executor(),
80 waitable_timer{stream_ptr->get_executor()},
81 remote_endpoint,
82 std::move(request),
83 journal)
84 , stream_ptr_(std::move(stream_ptr))
85 , ws_(*stream_ptr_)
86{
87}
88
89} // namespace ripple
90
91#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Represents an active WebSocket connection.
Definition: BaseWSPeer.h:45
http_request_type const & request() const override
Definition: BaseWSPeer.h:99
boost::asio::ip::tcp::endpoint const & remote_endpoint() const override
Definition: BaseWSPeer.h:105
boost::beast::websocket::stream< stream_type & > ws_
Definition: SSLWSPeer.h:52
SSLWSPeer(Port const &port, Handler &handler, endpoint_type remote_endpoint, boost::beast::http::request< Body, Headers > &&request, std::unique_ptr< stream_type > &&stream_ptr, beast::Journal journal)
Definition: SSLWSPeer.h:69
boost::beast::ssl_stream< socket_type > stream_type
Definition: SSLWSPeer.h:48
std::unique_ptr< stream_type > stream_ptr_
Definition: SSLWSPeer.h:51
boost::beast::tcp_stream socket_type
Definition: SSLWSPeer.h:47
boost::asio::ip::tcp::endpoint endpoint_type
Definition: SSLWSPeer.h:46
boost::system::error_code error_code
Definition: SSLWSPeer.h:45
boost::asio::basic_waitable_timer< clock_type > waitable_timer
Definition: SSLWSPeer.h:49
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
STL namespace.
Configuration information for a Server listening port.
Definition: Port.h:50