9#ifndef LIBE3_POSIX_CONNECTOR_HPP
10#define LIBE3_POSIX_CONNECTOR_HPP
14#include <condition_variable>
57 const std::string& endpoint,
69 int receive(std::vector<uint8_t>& buffer)
override;
92 return transport_layer_;
104 enum class SocketKind {
116 Target target()
const;
117 int make_socket(
int family)
const;
118 void tune_socket(
int fd, SocketKind kind)
const;
119 int listen_on(
const Target& where);
120 int connect_to(
const Target& where);
121 bool admit(
const void* address)
const;
122 void accept_pending();
123 std::shared_ptr<Peer> find_peer(uint64_t token);
124 bool pump(std::vector<uint8_t>& out, uint64_t& token,
int timeout_ms);
125 void drop_peer(
const std::shared_ptr<Peer>& peer);
126 void push_setup(
const std::shared_ptr<Peer>& peer, std::vector<uint8_t>&& pdu);
127 bool receiver_idle()
const;
128 int receive_client(std::vector<uint8_t>& buffer);
132 std::string endpoint_uri_;
134 PosixOptions options_;
137 mutable std::mutex peers_mutex_;
138 std::vector<std::shared_ptr<Peer>> peers_;
139 uint64_t next_token_{1};
140 size_t round_robin_{0};
142 std::mutex reader_mutex_;
143 std::atomic<int64_t> last_receive_ns_{0};
145 std::mutex queue_mutex_;
146 std::condition_variable setup_ready_;
147 std::deque<Queued> setup_queue_;
148 std::deque<Queued> inbound_queue_;
149 std::shared_ptr<Peer> setup_peer_;
150 uint64_t last_setup_token_{0};
151 uint64_t last_peer_token_{0};
152 std::mutex closed_mutex_;
153 std::vector<uint64_t> closed_peers_;
156 std::vector<uint8_t> client_rx_;
157 std::mutex client_write_mutex_;
158 bool setup_request_sent_{
false};
159 std::atomic<bool> awaiting_setup_response_{
false};
160 std::mutex await_mutex_;
161 std::condition_variable await_cv_;
163 bool connected_{
false};
164 std::atomic<bool> shutdown_requested_{
false};
E3Connector(const E3Connector &)=delete
E3LinkLayer link_layer() const noexcept override
Get the link layer type.
ErrorCode send_setup_request_client(const std::vector< uint8_t > &data) override
Send a SetupRequest on the setup channel (dApp role).
~PosixE3Connector() override
Close every socket.
uint64_t last_peer_token() const override
Which peer supplied the bytes the last receive() returned (RAN role).
int recv_setup_request(std::vector< uint8_t > &buffer) override
Receive a setup request.
uint64_t last_setup_peer_token() const override
Which peer sent the setup request the last recv_setup_request() returned (RAN role).
void dispose() override
Clean up and release all resources.
int receive(std::vector< uint8_t > &buffer) override
Receive data from the inbound channel.
ErrorCode send(const std::vector< uint8_t > &data) override
Send data on the outbound channel.
ErrorCode setup_initial_connection_client() override
Connect the setup channel (dApp role: REQ connect).
E3TransportLayer transport_layer() const noexcept override
Get the transport layer type.
ErrorCode send_to(uint64_t peer_token, const std::vector< uint8_t > &data, PduClass kind) override
Send data to one peer, or to all of them (RAN role).
int recv_setup_response_client(std::vector< uint8_t > &buffer) override
Receive a SetupResponse on the setup channel (dApp role).
ErrorCode send_response(const std::vector< uint8_t > &data) override
Send a setup response.
PosixE3Connector(E3TransportLayer transport_layer, const std::string &endpoint, uint16_t port, const PosixOptions &options)
Create a POSIX connector.
void shutdown() override
Interrupt blocking operations for shutdown.
ErrorCode setup_outbound_connection_client() override
Connect the outbound channel (dApp role: PUB connect to the RAN's subscriber endpoint).
ErrorCode setup_inbound_connection_client() override
Connect the inbound channel (dApp role: SUB connect to the RAN's publisher endpoint).
std::vector< uint64_t > take_closed_peers() override
Peers whose connection has closed since the last call (RAN role).
ErrorCode setup_initial_connection() override
Set up the initial connection (setup channel).
ErrorCode setup_inbound_connection() override
Set up the inbound connection (SUB channel).
ErrorCode setup_outbound_connection() override
Set up the outbound connection (PUB channel).
bool is_connected() const noexcept override
Check if connector is connected.
Abstract E3 Connector interface for transport layer.
ErrorCode
Error codes returned by libe3 operations Use shared error-code list (see libe3/error_codes....
E3TransportLayer
Transport layer types (matches Python E3TransportLayer).
E3LinkLayer
Link layer types (matches Python E3LinkLayer).
@ POSIX
POSIX socket-based transport.
PduClass
What a PDU is for, so that a link that has streams can pick one.
Socket and admission options of the POSIX link.