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/chrono.h>
25 #include <ripple/basics/BasicConfig.h>
26 #include <ripple/overlay/ClusterNode.h>
27 #include <ripple/protocol/PublicKey.h>
28 #include <ripple/beast/hash/uhash.h>
29 #include <ripple/beast/utility/Journal.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
49  ClusterNode const& lhs,
50  ClusterNode const& rhs) const
51  {
52  return lhs.identity() < rhs.identity();
53  }
54 
55  bool
57  ClusterNode const& lhs,
58  PublicKey const& rhs) const
59  {
60  return lhs.identity() < rhs;
61  }
62 
63  bool
65  PublicKey const& lhs,
66  ClusterNode const& rhs) const
67  {
68  return lhs < rhs.identity();
69  }
70  };
71 
73  std::mutex mutable mutex_;
74  beast::Journal mutable j_;
75 
76 public:
78 
84  boost::optional<std::string>
85  member (PublicKey const& node) const;
86 
89  size() const;
90 
96  bool
97  update (
98  PublicKey const& identity,
99  std::string name,
100  std::uint32_t loadFee = 0,
102 
107  void
108  for_each (
109  std::function<void(ClusterNode const&)> func) const;
110 
121  bool
122  load (Section const& nodes);
123 };
124 
125 } // ripple
126 
127 #endif
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
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
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:59
ripple::Cluster::load
bool load(Section const &nodes)
Load the list of cluster nodes.
Definition: Cluster.cpp:97
ripple::Cluster::member
boost::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
Definition: Cluster.cpp:40
ripple::Cluster::j_
beast::Journal j_
Definition: Cluster.h:74
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:60
std::uint32_t
ripple::Cluster::size
std::size_t size() const
The number of nodes in the cluster list.
Definition: Cluster.cpp:51
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
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:73
ripple::Cluster::nodes_
std::set< ClusterNode, Comparator > nodes_
Definition: Cluster.h:72
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:88
ripple::Cluster::Comparator::Comparator
Comparator()=default
type_traits
set
ripple::ClusterNode::identity
PublicKey const & identity() const
Definition: ClusterNode.h:62