CatapultServer  v0.5.0.1 (Elephant)
NetworkUtils.h
Go to the documentation of this file.
1 
21 #pragma once
28 
29 namespace catapult { namespace extensions {
30 
32  net::ConnectionSettings GetConnectionSettings(const config::CatapultConfiguration& config);
33 
35  void UpdateAsyncTcpServerSettings(net::AsyncTcpServerSettings& settings, const config::CatapultConfiguration& config);
36 
39 
42  template<typename TAcceptor>
43  std::shared_ptr<net::AsyncTcpServer> BootServer(
45  unsigned short port,
46  ionet::ServiceIdentifier serviceId,
47  const config::CatapultConfiguration& config,
48  subscribers::NodeSubscriber& nodeSubscriber,
49  TAcceptor acceptor) {
50  auto endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port);
51  auto settings = net::AsyncTcpServerSettings([acceptor, port, serviceId, &nodeSubscriber](const auto& socketInfo) {
52  acceptor(socketInfo, [port, serviceId, &nodeSubscriber](const auto& connectResult) {
53  CATAPULT_LOG(info) << "accept result to local node port " << port << ": " << connectResult.Code;
54  if (net::PeerConnectCode::Accepted == connectResult.Code)
55  nodeSubscriber.notifyIncomingNode(connectResult.IdentityKey, serviceId);
56  });
57  });
58 
59  UpdateAsyncTcpServerSettings(settings, config);
60  return serviceGroup.pushService(net::CreateAsyncTcpServer, endpoint, settings);
61  }
62 }}
catapult::net::AsyncTcpServerSettings::PacketSocketOptions
ionet::PacketSocketOptions PacketSocketOptions
Packet socket options.
Definition: AsyncTcpServer.h:46
catapult::config::NodeConfiguration::IncomingConnections
IncomingConnectionsSubConfiguration IncomingConnections
Incoming connections configuration.
Definition: NodeConfiguration.h:183
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::net::ConnectionSettings::Timeout
utils::TimeSpan Timeout
Connection timeout.
Definition: ConnectionSettings.h:49
catapult::net::ConnectionSettings::toSocketOptions
ionet::PacketSocketOptions toSocketOptions() const
Gets the packet socket options represented by the configured settings.
Definition: ConnectionSettings.h:68
catapult::extensions::UpdateAsyncTcpServerSettings
void UpdateAsyncTcpServerSettings(net::AsyncTcpServerSettings &settings, const config::CatapultConfiguration &config)
Updates settings with values in config.
Definition: NetworkUtils.cpp:38
catapult::config::CatapultConfiguration::BlockChain
const model::BlockChainConfiguration BlockChain
Block chain configuration.
Definition: CatapultConfiguration.h:48
catapult::net::ConnectionSettings
Settings used to configure connections.
Definition: ConnectionSettings.h:31
catapult::net::ConnectionSettings::IncomingSecurityModes
ionet::ConnectionSecurityMode IncomingSecurityModes
Accepted security modes of incoming connections initiated by other nodes.
Definition: ConnectionSettings.h:64
catapult::net::AsyncTcpServerSettings::MaxPendingConnections
uint16_t MaxPendingConnections
Definition: AsyncTcpServer.h:49
catapult::ionet::NodeRoles::Peer
A peer node.
catapult::thread::MultiServicePool::ServiceGroup::pushService
auto pushService(TFactory factory, TArgs &&... args)
Creates a new service by calling factory with args service arguments.
Definition: MultiServicePool.h:89
catapult::net::AsyncTcpServerSettings::AllowAddressReuse
bool AllowAddressReuse
true if the server should reuse ports already in use.
Definition: AsyncTcpServer.h:55
catapult::config::NodeConfiguration::MaxPacketDataSize
utils::FileSize MaxPacketDataSize
Maximum packet data size.
Definition: NodeConfiguration.h:104
catapult::config::CatapultConfiguration::Node
const NodeConfiguration Node
Node configuration.
Definition: CatapultConfiguration.h:51
catapult::subscribers::NodeSubscriber
Node subscriber.
Definition: NodeSubscriber.h:30
catapult::model::BlockChainConfiguration::Network
NetworkInfo Network
Block chain network.
Definition: BlockChainConfiguration.h:36
catapult::subscribers::NodeSubscriber::notifyIncomingNode
virtual void notifyIncomingNode(const Key &identityKey, ionet::ServiceIdentifier serviceId)=0
Indicates a new incoming connection for node with identityKey connected to serviceId.
catapult::utils::BaseValue
Immutable wrapper for basic types, to provide some type-safety.
Definition: BaseValue.h:100
catapult::config::NodeConfiguration::SocketWorkingBufferSensitivity
uint32_t SocketWorkingBufferSensitivity
Definition: NodeConfiguration.h:101
catapult::thread::MultiServicePool::ServiceGroup
Definition: MultiServicePool.h:56
catapult::net::ConnectionSettings::NetworkIdentifier
model::NetworkIdentifier NetworkIdentifier
Network identifier.
Definition: ConnectionSettings.h:46
catapult::config::NodeConfiguration::ConnectTimeout
utils::TimeSpan ConnectTimeout
Timeout for connecting to a peer.
Definition: NodeConfiguration.h:91
catapult::extensions::GetConnectionSettings
net::ConnectionSettings GetConnectionSettings(const config::CatapultConfiguration &config)
Extracts connection settings from config.
Definition: NetworkUtils.cpp:25
catapult::config::CatapultConfiguration
Comprehensive configuration for a catapult process.
Definition: CatapultConfiguration.h:34
catapult::ionet::NodeRoles
NodeRoles
A node's role.
Definition: NodeRoles.h:28
ConnectionSettings.h
forwardsValidation.info
def info(*args)
Definition: forwardsValidation.py:12
catapult::extensions::GetMaxIncomingConnectionsPerIdentity
uint32_t GetMaxIncomingConnectionsPerIdentity(ionet::NodeRoles roles)
Gets the maximum number of incoming connections per identity as specified by roles.
Definition: NetworkUtils.cpp:47
MultiServicePool.h
AsyncTcpServer.h
NodeSubscriber.h
catapult::ionet::NodeRoles::Api
An api node.
CatapultConfiguration.h
catapult::net::CreateAsyncTcpServer
std::shared_ptr< AsyncTcpServer > CreateAsyncTcpServer(const std::shared_ptr< thread::IoThreadPool > &pPool, const boost::asio::ip::tcp::endpoint &endpoint, const AsyncTcpServerSettings &settings)
Definition: AsyncTcpServer.cpp:217
catapult::config::NodeConfiguration::IncomingSecurityModes
ionet::ConnectionSecurityMode IncomingSecurityModes
Accepted security modes of incoming connections initiated by other nodes.
Definition: NodeConfiguration.h:128
NetworkUtils.h
catapult::extensions::BootServer
std::shared_ptr< net::AsyncTcpServer > BootServer(thread::MultiServicePool::ServiceGroup &serviceGroup, unsigned short port, ionet::ServiceIdentifier serviceId, const config::CatapultConfiguration &config, subscribers::NodeSubscriber &nodeSubscriber, TAcceptor acceptor)
Definition: NetworkUtils.h:43
catapult::net::ConnectionSettings::SocketWorkingBufferSensitivity
size_t SocketWorkingBufferSensitivity
Socket working buffer sensitivity.
Definition: ConnectionSettings.h:55
catapult::config::NodeConfiguration::ShouldAllowAddressReuse
bool ShouldAllowAddressReuse
true if the server should reuse ports already in use.
Definition: NodeConfiguration.h:42
PeerConnectResult.h
catapult::net::ConnectionSettings::SocketWorkingBufferSize
utils::FileSize SocketWorkingBufferSize
Socket working buffer size.
Definition: ConnectionSettings.h:52
catapult::net::AsyncTcpServerSettings::MaxActiveConnections
uint32_t MaxActiveConnections
Definition: AsyncTcpServer.h:52
catapult::net::AsyncTcpServerSettings
Settings used to configure AsyncTcpServer behavior.
Definition: AsyncTcpServer.h:33
catapult::config::NodeConfiguration::OutgoingSecurityMode
ionet::ConnectionSecurityMode OutgoingSecurityMode
Security mode of outgoing connections initiated by this node.
Definition: NodeConfiguration.h:125
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::net::ConnectionSettings::OutgoingSecurityMode
ionet::ConnectionSecurityMode OutgoingSecurityMode
Security mode of outgoing connections initiated by this node.
Definition: ConnectionSettings.h:61
catapult::net::ConnectionSettings::MaxPacketDataSize
utils::FileSize MaxPacketDataSize
Maximum packet data size.
Definition: ConnectionSettings.h:58
catapult::config::NodeConfiguration::SocketWorkingBufferSize
utils::FileSize SocketWorkingBufferSize
Initial socket working buffer size (socket reads will attempt to read buffers of roughly this size).
Definition: NodeConfiguration.h:97
catapult::model::NetworkInfo::Identifier
NetworkIdentifier Identifier
Network identifier.
Definition: NetworkInfo.h:70