rippled
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 <ripple/app/main/Application.h>
24 #include <ripple/basics/BasicConfig.h>
25 #include <ripple/basics/chrono.h>
26 #include <ripple/beast/hash/uhash.h>
27 #include <ripple/beast/utility/Journal.h>
28 #include <ripple/overlay/ClusterNode.h>
29 #include <ripple/protocol/PublicKey.h>
30 #include <functional>
31 #include <memory>
32 #include <mutex>
33 #include <set>
34 #include <type_traits>
35 
36 namespace ripple {
37 
38 class Cluster
39 {
40 private:
41  struct Comparator
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 
67  std::mutex mutable mutex_;
68  beast::Journal mutable j_;
69 
70 public:
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
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::ClusterNode
Definition: ClusterNode.h:30
ripple::Cluster::Cluster
Cluster(beast::Journal j)
Definition: Cluster.cpp:34
std::true_type
std::string
STL class.
functional
ripple::Cluster::Comparator::operator()
bool operator()(PublicKey const &lhs, ClusterNode const &rhs) const
Definition: Cluster.h:60
ripple::Cluster::member
std::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
Definition: Cluster.cpp:39
std::function
ripple::Cluster::update
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:58
ripple::Cluster::load
bool load(Section const &nodes)
Load the list of cluster nodes.
Definition: Cluster.cpp:92
ripple::Cluster::j_
beast::Journal j_
Definition: Cluster.h:68
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::Cluster
Definition: Cluster.h:38
std::chrono::time_point
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::Cluster::size
std::size_t size() const
The number of nodes in the cluster list.
Definition: Cluster.cpp:50
memory
ripple::Cluster::Comparator::operator()
bool operator()(ClusterNode const &lhs, ClusterNode const &rhs) const
Definition: Cluster.h:48
ripple::Cluster::Comparator
Definition: Cluster.h:41
ripple::Cluster::Comparator::operator()
bool operator()(ClusterNode const &lhs, PublicKey const &rhs) const
Definition: Cluster.h:54
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Cluster::mutex_
std::mutex mutex_
Definition: Cluster.h:67
ripple::Cluster::nodes_
std::set< ClusterNode, Comparator > nodes_
Definition: Cluster.h:66
std::optional< std::string >
mutex
std::size_t
ripple::Cluster::for_each
void for_each(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition: Cluster.cpp:84
ripple::Cluster::Comparator::Comparator
Comparator()=default
type_traits
set
ripple::ClusterNode::identity
PublicKey const & identity() const
Definition: ClusterNode.h:63