CatapultServer  v0.5.0.1 (Elephant)
catapult::ionet Namespace Reference

Namespaces

 detail
 
 operation_state
 

Classes

class  AcceptedPacketSocketInfo
 Result of a packet socket accept operation. More...
 
class  AppendContext
 
class  BatchPacketReader
 An read-optimized interface for reading packets. More...
 
struct  ConnectionState
 Connection state unique to a node and connection identifier. More...
 
struct  NetworkNode
 Information about a catapult node that is propagated through the network. More...
 
class  Node
 A node in the catapult network. More...
 
class  NodeContainer
 A collection of nodes. More...
 
struct  NodeContainerData
 
class  NodeContainerModifier
 A write only view on top of node container. More...
 
class  NodeContainerView
 A read only view on top of node container. More...
 
struct  NodeData
 
struct  NodeEndpoint
 A node's publicly accessible endpoint. More...
 
struct  NodeHasher
 Hasher object for a node. More...
 
struct  NodeInfo
 Information about a node and its interactions. More...
 
struct  NodeInteractionResult
 Result from a node interaction. More...
 
struct  NodeInteractions
 Node interactions. More...
 
class  NodeInteractionsContainer
 Node interactions container. More...
 
struct  NodeMetadata
 Additional node information. More...
 
class  NodePacketIoPair
 A node and packet io pair. More...
 
struct  NodeVersion_tag
 
struct  PackedConnectionState
 Connection state unique to a node and connection identifier. More...
 
struct  PackedNodeInfo
 Information about a node and its interactions. More...
 
struct  PackedNodeInteractions
 Node interactions. More...
 
struct  Packet
 A packet header with a data payload. More...
 
class  PacketExtractor
 Helper for extracting a packet from a working buffer. More...
 
struct  PacketHeader
 A packet header that all transferable information is expected to have. More...
 
class  PacketIo
 An interface for reading and writing packets. More...
 
class  PacketPayload
 A packet payload that can be written. More...
 
class  PacketPayloadBuilder
 A packet payload builder for creating payloads composed of heterogeneous data. More...
 
class  PacketPayloadFactory
 A factory for creating common packet payloads. More...
 
class  PacketReader
 
class  PacketSocket
 
struct  PacketSocketOptions
 Packet socket options. More...
 
struct  ReaderIdentity
 Identifying information about a reader. More...
 
struct  ServerPacketHandlerContext
 Context passed to a server packet handler function. More...
 
class  ServerPacketHandlers
 A collection of packet handlers where there is at most one handler per packet type. More...
 
struct  ServiceIdentifier_tag
 
class  SocketReader
 Reads and consumes packets from a socket. More...
 
class  WorkingBuffer
 A buffer for storing working data. More...
 

Typedefs

using ByteBuffer = std::vector< uint8_t >
 
using socket = boost::asio::ip::tcp::socket
 
using NodeVersion = utils::BaseValue< uint32_t, NodeVersion_tag >
 32-bit node version where first three bytes represent { major, minor, build } and last byte is user defined. More...
 
using NodeSet = std::unordered_set< Node, NodeHasher >
 A set of nodes. More...
 
using ServiceIdentifier = utils::BaseValue< uint32_t, ServiceIdentifier_tag >
 
using ConfigureSocketCallback = consumer< socket & >
 Callback for configuring a socket before initiating an accept. More...
 
using AcceptCallback = consumer< const AcceptedPacketSocketInfo & >
 Callback for an accepted socket. More...
 
using ConnectCallback = consumer< ConnectResult, const std::shared_ptr< PacketSocket > & >
 Callback for a connected socket. More...
 

Enumerations

enum  ConnectionSecurityMode : uint8_t { ConnectionSecurityMode::CONNECTION_SECURITY_MODE_LIST }
 Possible connection security modes. More...
 
enum  ConnectResult { ConnectResult::CONNECT_RESULT_LIST }
 Enumeration of possible connection results. More...
 
