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/app/main/Application.h>
24#include <xrpld/overlay/ClusterNode.h>
25#include <xrpl/basics/BasicConfig.h>
26#include <xrpl/basics/chrono.h>
27#include <xrpl/beast/hash/uhash.h>
28#include <xrpl/beast/utility/Journal.h>
29#include <xrpl/protocol/PublicKey.h>
30#include <functional>
31#include <memory>
32#include <mutex>
33#include <set>
34#include <type_traits>
35
36namespace ripple {
37
39{
40private:
42 {
43 explicit Comparator() = default;
44
46
47 bool
48 operator()(ClusterNode const& lhs, ClusterNode const& rhs) const
49 {
50 return lhs.identity() < rhs.identity();
51 }
52
53 bool
54 operator()(ClusterNode const& lhs, PublicKey const& rhs) const
55 {
56 return lhs.identity() < rhs;
57 }
58
59 bool
60 operator()(PublicKey const& lhs, ClusterNode const& rhs) const
61 {
62 return lhs < rhs.identity();
63 }
64 };
65
69
70public:
72
79 member(PublicKey const& node) const;
80
83 size() const;
84
90 bool
91 update(
92 PublicKey const& identity,
93 std::string name,
94 std::uint32_t loadFee = 0,
96
101 void
102 for_each(std::function<void(ClusterNode const&)> func) const;
103
114 bool
115 load(Section const& nodes);
116};
117
118} // namespace ripple
119
120#endif
A generic endpoint for log messages.
Definition: Journal.h:59
PublicKey const & identity() const
Definition: ClusterNode.h:63
std::set< ClusterNode, Comparator > nodes_
Definition: Cluster.h:66
void for_each(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition: Cluster.cpp:82
std::size_t size() const
The number of nodes in the cluster list.
Definition: Cluster.cpp:48
bool load(Section const &nodes)
Load the list of cluster nodes.
Definition: Cluster.cpp:90
beast::Journal j_
Definition: Cluster.h:68
std::mutex mutex_
Definition: Cluster.h:67
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:56
std::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
Definition: Cluster.cpp:37
A public key.
Definition: PublicKey.h:62
Holds a collection of configuration values.
Definition: BasicConfig.h:46
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool operator()(ClusterNode const &lhs, PublicKey const &rhs) const
Definition: Cluster.h:54
bool operator()(PublicKey const &lhs, ClusterNode const &rhs) const
Definition: Cluster.h:60
bool operator()(ClusterNode const &lhs, ClusterNode const &rhs) const
Definition: Cluster.h:48