Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ConnectionBase.hpp
1#pragma once
2
3#include "util/Taggable.hpp"
4#include "web/SubscriptionContextInterface.hpp"
5
6#include <boost/beast/http.hpp>
7#include <boost/beast/http/status.hpp>
8#include <boost/signals2.hpp>
9#include <boost/signals2/variadic_signal.hpp>
10
11#include <memory>
12#include <stdexcept>
13#include <string>
14#include <utility>
15
16namespace web {
17
18namespace http = boost::beast::http;
19
26protected:
27 boost::system::error_code ec_;
28 bool isAdmin_ = false;
29 std::string clientIp_;
30
31public:
32 bool upgraded = false;
33
40 ConnectionBase(util::TagDecoratorFactory const& tagFactory, std::string ip)
41 : Taggable(tagFactory), clientIp_(std::move(ip))
42 {
43 }
44
51 virtual void
52 send(std::string&& msg, http::status status = http::status::ok) = 0;
53
60 virtual void
61 send([[maybe_unused]] std::shared_ptr<std::string> msg)
62 {
63 throw std::logic_error("web server can not send the shared payload");
64 }
65
71 virtual void
72 sendSlowDown(std::string const& request) = 0;
81
87 bool
89 {
90 return ec_ != boost::system::error_code{};
91 }
92
98 [[nodiscard]] bool
99 isAdmin() const
100 {
101 return isAdmin_;
102 }
103
109 [[nodiscard]] std::string const&
110 clientIp() const
111 {
112 return clientIp_;
113 }
114};
115} // namespace web
A factory for TagDecorator instantiation.
Definition Taggable.hpp:165
A base class that allows attaching a tag decorator to a subclass.
Definition Taggable.hpp:236
Taggable(util::TagDecoratorFactory const &tagFactory)
New Taggable from a specified factory.
Definition Taggable.hpp:246
This namespace implements the web server and related components.
Definition Types.hpp:24
std::shared_ptr< SubscriptionContextInterface > SubscriptionContextPtr
An alias for shared pointer to a SubscriptionContextInterface.
Definition SubscriptionContextInterface.hpp:64
virtual SubscriptionContextPtr makeSubscriptionContext(util::TagDecoratorFactory const &factory)=0
Get the subscription context for this connection.
virtual void send(std::shared_ptr< std::string > msg)
Send via shared_ptr of string, that enables SubscriptionManager to publish to clients.
Definition ConnectionBase.hpp:61
std::string const & clientIp() const
Get the IP address of the client.
Definition ConnectionBase.hpp:110
ConnectionBase(util::TagDecoratorFactory const &tagFactory, std::string ip)
Create a new connection base.
Definition ConnectionBase.hpp:40
bool isAdmin() const
Indicates whether the connection has admin privileges.
Definition ConnectionBase.hpp:99
virtual void send(std::string &&msg, http::status status=http::status::ok)=0
Send the response to the client.
bool dead()
Indicates whether the connection had an error and is considered dead.
Definition ConnectionBase.hpp:88
virtual void sendSlowDown(std::string const &request)=0
Send a "slow down" error response to the client.