Derecho  0.9
Distributed systems toolkit for RDMA
Public Member Functions | Private Member Functions | Private Attributes | List of all members
tcp::tcp_connections Class Reference

#include <connection_manager.hpp>

Collaboration diagram for tcp::tcp_connections:
Collaboration graph
[legend]

Public Member Functions

 tcp_connections (node_id_t my_id, const std::map< node_id_t, std::pair< ip_addr_t, uint16_t >> ip_addrs_and_ports)
 Creates a TCP connection manager for a set of connections to all of the initial set of addresses. More...
 
void destroy ()
 
bool write (node_id_t node_id, char const *buffer, size_t size)
 Writes size bytes from a buffer to the node with ID node_id, using the TCP socket connected to that node. More...
 
bool write_all (char const *buffer, size_t size)
 Writes size bytes from a buffer to all the other nodes currently connected, in ascending order of node ID. More...
 
bool read (node_id_t node_id, char *buffer, size_t size)
 Receives size bytes from the node with ID node_id, over the TCP socket connected to that node. More...
 
bool add_node (node_id_t new_id, const std::pair< ip_addr_t, uint16_t > &new_ip_addr_and_port)
 Adds a TCP connection to a new node. More...
 
bool delete_node (node_id_t remove_id)
 Removes a node from the managed set of TCP connections, closing the socket connected to it. More...
 
bool contains_node (node_id_t node_id)
 Checks whether this connection manager currently has a socket connected to the node with the specified ID. More...
 
template<class T >
bool exchange (node_id_t node_id, T local, T &remote)
 
int32_t probe_all ()
 Checks all of the TCP connections managed by this object for new incoming data, and returns the ID of the lowest-numbered node that has data available to read. More...
 
void filter_to (const std::vector< node_id_t > &live_nodes_list)
 Compares the set of TCP connections to a list of known live nodes and removes any connections to nodes not in that list. More...
 
derecho::LockedReference< std::unique_lock< std::mutex >, socketget_socket (node_id_t node_id)
 Gets a locked reference to the TCP socket connected to a particular node. More...
 

Private Member Functions

bool add_connection (const node_id_t other_id, const std::pair< ip_addr_t, uint16_t > &other_ip_and_port)
 
void establish_node_connections (const std::map< node_id_t, std::pair< ip_addr_t, uint16_t >> &ip_addrs_and_ports)
 

Private Attributes

std::mutex sockets_mutex
 
node_id_t my_id
 
std::unique_ptr< connection_listenerconn_listener
 
std::map< node_id_t, socketsockets
 

Detailed Description

Definition at line 12 of file connection_manager.hpp.

Constructor & Destructor Documentation

◆ tcp_connections()

tcp::tcp_connections::tcp_connections ( node_id_t  my_id,
const std::map< node_id_t, std::pair< ip_addr_t, uint16_t >>  ip_addrs_and_ports 
)

Creates a TCP connection manager for a set of connections to all of the initial set of addresses.

Parameters
my_idThe ID of this node
ip_addrs_and_portsThe map of IP address-port pairs to connect to, indexed by node ID

Definition at line 80 of file connection_manager.cpp.

Member Function Documentation

◆ add_connection()

bool tcp::tcp_connections::add_connection ( const node_id_t  other_id,
const std::pair< ip_addr_t, uint16_t > &  other_ip_and_port 
)
private

Definition at line 8 of file connection_manager.cpp.

◆ add_node()

bool tcp::tcp_connections::add_node ( node_id_t  new_id,
const std::pair< ip_addr_t, uint16_t > &  new_ip_addr_and_port 
)

Adds a TCP connection to a new node.

If the new node's ID is lower than this node's ID, this function initiates a new TCP connection to it; otherwise, this function listens on a TCP socket and waits for the new node to make a connection.

Parameters
new_idThe ID of the new node
new_ip_addr_and_portThe IP address and port number of the new node
Returns
True if the TCP connection was set up successfully, false if there was an error.

Definition at line 120 of file connection_manager.cpp.

◆ contains_node()

bool tcp::tcp_connections::contains_node ( node_id_t  node_id)

Checks whether this connection manager currently has a socket connected to the node with the specified ID.

Parameters
node_idThe node ID to check
Returns
True if this connection manager has a socket for that node ID, false if it does not.

Definition at line 134 of file connection_manager.cpp.

