Networking#
constellation::networking
Namespace#
-
using constellation::networking::Port = std::uint16_t#
Port number for a network connection.
Note that most ports in Constellation are ephemeral ports, meaning that the port numbers are allocated dynamically. See also https://en.wikipedia.org/wiki/Ephemeral_port.
-
std::string constellation::networking::get_hostname()#
Get hostname.
Note
This function sanitized the hostname by replacing hyphens and dots with underscores
-
std::vector<Interface> constellation::networking::get_interfaces()#
Get all interfaces.
- Returns:
List with all interfaces
-
std::vector<Interface> constellation::networking::get_interfaces(std::vector<std::string> interface_names)#
Get interfaces matching a list of interface names.
- Returns:
List of interfaces with matching names
-
std::string constellation::networking::to_uri(const asio::ip::address_v4 &address, Port port, std::string_view protocol = "tcp")#
Build a URI from an IP address and a port.
- Parameters:
address – IPv4 address
port – Port
protocol – Protocol (without
://
), can be empty
- Returns:
URI in the form
protocol://address:port
-
Port constellation::networking::bind_ephemeral_port(zmq::socket_t &socket)#
Bind ZeroMQ socket to wildcard address with ephemeral port.
See also https://libzmq.readthedocs.io/en/latest/zmq_tcp.html.
- Parameters:
socket – Reference to socket which should be bound
- Returns:
Ephemeral port assigned by operating system
-
std::shared_ptr<zmq::context_t> &constellation::networking::global_zmq_context()#
Return the global ZeroMQ context.
Note
Since the global ZeroMQ context is static, static classes need to store an instance of the shared pointer.
- Returns:
Shared pointer to the global ZeroMQ context
-
struct Interface#
- #include <constellation/core/networking/asio_helpers.hpp>
Interface containing its name and address.
-
class NetworkError : public constellation::utils::RuntimeError#
- #include <constellation/core/networking/exceptions.hpp>
Errors related to network communication.
Problems that could never have been detected at compile time
Subclassed by constellation::networking::RecvTimeoutError, constellation::networking::SendTimeoutError
Public Functions
-
inline explicit NetworkError(std::string what_arg)#
Creates exception with the given network problem.
- Parameters:
what_arg – Text describing the problem
Protected Functions
-
NetworkError() = default#
Internal constructor for exceptions setting the error message indirectly.
-
inline explicit NetworkError(std::string what_arg)#
-
class RecvTimeoutError : public constellation::networking::NetworkError#
- #include <constellation/core/networking/exceptions.hpp>
Error when receiving a message timed out.
Public Functions
-
inline explicit RecvTimeoutError(const std::string &what, std::chrono::seconds timeout)#
-
inline explicit RecvTimeoutError(const std::string &what, std::chrono::seconds timeout)#
-
class SendTimeoutError : public constellation::networking::NetworkError#
- #include <constellation/core/networking/exceptions.hpp>
Error when sending a message timed out.
Public Functions
-
inline explicit SendTimeoutError(const std::string &what, std::chrono::seconds timeout)#
-
inline explicit SendTimeoutError(const std::string &what, std::chrono::seconds timeout)#