enum  NodeSource : uint32_t { NodeSource::NODE_SOURCE_LIST }
 
enum  NodeInteractionResultCode { NodeInteractionResultCode::NODE_INTERACTION_RESULT_CODE_LIST }
 Possible node interaction result codes. More...
 
enum  NodeRoles : uint32_t { NodeRoles::None, NodeRoles::Peer = 0x01, NodeRoles::Api = 0x02 }
 A node's role. More...
 
enum  PacketExtractResult { PacketExtractResult::PACKET_EXTRACT_RESULT_LIST }
 Possible results from PacketExtractor::tryExtractNextPacket. More...
 
enum  PacketType : uint32_t { PacketType::PACKET_TYPE_LIST }
 An enumeration of known packet types. More...
 
enum  SocketOperationCode { SocketOperationCode::SOCKET_OPERATION_CODE_LIST }
 Enumeration of socket operation results. More...
 

Functions

PacketPayload CreateBroadcastPayload (const std::shared_ptr< const model::Block > &pBlock)
 Creates a payload around pBlock for broadcasting. More...
 
PacketPayload CreateBroadcastPayload (const std::vector< model::TransactionInfo > &transactionInfos)
 Creates a payload around transactionInfos for broadcasting. More...
 
PacketPayload CreateBroadcastPayload (const std::vector< model::TransactionInfo > &transactionInfos, PacketType packetType)
 Creates a payload around transactionInfos for broadcasting using packetType. More...
 
PacketPayload CreateBroadcastPayload (const std::vector< model::DetachedCosignature > &cosignatures)
 Creates a payload around cosignatures for broadcasting. More...
 
std::shared_ptr< PacketIoCreateBufferedPacketIo (const std::shared_ptr< PacketIo > &pIo, boost::asio::io_context::strand &strand)
 Adds buffering to pIo using strand for synchronization. More...
 
std::ostream & operator<< (std::ostream &out, ConnectionSecurityMode value)
 Insertion operator for outputting value to out. More...
 
bool TryParseValue (const std::string &str, ConnectionSecurityMode &modes)
 Tries to parse str into connection security modes. More...
 
std::ostream & operator<< (std::ostream &out, ConnectResult value)
 Insertion operator for outputting value to out. More...
 
std::unique_ptr< NetworkNodePackNode (const Node &node)
 Packs a node model into a network node. More...
 
Node UnpackNode (const NetworkNode &networkNode)
 Unpacks a network node (networkNode) into a node model. More...
 
std::ostream & operator<< (std::ostream &out, const Node &node)
 
NodeSet FindAllActiveNodes (const NodeContainerView &view)
 Finds all active nodes in view. More...
 
std::ostream & operator<< (std::ostream &out, NodeSource value)
 Insertion operator for outputting value to out. More...
 
std::ostream & operator<< (std::ostream &out, NodeInteractionResultCode value)
 Insertion operator for outputting value to out. More...
 
bool TryParseValue (const std::string &str, NodeRoles &roles)
 Tries to parse str into node roles. More...
 
template<typename TPacket >
std::shared_ptr< TPacket > CreateSharedPacket (uint32_t payloadSize=0)
 Creates a packet of the specified type (TPacket) with the specified payload size. More...
 
template<>
std::shared_ptr< PacketCreateSharedPacket (uint32_t payloadSize)
 
template<typename TPacket >
const TPacket * CoercePacket (const Packet *pPacket)
 Coerces pPacket to the desired packet type or nullptr if it is incompatible. More...
 
constexpr bool IsPacketValid (const Packet &packet, PacketType type)
 Checks if packet is valid with type. More...
 
size_t CalculatePacketDataSize (const Packet &packet)
 Calculates the data size of packet. More...
 
template<typename TEntity >
bool IsSizeValid (const TEntity &entity)
 Checks the real size of entity against its reported size and returns true if the sizes match. More...
 
template<typename TEntity , typename TIsValidPredicate >
model::EntityRange< TEntity > ExtractEntitiesFromPacket (const Packet &packet, TIsValidPredicate isValid)
 
