rippled
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 <ripple/server/WSSession.h>
24 #include <ripple/server/impl/BaseHTTPPeer.h>
25 #include <boost/asio/ip/tcp.hpp>
26 #include <boost/asio/ssl/context.hpp>
27 #include <boost/asio/ssl/stream.hpp>
28 #include <boost/beast/core/tcp_stream.hpp>
29 #include <boost/beast/ssl/ssl_stream.hpp>
30 #include <boost/beast/websocket/ssl.hpp>
31 #include <memory>
32 
33 namespace ripple {
34 
35 template <class Handler>
36 class SSLWSPeer : public BaseWSPeer<Handler, SSLWSPeer<Handler>>,
37  public std::enable_shared_from_this<SSLWSPeer<Handler>>
38 {
39  friend class BasePeer<Handler, SSLWSPeer>;
40  friend class BaseWSPeer<Handler, SSLWSPeer>;
41 
43  using error_code = boost::system::error_code;
44  using endpoint_type = boost::asio::ip::tcp::endpoint;
45  using socket_type = boost::beast::tcp_stream;
46  using stream_type = boost::beast::ssl_stream<socket_type>;
47  using waitable_timer = boost::asio::basic_waitable_timer<clock_type>;
48 
50  boost::beast::websocket::stream<stream_type&> ws_;
51 
52 public:
53  template <class Body, class Headers>
54  SSLWSPeer(
55  Port const& port,
56  Handler& handler,
58  boost::beast::http::request<Body, Headers>&& request,
59  std::unique_ptr<stream_type>&& stream_ptr,
60  beast::Journal journal);
61 };
62 
63 //------------------------------------------------------------------------------
64 
65 template <class Handler>
66 template <class Body, class Headers>
68  Port const& port,
69  Handler& handler,
70  endpoint_type remote_endpoint,
71  boost::beast::http::request<Body, Headers>&& request,
72  std::unique_ptr<stream_type>&& stream_ptr,
73  beast::Journal journal)
74  : BaseWSPeer<Handler, SSLWSPeer>(
75  port,
76  handler,
77  stream_ptr->get_executor(),
78  waitable_timer{stream_ptr->get_executor()},
79  remote_endpoint,
80  std::move(request),
81  journal)
82  , stream_ptr_(std::move(stream_ptr))
83  , ws_(*stream_ptr_)
84 {
85 }
86 
87 } // namespace ripple
88 
89 #endif
std::chrono::system_clock
ripple::SSLWSPeer::socket_type
boost::beast::tcp_stream socket_type
Definition: SSLWSPeer.h:45
ripple::SSLWSPeer::SSLWSPeer
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:67
ripple::BasePeer
Definition: BasePeer.h:37
ripple::SSLWSPeer::error_code
boost::system::error_code error_code
Definition: SSLWSPeer.h:43
ripple::BaseWSPeer< Handler, SSLWSPeer< Handler > >::remote_endpoint
boost::asio::ip::tcp::endpoint const & remote_endpoint() const override
Definition: BaseWSPeer.h:97
ripple::SSLWSPeer::endpoint_type
boost::asio::ip::tcp::endpoint endpoint_type
Definition: SSLWSPeer.h:44
std::enable_shared_from_this
ripple::SSLWSPeer::stream_type
boost::beast::ssl_stream< socket_type > stream_type
Definition: SSLWSPeer.h:46
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::SSLWSPeer::ws_
boost::beast::websocket::stream< stream_type & > ws_
Definition: SSLWSPeer.h:50
ripple::Port
Configuration information for a Server listening port.
Definition: Port.h:48
memory
ripple::SSLWSPeer::waitable_timer
boost::asio::basic_waitable_timer< clock_type > waitable_timer
Definition: SSLWSPeer.h:47
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::BaseWSPeer< Handler, SSLWSPeer< Handler > >::request
http_request_type const & request() const override
Definition: BaseWSPeer.h:91
ripple::SSLWSPeer
Definition: SSLWSPeer.h:36
ripple::SSLWSPeer::stream_ptr_
std::unique_ptr< stream_type > stream_ptr_
Definition: SSLWSPeer.h:49
std::unique_ptr< stream_type >
ripple::BaseWSPeer< Handler, SSLWSPeer< Handler > >::port
Port const & port() const override
Definition: BaseWSPeer.h:85
ripple::BaseWSPeer
Represents an active WebSocket connection.
Definition: BaseWSPeer.h:39