CatapultServer  v0.5.0.1 (Elephant)
NodeContainer.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "Node.h"
23 #include "NodeInfo.h"
26 #include <unordered_map>
27 
28 namespace catapult {
29  namespace ionet {
30  struct NodeContainerData;
31  struct NodeData;
32  struct NodeInteractionResult;
33  }
34 }
35 
36 namespace catapult { namespace ionet {
37 
40  public:
43 
44  public:
46  size_t size() const;
47 
49  Timestamp time() const;
50 
52  bool contains(const Key& identityKey) const;
53 
55  const NodeInfo& getNodeInfo(const Key& identityKey) const;
56 
59 
60  private:
63  };
64 
67  public:
70 
71  public:
74  bool add(const Node& node, NodeSource source);
75 
78 
80  ConnectionState& provisionConnectionState(ServiceIdentifier serviceId, const Key& identityKey);
81 
83  void ageConnections(ServiceIdentifier serviceId, const utils::KeySet& identities);
84 
87  void ageConnectionBans(ServiceIdentifier serviceId, uint32_t maxConnectionBanAge, uint32_t numConsecutiveFailuresBeforeBanning);
88 
90  void incrementSuccesses(const Key& identityKey);
91 
93  void incrementFailures(const Key& identityKey);
94 
95  private:
97 
99 
100  void incrementInteraction(const Key& identityKey, const consumer<NodeInfo&>& incrementer);
101 
102  private:
106  };
107 
110  public:
112  NodeContainer();
113 
115  NodeContainer(size_t maxNodes, const supplier<Timestamp>& timeSupplier);
116 
118  ~NodeContainer();
119 
120  public:
122  NodeContainerView view() const;
123 
126 
127  private:
128  std::unique_ptr<NodeContainerData> m_pImpl;
130  };
131 
134 }}
catapult::ionet::NodeContainer::view
NodeContainerView view() const
Gets a read only view of the nodes.
Definition: NodeContainer.cpp:249
catapult::ionet::NodeData::NodeId
size_t NodeId
Definition: NodeContainer.cpp:42
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::ionet::NodeContainer::modifier
NodeContainerModifier modifier()
Gets a write only view of the nodes.
Definition: NodeContainer.cpp:254
catapult::ionet::NodeContainerData::MaxNodes
const size_t MaxNodes
Definition: NodeContainer.cpp:54
NodeInteractionResult.h
catapult::ionet::NodeData::Node
ionet::Node Node
Definition: NodeContainer.cpp:40
catapult::ionet::NodeContainerModifier::addConnectionStates
void addConnectionStates(ServiceIdentifier serviceId, ionet::NodeRoles role)
Adds connection states for the service identified by serviceId to all nodes with role.
Definition: NodeContainer.cpp:145
catapult::ionet::ConnectionState
Connection state unique to a node and connection identifier.
Definition: NodeInfo.h:59
catapult::ionet::NodeContainerModifier::m_writeLock
utils::SpinReaderWriterLock::WriterLockGuard m_writeLock
Definition: NodeContainer.h:105
catapult::ionet::FindAllActiveNodes
NodeSet FindAllActiveNodes(const NodeContainerView &view)
Finds all active nodes in view.
Definition: NodeContainer.cpp:263
catapult::ionet::NodeContainer::~NodeContainer
~NodeContainer()
Destroys a node container.
catapult::ionet::Node::identityKey
const Key & identityKey() const
Gets the unique identifier (a public key).
Definition: Node.cpp:60
catapult::ionet::NodeContainerView::getNodeInfo
const NodeInfo & getNodeInfo(const Key &identityKey) const
Gets node info for the node with identityKey.
Definition: NodeContainer.cpp:84
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
catapult::ionet::NodeContainerModifier::m_nodeContainerData
NodeContainerData & m_nodeContainerData
Definition: NodeContainer.h:103
catapult::ionet::NodeContainerModifier::ageConnectionBans
void ageConnectionBans(ServiceIdentifier serviceId, uint32_t maxConnectionBanAge, uint32_t numConsecutiveFailuresBeforeBanning)
Definition: NodeContainer.cpp:171
NodeInfo.h
m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: MemoryPtCache.cpp:258
catapult::ionet::NodeContainerModifier::NodeContainerModifier
NodeContainerModifier(NodeContainerData &nodeContainerData, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Creates a view around nodeContainerData with lock context readLock.
Definition: NodeContainer.cpp:101
catapult::ionet::NodeContainerView::contains
bool contains(const Key &identityKey) const
Returns true if the node with identityKey is in the container, false otherwise.
Definition: NodeContainer.cpp:80
catapult::ionet::NodeInfo
Information about a node and its interactions.
Definition: NodeInfo.h:82
catapult::ionet::NodeContainerModifier::autoProvisionConnectionStates
void autoProvisionConnectionStates(NodeData &nodeData)
Definition: NodeContainer.cpp:189
catapult::supplier
std::function< T()> supplier
A (stateless) supplier function.
Definition: functions.h:39
SpinReaderWriterLock.h
catapult::ionet::NodeContainerView::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: NodeContainer.h:62
catapult::utils::BaseValue< uint64_t, Timestamp_tag >
catapult::ionet::NodeContainer
A collection of nodes.
Definition: NodeContainer.h:109
catapult::ionet::NodeInfo::provisionConnectionState
ConnectionState & provisionConnectionState(ServiceIdentifier serviceId)
Gets connection state for the service identified by serviceId and creates zeroed state if no state ex...
Definition: NodeInfo.cpp:91
catapult::ionet::NodeContainerView::NodeContainerView
NodeContainerView(const NodeContainerData &nodeContainerData, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Creates a view around nodeContainerData with lock context readLock.
Definition: NodeContainer.cpp:65
catapult::ionet::NodeData::NodeData
NodeData(const Node &node, NodeSource source, size_t nodeId)
Definition: NodeContainer.cpp:33
catapult::ionet::NodeContainerModifier::ensureAtLeastOneEmptySlot
bool ensureAtLeastOneEmptySlot()
Definition: NodeContainer.cpp:194
catapult::utils::BasicSpinReaderWriterLock::acquireReader
ReaderLockGuard acquireReader()
Blocks until a reader lock can be acquired.
Definition: SpinReaderWriterLock.h:153
catapult::ionet::NodeContainerView::time
Timestamp time() const
Gets current container time.
Definition: NodeContainer.cpp:76
catapult::ionet::NodeInfo::source
NodeSource source() const
Gets the node source.
Definition: NodeInfo.cpp:47
catapult::utils::BasicSpinReaderWriterLock::WriterLockGuard
A writer lock guard.
Definition: SpinReaderWriterLock.h:83
catapult::ionet::NodeContainerData::ServiceRolesMap
std::vector< std::pair< ServiceIdentifier, ionet::NodeRoles > > ServiceRolesMap
Definition: NodeContainer.cpp:58
catapult::ionet::NodeContainerView
A read only view on top of node container.
Definition: NodeContainer.h:39
catapult::ionet::NodeContainerData::NodeContainerData
NodeContainerData(size_t maxNodes, const supplier< Timestamp > &timeSupplier)
Definition: NodeContainer.cpp:47
catapult::ionet::NodeContainerModifier::ageConnections
void ageConnections(ServiceIdentifier serviceId, const utils::KeySet &identities)
Ages all connections for the service identified by serviceId for nodes with identities.
Definition: NodeContainer.cpp:161
catapult::ionet::NodeContainerModifier::provisionConnectionState
ConnectionState & provisionConnectionState(ServiceIdentifier serviceId, const Key &identityKey)
Gets connection state for the service identified by serviceId and the node with identityKey.
Definition: NodeContainer.cpp:153
HexFormatter.h
catapult::ionet::NodeSet
std::unordered_set< Node, NodeHasher > NodeSet
A set of nodes.
Definition: Node.h:128
catapult::ionet::NodeData::Info
NodeInfo Info
Definition: NodeContainer.cpp:41
m_writeLock
utils::SpinReaderWriterLock::WriterLockGuard m_writeLock
Definition: MemoryPtCache.cpp:259
catapult::ionet::NodeData
Definition: NodeContainer.cpp:31
catapult::ionet::NodeRoles
NodeRoles
A node's role.
Definition: NodeRoles.h:28
Node.h
forwardsValidation.info
def info(*args)
Definition: forwardsValidation.py:12
NodeContainer.h
catapult::utils::KeySet
ArraySet< Key > KeySet
A key set.
Definition: ArraySet.h:64
catapult::ionet::NodeContainerView::m_nodeContainerData
const NodeContainerData & m_nodeContainerData
Definition: NodeContainer.h:61
CATAPULT_THROW_INVALID_ARGUMENT_1
#define CATAPULT_THROW_INVALID_ARGUMENT_1(MESSAGE, PARAM1)
Macro used to throw a catapult invalid argument with a single parameter.
Definition: exceptions.h:183
catapult::ionet::NodeContainerModifier::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: NodeContainer.h:104
catapult::ionet::NodeContainerData::NodeDataContainer
std::unordered_map< Key, NodeData, utils::ArrayHasher< Key > > NodeDataContainer
Definition: NodeContainer.cpp:57
catapult::ionet::NodeContainerModifier::incrementInteraction
void incrementInteraction(const Key &identityKey, const consumer< NodeInfo & > &incrementer)
Definition: NodeContainer.cpp:228
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
catapult::ionet::NodeSource
NodeSource
Definition: NodeInfo.h:47
catapult::ionet::NodeContainerModifier::incrementSuccesses
void incrementSuccesses(const Key &identityKey)
Increments the number of successful interactions for the node identified by identityKey.
Definition: NodeContainer.cpp:179
catapult::ionet::NodeContainer::m_lock
utils::SpinReaderWriterLock m_lock
Definition: NodeContainer.h:129
catapult::ionet::Node::metadata
const NodeMetadata & metadata() const
Gets tne metadata.
Definition: Node.cpp:68
catapult::ionet::NodeMetadata::Roles
NodeRoles Roles
Role(s).
Definition: Node.h:78
catapult::utils::BasicSpinReaderWriterLock::ReaderLockGuard
A reader lock guard.
Definition: SpinReaderWriterLock.h:99
catapult::ionet::NodeContainerModifier::add
bool add(const Node &node, NodeSource source)
Definition: NodeContainer.cpp:109
ArraySet.h
catapult::Timestamp
utils::BaseValue< uint64_t, Timestamp_tag > Timestamp
Definition: src/catapult/types.h:73
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::ionet::NodeContainerView::size
size_t size() const
Returns the number of nodes.
Definition: NodeContainer.cpp:72
catapult::ionet::NodeContainerModifier
A write only view on top of node container.
Definition: NodeContainer.h:66
catapult::utils::ByteArray< Key_Size, Key_tag >
catapult::ionet::NodeContainerData
Definition: NodeContainer.cpp:45
catapult::ionet::NodeContainer::NodeContainer
NodeContainer()
Creates a node container.
Definition: NodeContainer.cpp:240
catapult::ionet::Node
A node in the catapult network.
Definition: Node.h:82
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::ionet::NodeContainerData::TimeSupplier
const supplier< Timestamp > TimeSupplier
Definition: NodeContainer.cpp:55
catapult::ionet::NodeContainerModifier::incrementFailures
void incrementFailures(const Key &identityKey)
Increments the number of failed interactions for the node identified by identityKey.
Definition: NodeContainer.cpp:184
catapult::utils::BasicSpinReaderWriterLock
Definition: SpinReaderWriterLock.h:36
catapult::ionet::NodeContainerData::NextNodeId
size_t NextNodeId
Definition: NodeContainer.cpp:56
catapult::ionet::NodeContainer::m_pImpl
std::unique_ptr< NodeContainerData > m_pImpl
Definition: NodeContainer.h:128
catapult::ionet::NodeContainerView::forEach
void forEach(const consumer< const Node &, const NodeInfo & > &consumer) const
Iterates over all nodes and passes them to consumer.
Definition: NodeContainer.cpp:92