template<typename TEntity , typename TIsValidPredicate >
std::unique_ptr< TEntity > ExtractEntityFromPacket (const Packet &packet, TIsValidPredicate isValid)
 
template<typename TStructure >
model::EntityRange< TStructure > ExtractFixedSizeStructuresFromPacket (const Packet &packet)
 
std::ostream & operator<< (std::ostream &out, PacketExtractResult value)
 Insertion operator for outputting value to out. More...
 
std::ostream & operator<< (std::ostream &out, const PacketHeader &header)
 Insertion operator for outputting header to out. More...
 
constexpr bool IsPacketDataSizeValid (const PacketHeader &header, size_t maxPacketDataSize)
 Determines if header indicates a valid packet data size no greater than maxPacketDataSize. More...
 
template<typename TEntity , typename TIsValidPredicate >
std::vector< size_t > ExtractEntityOffsets (const RawBuffer &buffer, TIsValidPredicate isValid)
 
template<typename TEntity , typename TIsValidPredicate >
bool ContainsSingleEntity (const RawBuffer &buffer, TIsValidPredicate isValid)
 
template<typename TStructure >
size_t CountFixedSizeStructures (const RawBuffer &buffer)
 
void Accept (boost::asio::ip::tcp::acceptor &acceptor, const PacketSocketOptions &options, const ConfigureSocketCallback &configureSocket, const AcceptCallback &accept)
 
void Accept (boost::asio::ip::tcp::acceptor &acceptor, const PacketSocketOptions &options, const AcceptCallback &accept)
 Accepts a connection using acceptor and calls accept on completion configuring the socket with options. More...
 
action Connect (boost::asio::io_context &ioContext, const PacketSocketOptions &options, const NodeEndpoint &endpoint, const ConnectCallback &callback)
 
std::ostream & operator<< (std::ostream &out, PacketType value)
 Insertion operator for outputting value to out. More...
 
std::ostream & operator<< (std::ostream &out, const ReaderIdentity &identity)
 Insertion operator for outputting identity to out. More...
 
std::shared_ptr< PacketSocketSecure (const std::shared_ptr< PacketSocket > &pSocket, ConnectionSecurityMode securityMode, const crypto::KeyPair &sourceKeyPair, const Key &remoteKey, utils::FileSize maxPacketDataSize)
 
std::shared_ptr< PacketIoCreateSecureSignedPacketIo (const std::shared_ptr< PacketIo > &pIo, const crypto::KeyPair &sourceKeyPair, const Key &remoteKey, uint32_t maxSignedPacketDataSize)
 
std::shared_ptr< BatchPacketReaderCreateSecureSignedBatchPacketReader (const std::shared_ptr< BatchPacketReader > &pReader, const Key &remoteKey)
 
std::ostream & operator<< (std::ostream &out, SocketOperationCode value)
 Insertion operator for outputting value to out. More...
 
std::unique_ptr< SocketReaderCreateSocketReader (const std::shared_ptr< BatchPacketReader > &pReader, const std::shared_ptr< PacketIo > &pWriter, const ServerPacketHandlers &handlers, const ReaderIdentity &identity)
 Creates a socket packet reader around pReader, pWriter and handlers given a reader identity. More...
 

Typedef Documentation

◆ AcceptCallback

Callback for an accepted socket.

◆ ByteBuffer

using catapult::ionet::ByteBuffer = typedef std::vector<uint8_t>

◆ ConfigureSocketCallback

Callback for configuring a socket before initiating an accept.

◆ ConnectCallback

using catapult::ionet::ConnectCallback = typedef consumer<ConnectResult, const std::shared_ptr<PacketSocket>&>

Callback for a connected socket.

◆ NodeSet

using catapult::ionet::NodeSet = typedef std::unordered_set<Node, NodeHasher>

A set of nodes.

◆ NodeVersion

32-bit node version where first three bytes represent { major, minor, build } and last byte is user defined.

