CatapultServer  v0.5.0.1 (Elephant)
PeersConnectionTasks.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "NodeSelector.h"
25 #include "catapult/thread/Task.h"
26 #include <vector>
27 
28 namespace catapult {
29  namespace cache { class CatapultCache; }
30  namespace net {
31  class ConnectionContainer;
32  class PacketWriters;
33  }
34 }
35 
36 namespace catapult { namespace extensions {
37 
38  // region NodeAger
39 
40  // A node ager.
42 
45  ionet::ServiceIdentifier serviceId,
47  ionet::NodeContainer& nodes);
48 
49  // endregion
50 
51  // region SelectorSettings
52 
55  public:
58  const cache::CatapultCache& cache,
59  Importance totalChainImportance,
60  ionet::NodeContainer& nodes,
61  ionet::ServiceIdentifier serviceId,
62  ionet::NodeRoles requiredRole,
64 
67  const cache::CatapultCache& cache,
68  Importance totalChainImportance,
69  ionet::NodeContainer& nodes,
70  ionet::ServiceIdentifier serviceId,
72 
73  public:
76 
79 
82 
85 
88  };
89 
90  // endregion
91 
92  // region NodeSelector / ConnectPeersTask
93 
96 
101 
104 
108  thread::Task CreateConnectPeersTask(const SelectorSettings& settings, net::PacketWriters& packetWriters, const NodeSelector& selector);
109 
110  // endregion
111 
112  // region RemoveOnlyNodeSelector / AgePeersTask
113 
116 
120 
122  thread::Task CreateAgePeersTask(const SelectorSettings& settings, net::ConnectionContainer& connectionContainer);
123 
127  const SelectorSettings& settings,
128  net::ConnectionContainer& connectionContainer,
129  const RemoveOnlyNodeSelector& selector);
130 
131  // endregion
132 }}
FutureUtils.h
catapult::extensions::SelectorSettings::SelectorSettings
SelectorSettings(const cache::CatapultCache &cache, Importance totalChainImportance, ionet::NodeContainer &nodes, ionet::ServiceIdentifier serviceId, ionet::NodeRoles requiredRole, const config::NodeConfiguration::ConnectionsSubConfiguration &config)
Creates settings around cache, totalChainImportance, nodes, serviceId, requiredRole and config.
Definition: PeersConnectionTasks.cpp:50
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
ServiceId
ionet::ServiceIdentifier ServiceId
Definition: PeersConnectionTasks.cpp:106
NodeInteractionResult.h
catapult::net::PacketWriters
Manages a collection of connections that send data to external nodes.
Definition: PacketWriters.h:41
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
m_state
AddState m_state
Definition: PeersConnectionTasks.cpp:166
Parser.debug
def debug(*args)
Definition: Parser.py:46
catapult::ionet::ServiceIdentifier
utils::BaseValue< uint32_t, ServiceIdentifier_tag > ServiceIdentifier
Definition: NodeInfo.h:56
catapult::net::PeerConnectCode
PeerConnectCode
Enumeration of possible peer connection codes.
Definition: PeerConnectCode.h:44
catapult::extensions::SelectorSettings::Nodes
ionet::NodeContainer & Nodes
Container of nodes from which to select.
Definition: PeersConnectionTasks.h:75
Task.h
catapult::extensions::SelectNodes
NodeSelectionResult SelectNodes(const ionet::NodeContainer &nodes, const NodeSelectionConfiguration &config, const ImportanceRetriever &importanceRetriever)
Definition: NodeSelector.cpp:175
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
catapult::extensions::NodeSelectionConfiguration
Node selection configuration.
Definition: NodeSelector.h:84
PacketWriters.h
catapult::extensions::NodeAgingConfiguration
Node aging configuration.
Definition: NodeSelector.h:72
catapult::config::NodeConfiguration::ConnectionsSubConfiguration::MaxConnections
uint16_t MaxConnections
Maximum number of active connections.
Definition: NodeConfiguration.h:160
catapult::ionet::ConnectResult
ConnectResult
Enumeration of possible connection results.
Definition: ConnectResult.h:41
catapult::extensions::CreateConnectPeersTask
thread::Task CreateConnectPeersTask(const SelectorSettings &settings, net::PacketWriters &packetWriters)
Creates a task for the specified service that connects to nodes with the specified role given setting...
Definition: PeersConnectionTasks.cpp:186
catapult::extensions::NodeAger
consumer< const utils::KeySet & > NodeAger
Definition: PeersConnectionTasks.h:41
catapult::extensions::RemoveOnlyNodeSelector
supplier< utils::KeySet > RemoveOnlyNodeSelector
A remove-only node selector.
Definition: PeersConnectionTasks.h:115
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
Immutable wrapper for basic types, to provide some type-safety.
Definition: BaseValue.h:100
catapult::ionet::NodeContainer
A collection of nodes.
Definition: NodeContainer.h:109
catapult::config::NodeConfiguration::ConnectionsSubConfiguration::MaxConnectionAge
uint16_t MaxConnectionAge
Maximum connection age.
Definition: NodeConfiguration.h:163
catapult::thread::when_all
future< std::vector< future< T > > > when_all(std::vector< future< T >> &&allFutures)
Returns a future that is signaled when all futures in allFutures complete.
Definition: FutureUtils.h:31
catapult::utils::LogLevel::Info
Level for logging informational events.
catapult::extensions::ImportanceRetriever
std::function< ImportanceDescriptor(const Key &)> ImportanceRetriever
Retrieves an importance descriptor given a specified public key.
Definition: NodeSelector.h:41
catapult::extensions::CreateNodeSelector
NodeSelector CreateNodeSelector(const SelectorSettings &settings)
Definition: PeersConnectionTasks.cpp:170
PacketWriters
net::PacketWriters & PacketWriters
Definition: PeersConnectionTasks.cpp:105
PeersConnectionTasks.h
catapult::config::NodeConfiguration::ConnectionsSubConfiguration::NumConsecutiveFailuresBeforeBanning
uint16_t NumConsecutiveFailuresBeforeBanning
Number of consecutive connection failures before a connection is banned.
Definition: NodeConfiguration.h:169
catapult::thread::CreateNamedTask
Task CreateNamedTask(const std::string &name, const TaskCallback &callback)
Creates an unscheduled task with name and callback.
Definition: Task.cpp:52
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::NodeSet
std::unordered_set< Node, NodeHasher > NodeSet
A set of nodes.
Definition: Node.h:128
catapult::extensions::SelectorSettings::ServiceId
ionet::ServiceIdentifier ServiceId
Service identifier for selection.
Definition: PeersConnectionTasks.h:78
catapult::config::NodeConfiguration::ConnectionsSubConfiguration::MaxConnectionBanAge
uint16_t MaxConnectionBanAge
Maximum connection ban age.
Definition: NodeConfiguration.h:166
NodeConfiguration.h
catapult::net::ConnectionContainer::closeOne
virtual bool closeOne(const Key &identityKey)=0
Closes any active connections to the node identified by identityKey.
catapult::utils::LogLevel
LogLevel
Catapult log levels.
Definition: Logging.h:36
catapult::ionet::NodeRoles
NodeRoles
A node's role.
Definition: NodeRoles.h:28
catapult::extensions::NodeSelector
supplier< NodeSelectionResult > NodeSelector
A node selector.
Definition: PeersConnectionTasks.h:95
catapult::thread::TaskResult::Continue
Task should repeat.
NodeContainer.h
catapult::cache::CatapultCache
Central cache holding all sub caches.
Definition: CatapultCache.h:40
catapult::extensions::SelectorSettings
Settings used to initialize a selector task.
Definition: PeersConnectionTasks.h:54
catapult::extensions::CreateAgePeersTask
thread::Task CreateAgePeersTask(const SelectorSettings &settings, net::ConnectionContainer &connectionContainer)
Creates a task for the specified service that ages nodes given settings and connectionContainer.
Definition: PeersConnectionTasks.cpp:230
catapult::extensions::ImportanceDescriptor
Describes an importance value.
Definition: NodeSelector.h:32
catapult::extensions::SelectorSettings::Config
config::NodeConfiguration::ConnectionsSubConfiguration Config
Connections configuration.
Definition: PeersConnectionTasks.h:84
CatapultCache.h
CATAPULT_LOG_LEVEL
#define CATAPULT_LOG_LEVEL(LEVEL)
Writes a log entry to the default logger with LEVEL severity.
Definition: Logging.h:336
NodeSelector.h
catapult::thread::make_ready_future
future< T > make_ready_future(T &&value)
Produces a future that is ready immediately and holds the given value.
Definition: Future.h:126
AccountStateCache.h
catapult::cache::AccountStateCache
Synchronized cache composed of stateful account information.
Definition: AccountStateCache.h:72
catapult::net::ConnectionContainer
Manages a collection of connections.
Definition: ConnectionContainer.h:27
catapult::cache::CatapultCacheView::sub
const TCache::CacheViewType & sub() const
Gets a specific sub cache view.
Definition: CatapultCacheView.h:52
catapult::extensions::CreateNodeAger
NodeAger CreateNodeAger(ionet::ServiceIdentifier serviceId, const config::NodeConfiguration::ConnectionsSubConfiguration &config, ionet::NodeContainer &nodes)
Creates and prepares a node ager that ages all serviceId connections in nodes given config.
Definition: PeersConnectionTasks.cpp:34
Nodes
ionet::NodeContainer & Nodes
Definition: PeersConnectionTasks.cpp:104
catapult::cache::CatapultCache::createView
CatapultCacheView createView() const
Returns a locked cache view based on this cache.
Definition: CatapultCache.cpp:246
catapult::config::NodeConfiguration::ConnectionsSubConfiguration
Connections configuration.
Definition: NodeConfiguration.h:158
catapult::extensions::SelectorSettings::RequiredRole
ionet::NodeRoles RequiredRole
Required role for selection (if applicable).
Definition: PeersConnectionTasks.h:81
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::extensions::SelectorSettings::ImportanceRetriever
extensions::ImportanceRetriever ImportanceRetriever
Retrieves an account importance given a public key.
Definition: PeersConnectionTasks.h:87
catapult::validators::MapToLogLevel
constexpr utils::LogLevel MapToLogLevel(ValidationResult result)
Maps validation result to an appropriate logging level.
Definition: ValidationResult.h:100
Logging.h
catapult::extensions::CreateAgePeersTask
thread::Task CreateAgePeersTask(const SelectorSettings &settings, net::ConnectionContainer &connectionContainer, const RemoveOnlyNodeSelector &selector)
Definition: PeersConnectionTasks.cpp:235
ImportanceView.h
catapult::cache::ReadOnlyAccountStateCache
A read-only overlay on top of an account cache.
Definition: ReadOnlyAccountStateCache.h:36
catapult::extensions::CreateRemoveOnlyNodeSelector
RemoveOnlyNodeSelector CreateRemoveOnlyNodeSelector(const SelectorSettings &settings)
Definition: PeersConnectionTasks.cpp:218
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::thread::Task
A task that can be dispatched to the scheduler.
Definition: Task.h:45
catapult::utils::LogLevel::Warning
Level for logging warning events.
catapult::cache::ImportanceView
A view on top of an account state cache for retrieving importances.
Definition: ImportanceView.h:29
catapult::cache::ImportanceView::getAccountImportanceOrDefault
Importance getAccountImportanceOrDefault(const Key &publicKey, Height height) const
Gets the importance for publicKey at height or a default importance if no importance is set.
Definition: ImportanceView.cpp:76
catapult::net::ConnectionContainer::identities
virtual utils::KeySet identities() const =0
Gets the identities of active connections.