◆ delete_node()

bool tcp::tcp_connections::delete_node ( node_id_t  remove_id)

Removes a node from the managed set of TCP connections, closing the socket connected to it.

Parameters
remove_idThe ID of the node to remove
Returns
True if the node/socket was removed successfully, false if it was not.

Definition at line 129 of file connection_manager.cpp.

◆ destroy()

void tcp::tcp_connections::destroy ( )

Definition at line 86 of file connection_manager.cpp.

◆ establish_node_connections()

void tcp::tcp_connections::establish_node_connections ( const std::map< node_id_t, std::pair< ip_addr_t, uint16_t >> &  ip_addrs_and_ports)
private

Definition at line 64 of file connection_manager.cpp.

◆ exchange()

template<class T >
bool tcp::tcp_connections::exchange ( node_id_t  node_id,
local,
T &  remote 
)
inline

Definition at line 94 of file connection_manager.hpp.

◆ filter_to()

void tcp::tcp_connections::filter_to ( const std::vector< node_id_t > &  live_nodes_list)

Compares the set of TCP connections to a list of known live nodes and removes any connections to nodes not in that list.

This is used to filter out connections to nodes that were removed from the view.

Parameters
live_nodes_listA list of node IDs whose connections should be retained; all other connections will be deleted.

Definition at line 150 of file connection_manager.cpp.

◆ get_socket()

derecho::LockedReference< std::unique_lock< std::mutex >, socket > tcp::tcp_connections::get_socket ( node_id_t  node_id)

Gets a locked reference to the TCP socket connected to a particular node.

While the caller holds the locked reference to the socket, no other tcp_connections methods can be called. This makes it safe to use this method to access sockets directly, even though they are usually managed by the other tcp_connections methods.

Parameters
node_idThe ID of the desired node
Returns
A LockedReference to the TCP socket connected to that node.

Definition at line 168 of file connection_manager.cpp.

◆ probe_all()

int32_t tcp::tcp_connections::probe_all ( )

Checks all of the TCP connections managed by this object for new incoming data, and returns the ID of the lowest-numbered node that has data available to read.

Returns -1 if none of the connected nodes have any data ready to read.

Returns
The lowest node ID with data available in its TCP socket, or -1 if no sockets are ready to read.

Definition at line 139 of file connection_manager.cpp.

◆ read()

bool tcp::tcp_connections::read ( node_id_t  node_id,
char *  buffer,
size_t  size 
)

Receives size bytes from the node with ID node_id, over the TCP socket connected to that node.

Blocks until all the bytes have been received or there is an error while reading.

Parameters
node_idThe ID of the node to read from
bufferA byte buffer to put received data into
sizeThe number of bytes to read
Returns
True if all the bytes were read successfully, false if there was an error.

Definition at line 112 of file connection_manager.cpp.

◆ write()

bool tcp::tcp_connections::write ( node_id_t  node_id,
char const *  buffer,
size_t  size 
)

Writes size bytes from a buffer to the node with ID node_id, using the TCP socket connected to that node.

Blocks until all the bytes have been written or there is an error while writing.

Parameters
node_idThe ID of the node to send data to
bufferA byte buffer containing the data to send
sizeThe number of bytes to send; must be <= the size of buffer
Returns
True if all bytes were written successfully, false if there was an error.

Definition at line 92 of file connection_manager.cpp.

◆ write_all()

bool tcp::tcp_connections::write_all ( char const *  buffer,
size_t  size 
)

Writes size bytes from a buffer to all the other nodes currently connected, in ascending order of node ID.

Parameters
bufferA byte buffer containing the data to send
sizeThe number of bytes to send
Returns
True if all writes completed successfully, false if any of them didn't.

Definition at line 100 of file connection_manager.cpp.

Member Data Documentation

◆ conn_listener

std::unique_ptr<connection_listener> tcp::tcp_connections::conn_listener
private

Definition at line 16 of file connection_manager.hpp.

◆ my_id

node_id_t tcp::tcp_connections::my_id
private

Definition at line 15 of file connection_manager.hpp.

◆ sockets

std::map<node_id_t, socket> tcp::tcp_connections::sockets
private

Definition at line 17 of file connection_manager.hpp.

◆ sockets_mutex

std::mutex tcp::tcp_connections::sockets_mutex
private

Definition at line 13 of file connection_manager.hpp.


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