◆ ServiceIdentifier

◆ socket

using catapult::ionet::socket = typedef boost::asio::ip::tcp::socket

Enumeration Type Documentation

◆ ConnectionSecurityMode

Possible connection security modes.

Enumerator
CONNECTION_SECURITY_MODE_LIST 

◆ ConnectResult

Enumeration of possible connection results.

Enumerator
CONNECT_RESULT_LIST 

◆ NodeInteractionResultCode

Possible node interaction result codes.

Enumerator
NODE_INTERACTION_RESULT_CODE_LIST 

◆ NodeRoles

enum catapult::ionet::NodeRoles : uint32_t
strong

A node's role.

Enumerator
None 

No roles.

Peer 

A peer node.

Api 

An api node.

◆ NodeSource

enum catapult::ionet::NodeSource : uint32_t
strong

Source of a node.

Note
Higher value sources correspond to higher levels of trust.
Enumerator
NODE_SOURCE_LIST 

◆ PacketExtractResult

Possible results from PacketExtractor::tryExtractNextPacket.

Enumerator
PACKET_EXTRACT_RESULT_LIST 

◆ PacketType

enum catapult::ionet::PacketType : uint32_t
strong

An enumeration of known packet types.

Enumerator
PACKET_TYPE_LIST 

◆ SocketOperationCode

Enumeration of socket operation results.

Enumerator
SOCKET_OPERATION_CODE_LIST 

Function Documentation

◆ Accept() [1/2]

void catapult::ionet::Accept ( boost::asio::ip::tcp::acceptor &  acceptor,
const PacketSocketOptions options,
const AcceptCallback accept 
)

Accepts a connection using acceptor and calls accept on completion configuring the socket with options.

Here is the call graph for this function:

◆ Accept() [2/2]

void catapult::ionet::Accept ( boost::asio::ip::tcp::acceptor &  acceptor,
const PacketSocketOptions options,
const ConfigureSocketCallback configureSocket,
const AcceptCallback accept 
)

Accepts a connection using acceptor and calls accept on completion configuring the socket with options. configureSocket is called before starting the accept to allow custom configuration of asio sockets.

Note
User callbacks passed to the accepted socket are serialized.
Here is the caller graph for this function:

◆ CalculatePacketDataSize()

size_t catapult::ionet::CalculatePacketDataSize ( const Packet packet)
inline

Calculates the data size of packet.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CoercePacket()

template<typename TPacket >
const TPacket* catapult::ionet::CoercePacket ( const Packet pPacket)

Coerces pPacket to the desired packet type or nullptr if it is incompatible.

◆ Connect()

action catapult::ionet::Connect ( boost::asio::io_context &  ioContext,
const PacketSocketOptions options,
const NodeEndpoint endpoint,
const ConnectCallback callback 
)

Attempts to connect a socket to the specified endpoint using ioContext and calls callback on completion configuring the socket with options. The returned function can be used to cancel the connect.

Note
User callbacks passed to the connected socket are serialized.

◆ ContainsSingleEntity()

template<typename TEntity , typename TIsValidPredicate >
bool catapult::ionet::ContainsSingleEntity ( const RawBuffer &  buffer,
TIsValidPredicate  isValid 
)

Determines if buffer contains a single entity with a validity check (isValid).

Note
If the buffer is invalid and/or contains partial or multiple entities, false will be returned.
Here is the call graph for this function:

◆ CountFixedSizeStructures()

template<typename TStructure >
size_t catapult::ionet::CountFixedSizeStructures ( const RawBuffer &  buffer)

Counts the number of fixed size structures in buffer.

Note
If the buffer is invalid and/or contains partial structures, 0 will be returned.

◆ CreateBroadcastPayload() [1/4]

PacketPayload catapult::ionet::CreateBroadcastPayload ( const std::shared_ptr< const model::Block > &  pBlock)

Creates a payload around pBlock for broadcasting.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateBroadcastPayload() [2/4]

