rippled
Loading...
Searching...
No Matches
Cluster.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_OVERLAY_CLUSTER_H_INCLUDED
21#define RIPPLE_OVERLAY_CLUSTER_H_INCLUDED
22
23#include <xrpld/overlay/ClusterNode.h>
24
25#include <xrpl/basics/BasicConfig.h>
26#include <xrpl/basics/chrono.h>
27#include <xrpl/beast/utility/Journal.h>
28#include <xrpl/protocol/PublicKey.h>
29
30#include <functional>
31#include <mutex>
32#include <set>
33
34namespace ripple {
35
37{
38private:
40 {
41 explicit Comparator() = default;
42
44
45 bool
46 operator()(ClusterNode const& lhs, ClusterNode const& rhs) const
47 {
48 return lhs.identity() < rhs.identity();
49 }
50
51 bool
52 operator()(ClusterNode const& lhs, PublicKey const& rhs) const
53 {
54 return lhs.identity() < rhs;
55 }
56
57 bool
58 operator()(PublicKey const& lhs, ClusterNode const& rhs) const
59 {
60 return lhs < rhs.identity();
61 }
62 };
63
67
68public:
70
77 member(PublicKey const& node) const;
78
81 size() const;
82
88 bool
89 update(
90 PublicKey const& identity,
91 std::string name,
92 std::uint32_t loadFee = 0,
94
99 void
100 for_each(std::function<void(ClusterNode const&)> func) const;
101
112 bool
113 load(Section const& nodes);
114};
115
116} // namespace ripple
117
118#endif
A generic endpoint for log messages.
Definition Journal.h:60
PublicKey const & identity() const
Definition ClusterNode.h:64
std::set< ClusterNode, Comparator > nodes_
Definition Cluster.h:64
void for_each(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition Cluster.cpp:83
std::size_t size() const
The number of nodes in the cluster list.
Definition Cluster.cpp:49
bool load(Section const &nodes)
Load the list of cluster nodes.
Definition Cluster.cpp:91
beast::Journal j_
Definition Cluster.h:66
std::mutex mutex_
Definition Cluster.h:65
bool update(PublicKey const &identity, std::string name, std::uint32_t loadFee=0, NetClock::time_point reportTime=NetClock::time_point{})
Store information about the state of a cluster node.
Definition Cluster.cpp:57
std::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
Definition Cluster.cpp:38
A public key.
Definition PublicKey.h:61
Holds a collection of configuration values.
Definition BasicConfig.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
bool operator()(ClusterNode const &lhs, PublicKey const &rhs) const
Definition Cluster.h:52
bool operator()(PublicKey const &lhs, ClusterNode const &rhs) const
Definition Cluster.h:58
bool operator()(ClusterNode const &lhs, ClusterNode const &rhs) const
Definition Cluster.h:46