CatapultServer  v0.5.0.1 (Elephant)
NodeSelector.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/ionet/Node.h"
25 #include <random>
26 
27 namespace catapult { namespace ionet { class NodeContainer; } }
28 
29 namespace catapult { namespace extensions {
30 
35 
38  };
39 
41  using ImportanceRetriever = std::function<ImportanceDescriptor (const Key&)>;
42 
45  public:
47  WeightedCandidate(const ionet::Node& node, uint64_t weight)
48  : Node(node)
49  , Weight(weight)
50  {}
51 
52  public:
54  const ionet::Node& Node;
55 
57  uint64_t Weight;
58  };
59 
60  using WeightedCandidates = std::vector<WeightedCandidate>;
61 
66 
69  };
70 
75 
77  uint32_t MaxConnections;
78 
80  uint32_t MaxConnectionAge;
81  };
82 
87 
90 
92  uint32_t MaxConnections;
93 
95  uint32_t MaxConnectionAge;
96  };
97 
99  enum class WeightPolicy {
101  Interactions,
102 
104  Importance
105  };
106 
109  public:
112  : m_generator(std::random_device()())
113  , m_distr(1, 4)
114  {}
115 
116  public:
119  return 4 == static_cast<uint32_t>(m_distr(m_generator)) ? WeightPolicy::Importance : WeightPolicy::Interactions;
120  }
121 
122  private:
123  std::mt19937 m_generator;
124  std::uniform_int_distribution<> m_distr;
125  };
126 
128  uint32_t CalculateWeight(
129  const ionet::NodeInteractions& interactions,
130  WeightPolicy weightPolicy,
131  const supplier<ImportanceDescriptor>& importanceSupplier);
132 
136  const WeightedCandidates& candidates,
137  uint64_t totalCandidateWeight,
138  size_t maxCandidates);
139 
143  const ionet::NodeContainer& nodes,
144  const NodeSelectionConfiguration& config,
145  const ImportanceRetriever& importanceRetriever);
146 
150  const ionet::NodeContainer& nodes,
151  const NodeAgingConfiguration& config,
152  const ImportanceRetriever& importanceRetriever);
153 }}
catapult::extensions::NodeAgingConfiguration::MaxConnections
uint32_t MaxConnections
Maximum number of connections (per service).
Definition: NodeSelector.h:77
catapult::extensions::WeightedCandidate::Node
const ionet::Node & Node
Node.
Definition: NodeSelector.h:54
catapult::extensions::CalculateWeight
uint32_t CalculateWeight(const ionet::NodeInteractions &interactions, WeightPolicy weightPolicy, const supplier< ImportanceDescriptor > &importanceSupplier)
Calculates the weight from interactions or importanceSupplier depending on weightPolicy.
Definition: NodeSelector.cpp:123
catapult::extensions::ImportanceDescriptor::Importance
catapult::Importance Importance
Associated importance.
Definition: NodeSelector.h:34
TotalCandidateWeight
uint64_t TotalCandidateWeight
Definition: NodeSelector.cpp:45
catapult::extensions::NodeSelectionResult::AddCandidates
ionet::NodeSet AddCandidates
Nodes that should be activatated.
Definition: NodeSelector.h:65
catapult::ionet::ServiceIdentifier
utils::BaseValue< uint32_t, ServiceIdentifier_tag > ServiceIdentifier
Definition: NodeInfo.h:56
catapult::extensions::NodeAgingConfiguration::MaxConnectionAge
uint32_t MaxConnectionAge
Maximum connection age.
Definition: NodeSelector.h:80
catapult::extensions::SelectNodes
NodeSelectionResult SelectNodes(const ionet::NodeContainer &nodes, const NodeSelectionConfiguration &config, const ImportanceRetriever &importanceRetriever)
Definition: NodeSelector.cpp:175
catapult::extensions::WeightPolicy::Interactions
Weight is calculated using the interaction statistics.
catapult::extensions::NodeSelectionConfiguration
Node selection configuration.
Definition: NodeSelector.h:84
catapult::extensions::WeightedCandidates
std::vector< WeightedCandidate > WeightedCandidates
Definition: NodeSelector.h:60
catapult::extensions::WeightedCandidate
A weighted candidate.
Definition: NodeSelector.h:44
catapult::extensions::WeightPolicyGenerator::operator()
WeightPolicy operator()()
Generates the next weight policy.
Definition: NodeSelector.h:118
NodeInfo.h
catapult::extensions::NodeAgingConfiguration
Node aging configuration.
Definition: NodeSelector.h:72
catapult::extensions::NodeSelectionResult
Result of a node selection.
Definition: NodeSelector.h:63
catapult::extensions::NodeSelectionConfiguration::MaxConnections
uint32_t MaxConnections
Maximum number of connections (per service).
Definition: NodeSelector.h:92
catapult::extensions::WeightPolicyGenerator
Weight policy generator.
Definition: NodeSelector.h:108
catapult::supplier
std::function< T()> supplier
A (stateless) supplier function.
Definition: functions.h:39
catapult::extensions::SelectNodesForRemoval
utils::KeySet SelectNodesForRemoval(const ionet::NodeContainer &nodes, const NodeAgingConfiguration &config, const ImportanceRetriever &importanceRetriever)
Definition: NodeSelector.cpp:198
catapult::utils::BaseValue< uint64_t, Importance_tag >
catapult::ionet::NodeContainer
A collection of nodes.
Definition: NodeContainer.h:109
catapult::extensions::WeightPolicy
WeightPolicy
Weight calculation policies.
Definition: NodeSelector.h:99
catapult::extensions::SelectCandidatesBasedOnWeight
ionet::NodeSet SelectCandidatesBasedOnWeight(const WeightedCandidates &candidates, uint64_t totalCandidateWeight, size_t maxCandidates)
Definition: NodeSelector.cpp:143
catapult::extensions::NodeSelectionConfiguration::MaxConnectionAge
uint32_t MaxConnectionAge
Maximum connection age.
Definition: NodeSelector.h:95
catapult::extensions::ImportanceRetriever
std::function< ImportanceDescriptor(const Key &)> ImportanceRetriever
Retrieves an importance descriptor given a specified public key.
Definition: NodeSelector.h:41
catapult::extensions::ImportanceDescriptor::TotalChainImportance
catapult::Importance TotalChainImportance
Total chain importance.
Definition: NodeSelector.h:37
catapult::extensions::WeightedCandidate::WeightedCandidate
WeightedCandidate(const ionet::Node &node, uint64_t weight)
Creates a weighted candidate around node and weight.
Definition: NodeSelector.h:47
catapult::extensions::WeightedCandidate::Weight
uint64_t Weight
Weight of the node.
Definition: NodeSelector.h:57
catapult::extensions::WeightPolicyGenerator::m_distr
std::uniform_int_distribution m_distr
Definition: NodeSelector.h:124
catapult::ionet::NodeSet
std::unordered_set< Node, NodeHasher > NodeSet
A set of nodes.
Definition: Node.h:128
catapult::ionet::NodeRoles
NodeRoles
A node's role.
Definition: NodeRoles.h:28
Node.h
NodeContainer.h
catapult::extensions::NodeSelectionConfiguration::ServiceId
ionet::ServiceIdentifier ServiceId
Identity of the service for which nodes should be selected.
Definition: NodeSelector.h:86
catapult::extensions::WeightPolicy::Importance
Weight is calculated using importance.
catapult::utils::KeySet
ArraySet< Key > KeySet
A key set.
Definition: ArraySet.h:64
catapult::extensions::WeightPolicyGenerator::m_generator
std::mt19937 m_generator
Definition: NodeSelector.h:123
catapult::extensions::ImportanceDescriptor
Describes an importance value.
Definition: NodeSelector.h:32
catapult::ionet::NodeInteractions::NumSuccesses
uint32_t NumSuccesses
Number of successful interactions.
Definition: NodeInteractionsContainer.h:43
catapult::ionet::NodeSource
NodeSource
Definition: NodeInfo.h:47
catapult::ionet::NodeInteractions
Node interactions.
Definition: NodeInteractionsContainer.h:29
NodeSelector.h
catapult::extensions::NodeSelectionResult::RemoveCandidates
utils::KeySet RemoveCandidates
Identities of the nodes that should be deactivated.
Definition: NodeSelector.h:68
catapult::extensions::WeightPolicyGenerator::WeightPolicyGenerator
WeightPolicyGenerator()
Creates a default weight policy generator.
Definition: NodeSelector.h:111
Candidates
WeightedCandidates Candidates
Definition: NodeSelector.cpp:44
ArraySet.h
catapult::extensions::NodeSelectionConfiguration::RequiredRole
ionet::NodeRoles RequiredRole
Required node role.
Definition: NodeSelector.h:89
catapult
Definition: AddressExtractionExtension.cpp:28
Actives
NodeScorePairs Actives
Definition: NodeSelector.cpp:43
catapult::utils::ByteArray< Key_Size, Key_tag >
catapult::ionet::Node
A node in the catapult network.
Definition: Node.h:82
catapult::extensions::NodeAgingConfiguration::ServiceId
ionet::ServiceIdentifier ServiceId
Identity of the service for which nodes should be selected.
Definition: NodeSelector.h:74