PacketPayload catapult::ionet::CreateBroadcastPayload ( const std::vector< model::DetachedCosignature > &  cosignatures)

Creates a payload around cosignatures for broadcasting.

Here is the call graph for this function:

◆ CreateBroadcastPayload() [3/4]

PacketPayload catapult::ionet::CreateBroadcastPayload ( const std::vector< model::TransactionInfo > &  transactionInfos)

Creates a payload around transactionInfos for broadcasting.

Here is the call graph for this function:

◆ CreateBroadcastPayload() [4/4]

PacketPayload catapult::ionet::CreateBroadcastPayload ( const std::vector< model::TransactionInfo > &  transactionInfos,
PacketType  packetType 
)

Creates a payload around transactionInfos for broadcasting using packetType.

Here is the call graph for this function:

◆ CreateBufferedPacketIo()

std::shared_ptr< PacketIo > catapult::ionet::CreateBufferedPacketIo ( const std::shared_ptr< PacketIo > &  pIo,
boost::asio::io_context::strand &  strand 
)

Adds buffering to pIo using strand for synchronization.

Here is the caller graph for this function:

◆ CreateSecureSignedBatchPacketReader()

std::shared_ptr< BatchPacketReader > catapult::ionet::CreateSecureSignedBatchPacketReader ( const std::shared_ptr< BatchPacketReader > &  pReader,
const Key remoteKey 
)

Adds secure signing to all packets read from pReader.

  • All read packets are validated to be signed by remoteKey.

◆ CreateSecureSignedPacketIo()

std::shared_ptr< PacketIo > catapult::ionet::CreateSecureSignedPacketIo ( const std::shared_ptr< PacketIo > &  pIo,
const crypto::KeyPair sourceKeyPair,
const Key remoteKey,
uint32_t  maxSignedPacketDataSize 
)

Adds secure signing to all packets read from and written to pIo.

  • All written packets are wrapped in a signature packet, signed by sourceKeyPair and must have a max packet data size of maxSignedPacketDataSize.
  • All read packets are validated to be signed by remoteKey.

◆ CreateSharedPacket() [1/2]

template<>
std::shared_ptr<Packet> catapult::ionet::CreateSharedPacket ( uint32_t  payloadSize)
inline

◆ CreateSharedPacket() [2/2]

template<typename TPacket >
std::shared_ptr<TPacket> catapult::ionet::CreateSharedPacket ( uint32_t  payloadSize = 0)

Creates a packet of the specified type (TPacket) with the specified payload size.

◆ CreateSocketReader()

std::unique_ptr< SocketReader > catapult::ionet::CreateSocketReader ( const std::shared_ptr< BatchPacketReader > &  pReader,
const std::shared_ptr< PacketIo > &  pWriter,
const ServerPacketHandlers handlers,
const ReaderIdentity identity 
)

Creates a socket packet reader around pReader, pWriter and handlers given a reader identity.

◆ ExtractEntitiesFromPacket()

template<typename TEntity , typename TIsValidPredicate >
model::EntityRange<TEntity> catapult::ionet::ExtractEntitiesFromPacket ( const Packet packet,
TIsValidPredicate  isValid 
)

Extracts entities from packet with a validity check (isValid).

Note
If the packet is invalid and/or contains partial entities, the returned range will be empty.
Here is the call graph for this function:

◆ ExtractEntityFromPacket()

template<typename TEntity , typename TIsValidPredicate >
std::unique_ptr<TEntity> catapult::ionet::ExtractEntityFromPacket ( const Packet packet,
TIsValidPredicate  isValid 
)

Extracts a single entity from packet with a validity check (isValid).

Note
If the packet is invalid and/or contains partial or multiple entities, nullptr will be returned.
Here is the call graph for this function:

◆ ExtractEntityOffsets()

template<typename TEntity , typename TIsValidPredicate >
std::vector<size_t> catapult::ionet::ExtractEntityOffsets ( const RawBuffer &  buffer,
TIsValidPredicate  isValid 
)

