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