rippled
ResourceManager.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_RESOURCE_MANAGER_H_INCLUDED
21 #define RIPPLE_RESOURCE_MANAGER_H_INCLUDED
22 
23 #include <ripple/beast/insight/Collector.h>
24 #include <ripple/beast/net/IPEndpoint.h>
25 #include <ripple/beast/utility/Journal.h>
26 #include <ripple/beast/utility/PropertyStream.h>
27 #include <ripple/json/json_value.h>
28 #include <ripple/resource/Consumer.h>
29 #include <ripple/resource/Gossip.h>
30 #include <boost/utility/string_view.hpp>
31 
32 namespace ripple {
33 namespace Resource {
34 
37 {
38 protected:
39  Manager();
40 
41 public:
42  virtual ~Manager() = 0;
43 
46  virtual Consumer
47  newInboundEndpoint(beast::IP::Endpoint const& address) = 0;
48  virtual Consumer
50  beast::IP::Endpoint const& address,
51  bool const proxy,
52  boost::string_view const& forwardedFor) = 0;
53 
55  virtual Consumer
56  newOutboundEndpoint(beast::IP::Endpoint const& address) = 0;
57 
59  virtual Consumer
60  newUnlimitedEndpoint(beast::IP::Endpoint const& address) = 0;
61 
63  virtual Gossip
64  exportConsumers() = 0;
65 
67  virtual Json::Value
68  getJson() = 0;
69  virtual Json::Value
70  getJson(int threshold) = 0;
71 
75  virtual void
76  importConsumers(std::string const& origin, Gossip const& gossip) = 0;
77 };
78 
79 //------------------------------------------------------------------------------
80 
83  beast::insight::Collector::ptr const& collector,
84  beast::Journal journal);
85 
86 } // namespace Resource
87 } // namespace ripple
88 
89 #endif
ripple::Resource::Manager::newInboundEndpoint
virtual Consumer newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
ripple::Resource::Manager::newOutboundEndpoint
virtual Consumer newOutboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by outbound IP address and port.
ripple::Resource::Manager::getJson
virtual Json::Value getJson()=0
Extract consumer information for reporting.
std::string
STL class.
std::shared_ptr< Collector >
ripple::Resource::Gossip
Data format for exchanging consumption information across peers.
Definition: Gossip.h:29
beast::PropertyStream::Source
Subclasses can be called to write to a stream and have children.
Definition: PropertyStream.h:330
ripple::Resource::Manager::exportConsumers
virtual Gossip exportConsumers()=0
Extract packaged consumer information for export.
ripple::Resource::Manager::importConsumers
virtual void importConsumers(std::string const &origin, Gossip const &gossip)=0
Import packaged consumer information.
ripple::forwardedFor
boost::string_view forwardedFor(http_request_type const &request)
Definition: Role.cpp:261
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::Resource::Manager::Manager
Manager()
Definition: ResourceManager.cpp:166
ripple::Resource::Manager
Tracks load and resource consumption.
Definition: ResourceManager.h:36
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Resource::make_Manager
std::unique_ptr< Manager > make_Manager(beast::insight::Collector::ptr const &collector, beast::Journal journal)
Definition: ResourceManager.cpp:175
ripple::Resource::Manager::newUnlimitedEndpoint
virtual Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)=0
Create a new unlimited endpoint keyed by forwarded IP.
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:34
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
std::unique_ptr
STL class.
ripple::Resource::Manager::~Manager
virtual ~Manager()=0
Json::Value
Represents a JSON value.
Definition: json_value.h:145