Extracts entity offsets from buffer with a validity check (isValid).

Note
If the buffer is invalid and/or contains partial entities, the returned vector will be empty.
Here is the call graph for this function:

◆ ExtractFixedSizeStructuresFromPacket()

template<typename TStructure >
model::EntityRange<TStructure> catapult::ionet::ExtractFixedSizeStructuresFromPacket ( const Packet packet)

Extracts fixed size structures from packet.

Note
If the packet is invalid and/or contains partial structures, the returned range will be empty.
Here is the call graph for this function:

◆ FindAllActiveNodes()

NodeSet catapult::ionet::FindAllActiveNodes ( const NodeContainerView view)

Finds all active nodes in view.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsPacketDataSizeValid()

constexpr bool catapult::ionet::IsPacketDataSizeValid ( const PacketHeader header,
size_t  maxPacketDataSize 
)
constexpr

Determines if header indicates a valid packet data size no greater than maxPacketDataSize.

Here is the caller graph for this function:

◆ IsPacketValid()

constexpr bool catapult::ionet::IsPacketValid ( const Packet packet,
PacketType  type 
)
constexpr

Checks if packet is valid with type.

Here is the caller graph for this function:

◆ IsSizeValid()

template<typename TEntity >
bool catapult::ionet::IsSizeValid ( const TEntity &  entity)

Checks the real size of entity against its reported size and returns true if the sizes match.

◆ operator<<() [1/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
ConnectionSecurityMode  value 
)

Insertion operator for outputting value to out.

◆ operator<<() [2/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
ConnectResult  value 
)

Insertion operator for outputting value to out.

◆ operator<<() [3/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
const Node node 
)

◆ operator<<() [4/10]

std::ostream & catapult::ionet::operator<< ( std::ostream &  out,
const PacketHeader header 
)

Insertion operator for outputting header to out.

◆ operator<<() [5/10]

std::ostream & catapult::ionet::operator<< ( std::ostream &  out,
const ReaderIdentity identity 
)

Insertion operator for outputting identity to out.

◆ operator<<() [6/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
NodeInteractionResultCode  value 
)

Insertion operator for outputting value to out.

◆ operator<<() [7/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
NodeSource  value 
)

Insertion operator for outputting value to out.

◆ operator<<() [8/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
PacketExtractResult  value 
)

Insertion operator for outputting value to out.

◆ operator<<() [9/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
PacketType  value 
)

Insertion operator for outputting value to out.

◆ operator<<() [10/10]

std::ostream& catapult::ionet::operator<< ( std::ostream &  out,
SocketOperationCode  value 
)

Insertion operator for outputting value to out.

◆ PackNode()

std::unique_ptr< NetworkNode > catapult::ionet::PackNode ( const Node node)

Packs a node model into a network node.

Here is the call graph for this function:

◆ Secure()

std::shared_ptr< PacketSocket > catapult::ionet::Secure ( const std::shared_ptr< PacketSocket > &  pSocket,
ConnectionSecurityMode  securityMode,
const crypto::KeyPair sourceKeyPair,
const Key remoteKey,
utils::FileSize  maxPacketDataSize 
)

Secures a packet socket (pSocket) to conform with securityMode for a connection from sourceKeyPair to remoteKey allowing a specified max packet data size (maxPacketDataSize).

Here is the call graph for this function:

◆ TryParseValue() [1/2]

bool catapult::ionet::TryParseValue ( const std::string &  str,
ConnectionSecurityMode modes 
)

Tries to parse str into connection security modes.

Here is the call graph for this function:

◆ TryParseValue() [2/2]

bool catapult::ionet::TryParseValue ( const std::string &  str,
NodeRoles roles 
)

Tries to parse str into node roles.

Here is the call graph for this function:

◆ UnpackNode()

Node catapult::ionet::UnpackNode ( const NetworkNode networkNode)

Unpacks a network node (networkNode) into a node model.

Here is the caller graph for this function: