OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::network::peer Class Reference

Maintains a TCP socket. More...

#include <peer.hpp>

Public Types

using callback_type = std::function<void(std::shared_ptr<cbdc::buffer>)>
 Type for the packet receipt callback function.
 

Public Member Functions

 peer (std::unique_ptr< tcp_socket > sock, callback_type cb, bool attempt_reconnect)
 Constructor.
 
 ~peer ()
 Destructor. Calls shutdown().
 
 peer (const peer &)=delete
 
auto operator= (const peer &) -> peer &=delete
 
 peer (peer &&)=delete
 
auto operator= (peer &&) -> peer &=delete
 
void send (const std::shared_ptr< cbdc::buffer > &data)
 Sends buffered data.
 
void shutdown ()
 Clears any packets in the pending send queue.
 
auto connected () const -> bool
 Indicates whether the TCP socket is currently connected.
 

Detailed Description

Maintains a TCP socket.

Handles reconnecting to a TCP socket, queuing discrete packets to send, sending queued packets, and passing received packets to a callback function.

Definition at line 21 of file peer.hpp.

Member Typedef Documentation

◆ callback_type

using cbdc::network::peer::callback_type = std::function<void(std::shared_ptr<cbdc::buffer>)>

Type for the packet receipt callback function.

Accepts a pointer to a discrete packet received via the TCP socket.

Definition at line 25 of file peer.hpp.

Constructor & Destructor Documentation

◆ peer() [1/3]

cbdc::network::peer::peer ( std::unique_ptr< tcp_socket > sock,
peer::callback_type cb,
bool attempt_reconnect )

Constructor.

Starts socket management threads.

Starts a thread to send queued packets via the associated TCP socket. Starts a thread to receive packets and call a callback function. Starts a thread to monitor the connection status of the TCP socket and reconnect if the socket disconnects.

Parameters
sockTCP socket to manage.
cbcallback function to call with packets received by the socket.
attempt_reconnecttrue if the instance should reconnect the TCP socket if it loses the connection.

Definition at line 12 of file peer.cpp.

◆ ~peer()

cbdc::network::peer::~peer ( )

Destructor. Calls shutdown().

Definition at line 23 of file peer.cpp.

References shutdown().

Here is the call graph for this function:

◆ peer() [2/3]

cbdc::network::peer::peer ( const peer & )
delete

◆ peer() [3/3]

cbdc::network::peer::peer ( peer && )
delete

Member Function Documentation

◆ connected()

auto cbdc::network::peer::connected ( ) const -> bool
nodiscard

Indicates whether the TCP socket is currently connected.

Returns
true if the TCP socket is connected.

Definition at line 42 of file peer.cpp.

◆ operator=() [1/2]

auto cbdc::network::peer::operator= ( const peer & ) -> peer &=delete
delete

◆ operator=() [2/2]

auto cbdc::network::peer::operator= ( peer && ) -> peer &=delete
delete

◆ send()

void cbdc::network::peer::send ( const std::shared_ptr< cbdc::buffer > & data)

Sends buffered data.

Queues a packet to send via the TCP socket. The recipient peer receives it as a discrete unit.

Parameters
databuffer to send.

Definition at line 27 of file peer.cpp.

Referenced by cbdc::network::connection_manager::broadcast(), and cbdc::network::connection_manager::send().

◆ shutdown()

void cbdc::network::peer::shutdown ( )

Clears any packets in the pending send queue.

Stops the send, receive, and reconnect threads. Disconnects the TCP socket.

Definition at line 33 of file peer.cpp.

Referenced by cbdc::network::connection_manager::close(), and ~peer().


The documentation for this class was generated from the following files: