#include <connection_manager.hpp>
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 >, socket > | get_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_listener > | conn_listener |
std::map< node_id_t, socket > | sockets |
Definition at line 12 of file connection_manager.hpp.
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.
my_id | The ID of this node |
ip_addrs_and_ports | The map of IP address-port pairs to connect to, indexed by node ID |
Definition at line 80 of file connection_manager.cpp.
|
private |
Definition at line 8 of file connection_manager.cpp.
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.
new_id | The ID of the new node |
new_ip_addr_and_port | The IP address and port number of the new node |
Definition at line 120 of file connection_manager.cpp.
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.
node_id | The node ID to check |
Definition at line 134 of file connection_manager.cpp.
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.
remove_id | The ID of the node to remove |
Definition at line 129 of file connection_manager.cpp.
void tcp::tcp_connections::destroy | ( | ) |
Definition at line 86 of file connection_manager.cpp.
|
private |
Definition at line 64 of file connection_manager.cpp.
|
inline |
Definition at line 94 of file connection_manager.hpp.
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.
live_nodes_list | A list of node IDs whose connections should be retained; all other connections will be deleted. |
Definition at line 150 of file connection_manager.cpp.
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.
node_id | The ID of the desired node |
Definition at line 168 of file connection_manager.cpp.
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.
Definition at line 139 of file connection_manager.cpp.
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.
node_id | The ID of the node to read from |
buffer | A byte buffer to put received data into |
size | The number of bytes to read |
Definition at line 112 of file connection_manager.cpp.
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.
node_id | The ID of the node to send data to |
buffer | A byte buffer containing the data to send |
size | The number of bytes to send; must be <= the size of buffer |
Definition at line 92 of file connection_manager.cpp.
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.
buffer | A byte buffer containing the data to send |
size | The number of bytes to send |
Definition at line 100 of file connection_manager.cpp.
|
private |
Definition at line 16 of file connection_manager.hpp.
|
private |
Definition at line 15 of file connection_manager.hpp.
Definition at line 17 of file connection_manager.hpp.
|
private |
Definition at line 13 of file connection_manager.hpp.