CatapultServer  v0.5.0.1 (Elephant)
PacketSocket.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "BatchPacketReader.h"
23 #include "ConnectResult.h"
24 #include "IoTypes.h"
25 #include "PacketSocketOptions.h"
26 
27 namespace catapult {
28  namespace ionet {
29  struct NodeEndpoint;
30  struct Packet;
31  }
32 }
33 
34 namespace catapult { namespace ionet {
35 
38  class PacketSocket : public PacketIo, public BatchPacketReader {
39  public:
41  struct Stats {
43  bool IsOpen;
44 
47  };
48 
50 
51  public:
52  virtual ~PacketSocket() = default;
53 
54  public:
56  virtual void stats(const StatsCallback& callback) = 0;
57 
59  virtual void close() = 0;
60 
62  virtual std::shared_ptr<PacketIo> buffered() = 0;
63  };
64 
65  // region Accept
66 
69  public:
72  {}
73 
75  explicit AcceptedPacketSocketInfo(const std::string& host, const std::shared_ptr<PacketSocket>& pPacketSocket)
76  : m_host(host)
77  , m_pPacketSocket(pPacketSocket)
78  {}
79 
80  public:
82  const std::string& host() const {
83  return m_host;
84  }
85 
87  const std::shared_ptr<PacketSocket>& socket() const {
88  return m_pPacketSocket;
89  }
90 
91  public:
93  explicit operator bool() const {
94  return !!m_pPacketSocket;
95  }
96 
97  private:
98  std::string m_host;
99  std::shared_ptr<PacketSocket> m_pPacketSocket;
100  };
101 
104 
107 
109  void Accept(boost::asio::ip::tcp::acceptor& acceptor, const PacketSocketOptions& options, const AcceptCallback& accept);
110 
114  void Accept(
115  boost::asio::ip::tcp::acceptor& acceptor,
116  const PacketSocketOptions& options,
117  const ConfigureSocketCallback& configureSocket,
118  const AcceptCallback& accept);
119 
120  // endregion
121 
122  // region Connect
123 
126 
130  action Connect(
131  boost::asio::io_context& ioContext,
132  const PacketSocketOptions& options,
133  const NodeEndpoint& endpoint,
134  const ConnectCallback& callback);
135 
136  // endregion
137 }}
catapult::ionet::PacketSocket::~PacketSocket
virtual ~PacketSocket()=default
catapult::ionet::NodeEndpoint
A node's publicly accessible endpoint.
Definition: Node.h:35
catapult::ionet::AcceptedPacketSocketInfo::m_pPacketSocket
std::shared_ptr< PacketSocket > m_pPacketSocket
Definition: PacketSocket.h:99
BufferedPacketIo.h
m_host
std::string m_host
Definition: PacketSocket.cpp:477
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::ionet::Connect
action Connect(boost::asio::io_context &ioContext, const PacketSocketOptions &options, const NodeEndpoint &endpoint, const ConnectCallback &callback)
Definition: PacketSocket.cpp:525
catapult::ionet::ConnectCallback
consumer< ConnectResult, const std::shared_ptr< PacketSocket > & > ConnectCallback
Callback for a connected socket.
Definition: PacketSocket.h:125
m_query
Resolver::query m_query
Definition: PacketSocket.cpp:478
m_strandWrapper
thread::StrandOwnerLifetimeExtender< StrandedPacketSocket > m_strandWrapper
Definition: PacketSocket.cpp:323
m_nextBufferIndex
size_t m_nextBufferIndex
Definition: PacketSocket.cpp:128
m_resolver
Resolver m_resolver
Definition: PacketSocket.cpp:476
catapult::ionet::AcceptedPacketSocketInfo::AcceptedPacketSocketInfo
AcceptedPacketSocketInfo()
Creates an empty info.
Definition: PacketSocket.h:71
m_callback
const PacketSocket::WriteCallback m_callback
Definition: PacketSocket.cpp:127
m_maxPacketDataSize
size_t m_maxPacketDataSize
Definition: PacketSocket.cpp:243
catapult::extensions::ExtensionManager::addServiceRegistrar
void addServiceRegistrar(std::unique_ptr< ServiceRegistrar > &&pServiceRegistrar)
Adds a service registrar (pServiceRegistrar).
Definition: ExtensionManager.cpp:42
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
m_acceptor
boost::asio::ip::tcp::acceptor & m_acceptor
Definition: PacketSocket.cpp:370
PacketSocketOptions.h
RegisterExtension
PLUGIN_API void RegisterExtension(catapult::extensions::ProcessBootstrapper &bootstrapper)
Entry point for registering a dynamic extension module with bootstrapper.
Definition: PacketServerExtension.cpp:35
m_socket
socket m_socket
Definition: PacketSocket.cpp:240
catapult::ionet::ConfigureSocketCallback
consumer< socket & > ConfigureSocketCallback
Callback for configuring a socket before initiating an accept.
Definition: PacketSocket.h:103
catapult::ionet::ConnectResult
ConnectResult
Enumeration of possible connection results.
Definition: ConnectResult.h:41
m_packetExtractor
PacketExtractor & m_packetExtractor
Definition: PacketSocket.cpp:44
catapult::ionet::AcceptedPacketSocketInfo::host
const std::string & host() const
Gets the host.
Definition: PacketSocket.h:82
catapult::ionet::PacketIo::WriteCallback
consumer< SocketOperationCode > WriteCallback
Definition: PacketIo.h:34
NetworkPacketReadersService.h
m_wrapper
TSocketCallbackWrapper & m_wrapper
Definition: PacketSocket.cpp:241
ConnectResult.h
m_accept
AcceptCallback m_accept
Definition: PacketSocket.cpp:372
catapult::ionet::SocketOperationCode
SocketOperationCode
Enumeration of socket operation results.
Definition: SocketOperationCode.h:50
m_isCancelled
bool m_isCancelled
Definition: PacketSocket.cpp:479
catapult::net::AcceptHandler
consumer< const ionet::AcceptedPacketSocketInfo & > AcceptHandler
Definition: AsyncTcpServer.h:28
catapult::ionet::PacketIo
An interface for reading and writing packets.
Definition: PacketIo.h:31
PacketSocket.h
catapult::ionet::IsPacketDataSizeValid
constexpr bool IsPacketDataSizeValid(const PacketHeader &header, size_t maxPacketDataSize)
Determines if header indicates a valid packet data size no greater than maxPacketDataSize.
Definition: PacketHeader.h:41
m_strand
boost::asio::io_context::strand m_strand
Definition: PacketSocket.cpp:322
PLUGIN_API
#define PLUGIN_API
Definition: plugins.h:30
catapult::ionet::PacketSocket::buffered
virtual std::shared_ptr< PacketIo > buffered()=0
Gets a buffered interface to the packet socket.
catapult::ionet::PacketIo::ReadCallback
consumer< SocketOperationCode, const Packet * > ReadCallback
Definition: PacketIo.h:33
m_handler
BasicConnectHandler< StrandedConnectHandler > m_handler
Definition: PacketSocket.cpp:520
Context
AppendContext Context
Definition: PacketSocket.cpp:194
BatchPacketReader.h
Node.h
forwardsValidation.info
def info(*args)
Definition: forwardsValidation.py:12
catapult::ionet::AcceptedPacketSocketInfo::m_host
std::string m_host
Definition: PacketSocket.h:98
catapult::ionet::AcceptedPacketSocketInfo::AcceptedPacketSocketInfo
AcceptedPacketSocketInfo(const std::string &host, const std::shared_ptr< PacketSocket > &pPacketSocket)
Creates an info around host and pPacketSocket.
Definition: PacketSocket.h:75
m_endpoint
boost::asio::ip::tcp::endpoint m_endpoint
Definition: PacketSocket.cpp:480
catapult::ionet::PacketExtractResult
PacketExtractResult
Possible results from PacketExtractor::tryExtractNextPacket.
Definition: PacketExtractor.h:40
catapult::ionet::socket
boost::asio::ip::tcp::socket socket
Definition: IoTypes.h:30
catapult::ionet::AcceptCallback
consumer< const AcceptedPacketSocketInfo & > AcceptCallback
Callback for an accepted socket.
Definition: PacketSocket.h:106
catapult::ionet::PacketSocket::Stats
Statistics about a socket.
Definition: PacketSocket.h:41
catapult::action
std::function< void()> action
An action function.
Definition: functions.h:27
catapult::extensions::ProcessBootstrapper::extensionManager
ExtensionManager & extensionManager()
Gets the extension manager.
Definition: ProcessBootstrapper.cpp:67
catapult::ionet::AcceptedPacketSocketInfo::socket
const std::shared_ptr< PacketSocket > & socket() const
Gets the socket.
Definition: PacketSocket.h:87
m_payload
const PacketPayload m_payload
Definition: PacketSocket.cpp:126
catapult::ionet::PacketSocket::close
virtual void close()=0
Closes the socket.
catapult::ionet::CreateBufferedPacketIo
std::shared_ptr< PacketIo > CreateBufferedPacketIo(const std::shared_ptr< PacketIo > &pIo, boost::asio::io_context::strand &strand)
Adds buffering to pIo using strand for synchronization.
Definition: BufferedPacketIo.cpp:178
catapult::ionet::Accept
void Accept(boost::asio::ip::tcp::acceptor &acceptor, const PacketSocketOptions &options, const ConfigureSocketCallback &configureSocket, const AcceptCallback &accept)
Definition: PacketSocket.cpp:377
WorkingBuffer.h
catapult::ionet::PacketSocket::StatsCallback
consumer< const Stats & > StatsCallback
Definition: PacketSocket.h:49
m_buffer
WorkingBuffer m_buffer
Definition: PacketSocket.cpp:242
m_pSocket
std::shared_ptr< StrandedPacketSocket > m_pSocket
Definition: PacketSocket.cpp:373
catapult::ionet::PacketSocket::stats
virtual void stats(const StatsCallback &callback)=0
Retrieves statistics about this socket and passes them to callback.
Casting.h
pSocket
SocketPointer pSocket
Definition: PacketWriters.cpp:46
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::extensions::ProcessBootstrapper
Process bootstrapper.
Definition: ProcessBootstrapper.h:42
catapult::ionet::PacketSocketOptions
Packet socket options.
Definition: PacketSocketOptions.h:27
catapult::ionet::AcceptedPacketSocketInfo
Result of a packet socket accept operation.
Definition: PacketSocket.h:68
catapult::ionet::PacketSocket::Stats::NumUnprocessedBytes
size_t NumUnprocessedBytes
Number of unprocessed bytes.
Definition: PacketSocket.h:46
Logging.h
catapult::ionet::PacketSocket::Stats::IsOpen
bool IsOpen
true if the socket is open.
Definition: PacketSocket.h:43
ProcessBootstrapper.h
catapult::ionet::BatchPacketReader
An read-optimized interface for reading packets.
Definition: BatchPacketReader.h:27
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::ionet::PacketSocket
Definition: PacketSocket.h:38
IoTypes.h
StrandOwnerLifetimeExtender.h
m_configureSocket
ConfigureSocketCallback m_configureSocket
Definition: PacketSocket.cpp:371