### Example TLS Server Setup Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/simple/fn.tls_server.html Demonstrates how to set up and run a TLS-secured TCP server using `aggligator_transport_tcp::simple::tls_server`. Ensure all server IP addresses are registered in DNS for client discovery. Requires loading certificate and private key. ```rust use std::net::{Ipv6Addr, SocketAddr}; use std::sync::Arc; use aggligator_transport_tcp::simple::{tls_server, ServerConfig}; #[tokio::main] async fn main() -> std::io::Result<()> { let tls_certs = todo!("load certificate tree"); let tls_key = todo!("load private key"); let tls_cfg = Arc::new( ServerConfig::builder() .with_no_client_auth() .with_single_cert(tls_certs, tls_key) .unwrap() ); tls_server( SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 5901), tls_cfg, |stream| async move { // use the incoming connection } ).await?; Ok(()) } ``` -------------------------------- ### Run a TCP Server with Aggligator Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/simple/fn.tcp_server.html Example of starting a TCP server on port 5900 that listens on all interfaces. ```rust use std::net::{Ipv6Addr, SocketAddr}; use aggligator_transport_tcp::simple::tcp_server; #[tokio::main] async fn main() -> std::io::Result<()> { tcp_server( SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 5900), |stream| async move { // use the incoming connection } ).await?; Ok(()) } ``` -------------------------------- ### Basic Usage and Utility Functions Source: https://docs.rs/aggligator/latest/index.html Guides on how to use the aggligator crate for establishing connections and utilizing utility functions. ```APIDOC ## Basic Usage and Utility Functions See the `connect` module on how to accept incoming connections and establish outgoing connections. This is agnostic of the underlying protocol. Useful functions for working with TCP-based links, encryption and authentication using TLS, can be found in the **aggligator-transport-tcp** crate. A collection of transports for Aggligator is provided on crates.io. Command line utilites, that also serve as fully worked out examples, are provided in the **aggligator-util** crate. ``` -------------------------------- ### Start Graceful Disconnection Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Starts the process of graceful disconnection for the link. This function returns immediately. ```rust pub fn start_disconnect(&self) ``` -------------------------------- ### Internal Listener Setup Source: https://docs.rs/aggligator-transport-tcp/latest/src/aggligator_transport_tcp/lib.rs.html Helper function to bind a socket to a specific interface and port. ```rust fn listen(interface: &util::NetworkInterface, port: u16, ip_version: IpVersion) -> Result { let ip = interface .addr .iter() .find_map(|addr| match addr { Addr::V4(ip) if ip_version != IpVersion::IPv6 => Some(IpAddr::V4(ip.ip)), Addr::V6(ip) if ip_version != IpVersion::IPv4 => Some(IpAddr::V6(ip.ip)), _ => None, }) .ok_or(ErrorKind::NotFound)?; let addr = SocketAddr::new(ip, port); let socket = match addr.ip() { IpAddr::V4(_) => TcpSocket::new_v4()?, IpAddr::V6(_) => TcpSocket::new_v6()?, }; if addr.is_ipv6() { let _ = SockRef::from(&socket).set_only_v6(false); } socket.bind(addr)?; #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] socket.bind_device(Some(interface.name.as_bytes()))?; tracing::debug!(%addr, interface =% interface.name, "listening"); socket.listen(8) } ``` -------------------------------- ### Start Accepting Incoming Connections Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Server.html Begins listening for new incoming connections. Only one `Listener` can exist at a time; attempting to create another will result in an error. Incoming links can be added to existing connections without needing to listen. ```rust pub fn listen(&self) -> Result, ListenError> ``` -------------------------------- ### Get Not Working Reason Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Returns the reason why the link is not working. Returns `None` if the link is working. ```rust pub fn not_working_reason(&self) -> Option ``` -------------------------------- ### Initialize outgoing connection Source: https://docs.rs/aggligator/latest/src/aggligator/connect.rs.html Starts building a new connection with outgoing links only, returning the task, outgoing handle, and control interface. ```rust pub fn connect(cfg: Cfg) -> (Task, Outgoing, Control) where RX: Stream> + Unpin + Send + 'static, TX: Sink + Unpin + Send + 'static, TAG: Send + Sync + 'static, { let AggParts { task, channel, control, connected_rx } = AggParts::new( Arc::new(cfg), OwnedConnId::untracked(ConnId::generate()), Direction::Outgoing, None, None, Vec::new(), None, ); (task, Outgoing { channel, connected_rx }, control) } ``` -------------------------------- ### Start Building Outgoing Connection Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Server.html Initiates the process of building a new outgoing connection. The returned `Task` must be executed for the connection to function. Links can be added using `Control::add` or `Control::add_io` before establishing the connection with `Outgoing::connect`. ```rust pub fn connect(&self) -> (Task, Outgoing, Control) ``` -------------------------------- ### Demonstrate ambiguous Pin conversion Source: https://docs.rs/aggligator/latest/aggligator/transport/type.LinkTagBox.html An example of a discouraged implementation of From that causes ambiguity when calling Pin::from. ```rust struct Foo; // A type defined in this crate. impl From> for Pin { fn from(_: Box<()>) -> Pin { Pin::new(Foo) } } let foo = Box::new(()); let bar = Pin::from(foo); ``` -------------------------------- ### Listener Methods Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Listener.html This section covers the implementations of the Listener struct, including methods to get the server ID and accept new incoming connections. ```APIDOC ## Implementations ### impl Listener #### pub fn id(&self) -> ServerId ##### Description The server id. ##### Method GET ##### Endpoint N/A (Method on struct instance) #### pub async fn next(&mut self) -> Result, IncomingError> ##### Description Gets the next incoming connection. The incoming connection can be inspected before making the decision to accept or refuse it. This function is cancel-safe. ##### Method GET ##### Endpoint N/A (Method on struct instance) #### pub async fn accept( &mut self, ) -> Result<(Task, Channel, Control), IncomingError> ##### Description Accepts the next incoming connection. This function is cancel-safe. ##### Method POST ##### Endpoint N/A (Method on struct instance) ``` -------------------------------- ### Connect Function API Source: https://docs.rs/aggligator/latest/aggligator/connect/index.html Details on the 'connect' function for starting new outgoing connections. ```APIDOC ## connect ### Description Starts building a new connection consisting of outgoing links only. ### Method (Not specified, likely a function call within Rust code) ### Endpoint N/A (This is a Rust function, not an HTTP endpoint) ### Parameters (No specific parameters listed in the provided text) ### Request Example (Not applicable for a Rust function) ### Response (No specific return type or success/error details provided for the function itself) ``` -------------------------------- ### Server and Listener for Incoming Connections Source: https://docs.rs/aggligator/latest/aggligator/connect/index.html Information on setting up servers and listeners to accept incoming connections. ```APIDOC ## Incoming Connections ### Description To accept **incoming connections** a Server and corresponding Listener are required. Incoming links must be fed to the server, which then combines them and exposes them as connections of aggregated links via the listener. ### Structs #### Listener Listens for new connections consisting of aggregated links. #### Server Handle to a link aggregator server. ### Enums #### ListenError Listen error. ``` -------------------------------- ### Initiate Link Flushing Source: https://docs.rs/aggligator/latest/src/aggligator/agg/task.rs.html Starts the flushing process for a specific link, typically to send buffered data or acknowledgments. It also removes the link from the idle list. ```rust fn flush_link(&mut self, id: usize) { let link = self.links[id].as_mut().unwrap(); link.start_flush(); self.idle_links.retain(|&idle_id| idle_id != id); } ``` -------------------------------- ### Get Cause of LinkError (Deprecated) Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxLinkError.html Deprecated method for getting the cause of the error. Use Error::source instead. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### Create IoTx Instances Source: https://docs.rs/aggligator/latest/aggligator/io/struct.IoTx.html Methods to initialize the IoTx wrapper with either default or custom codecs. ```rust pub fn new(write: W) -> Self ``` ```rust pub fn with_codec(write: W, codec: IntegrityCodec) -> Self ``` -------------------------------- ### Get Description of LinkError (Deprecated) Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxLinkError.html Deprecated method for getting a string description of the error. Use Display or to_string() instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### Get Link Direction Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Returns the direction of the link. ```rust pub fn direction(&self) -> Direction ``` -------------------------------- ### Create New Server Instance Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Server.html Initializes a new link aggregator server with the provided configuration. ```rust pub fn new(cfg: Cfg) -> Self ``` -------------------------------- ### Get Connection Statistics Source: https://docs.rs/aggligator/latest/src/aggligator/control.rs.html Retrieves the current statistics for the connection. ```APIDOC ## GET /control/stats ### Description Returns the current connection statistics. ### Method GET ### Endpoint /control/stats ### Response #### Success Response (200) - **stats** (Stats) - The current connection statistics object. ``` -------------------------------- ### Server Creation and Management Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Server.html Methods for creating and managing the Server instance. ```APIDOC ## POST /api/users ### Description Creates a new link aggregator server. ### Method POST ### Endpoint /api/users ### Parameters #### Query Parameters - **cfg** (Cfg) - Required - Configuration for the new server. ### Request Example ```json { "cfg": { ... } } ``` ### Response #### Success Response (200) - **Server** (Server) - A handle to the newly created link aggregator server. #### Response Example ```json { "server_id": "some_server_id" } ``` ``` -------------------------------- ### Get Connection Statistics Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxControl.html Returns the current connection statistics. ```rust pub fn stats(&self) -> Stats ``` -------------------------------- ### Manage Connections and Listeners Source: https://docs.rs/aggligator/latest/src/aggligator/connect.rs.html Methods for initiating outgoing connections and setting up a listener for incoming connections. ```rust pub fn connect(&self) -> (Task, Outgoing, Control) { let mut inner = self.inner.lock().unwrap(); let conn_id = ConnId::generate(); let (link_tx, link_rx) = mpsc::channel(inner.cfg.connect_queue.get()); let AggParts { task, channel, control, connected_rx } = AggParts::new( inner.cfg.clone(), OwnedConnId::new(conn_id, inner.closed_conns_tx.clone()), Direction::Outgoing, Some(self.server_id), None, Vec::new(), Some((link_tx.clone(), link_rx)), ); inner.conns.insert(conn_id, link_tx); (task, Outgoing { channel, connected_rx }, control) } pub fn listen(&self) -> Result, ListenError> { let mut inner = self.inner.lock().unwrap(); if !inner.listen_tx.is_closed() { return Err(ListenError::AlreadyListening); } let (listen_tx, listen_rx) = mpsc::channel(inner.cfg.connect_queue.get()); inner.listen_tx = listen_tx; Ok(Listener { server_id: inner.server_id, listen_rx }) } ``` -------------------------------- ### Get Link Statistics Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Retrieves the current statistics for the link. ```rust pub fn stats(&self) -> LinkStats ``` -------------------------------- ### Server Creation and Information Source: https://docs.rs/aggligator/latest/src/aggligator/connect.rs.html Provides methods for creating a new server instance and retrieving its ID. ```APIDOC ## POST /api/server ### Description Creates a new link aggregator server. ### Method POST ### Endpoint /api/server ### Request Body - **cfg** (Cfg) - Required - Configuration for the server. ### Response #### Success Response (200) - **ServerId** (ServerId) - The unique identifier for the newly created server. ### Request Example ```json { "cfg": { "connect_queue": 100, "link_ping_timeout": "5s" } } ``` ### Response Example ```json { "server_id": "some-unique-server-id" } ``` ## GET /api/server/{server_id}/id ### Description Retrieves the server ID. ### Method GET ### Endpoint /api/server/{server_id}/id ### Parameters #### Path Parameters - **server_id** (ServerId) - Required - The ID of the server. ### Response #### Success Response (200) - **ServerId** (ServerId) - The ID of the server. ### Response Example ```json { "server_id": "some-unique-server-id" } ``` ``` -------------------------------- ### Get Link Configuration Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Provides access to the configuration of the connection. ```rust pub fn cfg(&self) -> &Cfg ``` -------------------------------- ### Get Connection ID Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Retrieves the identifier for the underlying connection. ```rust pub fn conn_id(&self) -> ConnId ``` -------------------------------- ### TxRxBox::new Source: https://docs.rs/aggligator/latest/aggligator/io/struct.TxRxBox.html Creates a new instance of TxRxBox. ```APIDOC ## pub fn new ### Description Creates a new instance. ### Parameters - **tx** (impl Sink + Send + Sync + 'static) - The sender component. - **rx** (impl Stream> + Send + Sync + 'static) - The receiver component. ### Returns - Self - A new instance of TxRxBox. ``` -------------------------------- ### AcceptorBuilder Methods Source: https://docs.rs/aggligator/latest/aggligator/transport/struct.AcceptorBuilder.html Methods for initializing and configuring the AcceptorBuilder. ```APIDOC ## new(cfg: Cfg) ### Description Creates a new instance of AcceptorBuilder. ### Method Constructor ### Parameters #### Request Body - **cfg** (Cfg) - Required - The configuration for the builder. --- ## set_task_cfg(task_cfg) ### Description Sets the function configuring the connection task of each incoming connection. ### Parameters #### Request Body - **task_cfg** (impl Fn(&mut BoxTask) + Send + Sync + 'static) - Required - Configuration function for the connection task. --- ## set_no_transport_timeout(no_transport_timeout) ### Description Sets the timeout for waiting for a connection when no transports are currently present. ### Parameters #### Request Body - **no_transport_timeout** (Duration) - Required - The timeout duration. --- ## wrap(wrapper) ### Description Adds a connection wrapper to the wrapper stack. ### Parameters #### Request Body - **wrapper** (impl AcceptingWrapper) - Required - The wrapper to add. --- ## build() ### Description Finalizes the configuration and builds the Acceptor. ### Response - **Acceptor** - The constructed Acceptor instance. ``` -------------------------------- ### Get Link ID Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Retrieves the unique identifier for the link. ```rust pub fn id(&self) -> LinkId ``` -------------------------------- ### Get TcpConnector Name Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/struct.TcpConnector.html Returns the name of the TCP transport. ```rust fn name(&self) -> &str ``` -------------------------------- ### AcceptorBuilder Build Method Source: https://docs.rs/aggligator/latest/src/aggligator/transport/acceptor.rs.html Constructs and returns an Acceptor instance based on the configured builder settings. It initializes necessary channels and spawns the main acceptor task. ```rust pub fn build(self) -> Acceptor { let Self { server, task_cfg, wrappers, no_transport_timeout } = self; let active_transports = Arc::new(RwLock::new(Vec::>::new())); let (transport_tx, transport_rx) = mpsc::unbounded_channel(); let (transports_present_tx, transports_present_rx) = watch::channel(true); let (error_tx, error_rx) = broadcast::channel(1024); let listener = Mutex::new(server.listen().unwrap()); exec::spawn( Acceptor::task( server.clone(), active_transports.clone(), transport_rx, error_tx, transports_present_tx, wrappers, ) .in_current_span(), ); Acceptor { server, listener, task_cfg, transport_tx, transports_present_rx, transports_being_added: Arc::new(Semaphore::new(Semaphore::MAX_PERMITS)), error_rx, active_transports, } } ``` -------------------------------- ### Get Connection Direction Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxTask.html Returns the direction of the connection managed by the BoxTask. ```rust pub fn direction(&self) -> Direction ``` -------------------------------- ### Box::new_uninit_in Source: https://docs.rs/aggligator/latest/aggligator/transport/type.LinkTagBox.html Constructs a new Box with uninitialized contents in the provided allocator. This is a nightly-only experimental API and is available only on non-`no_global_oom_handling` configurations. ```APIDOC ## POST /box/new_uninit_in ### Description Constructs a new box with uninitialized contents in the provided allocator. This is a nightly-only experimental API. ### Method POST ### Endpoint /box/new_uninit_in ### Parameters #### Request Body - **alloc** (A) - Required - The allocator to use for memory allocation. ### Response #### Success Response (200) - **Box, A>** - A Box with uninitialized contents allocated using the provided allocator. ``` -------------------------------- ### Get Connection Links Source: https://docs.rs/aggligator/latest/src/aggligator/control.rs.html Retrieves handles to all links currently associated with the connection. ```APIDOC ## GET /control/links ### Description Gets handles to all links of the connection. ### Method GET ### Endpoint /control/links ### Response #### Success Response (200) - **links** (Vec>) - A list of link handles. ``` -------------------------------- ### Accepting Incoming Connections Source: https://docs.rs/aggligator/latest/src/aggligator/transport/mod.rs.html Demonstrates how to use the Acceptor to listen for and handle incoming connections on a specified transport. ```APIDOC ## Accepting Incoming Connections ### Description Use the `Acceptor` to listen for incoming connections. The acceptor must be configured with a transport-specific listener. ### Usage Example ```rust use std::net::{Ipv6Addr, SocketAddr}; use aggligator::Acceptor; use aggligator_transport_tcp::TcpAcceptor; let acceptor = Acceptor::new(); acceptor.add(TcpAcceptor::new([SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 5900)]).await?); loop { let (ch, _control) = acceptor.accept().await?; let stream = ch.into_stream(); } ``` ``` -------------------------------- ### Get Connector Control Source: https://docs.rs/aggligator/latest/src/aggligator/transport/connector.rs.html Obtains a clone of the connection control for the aggregated connection. ```rust pub fn control(&self) -> BoxControl { self.control.clone() } ``` -------------------------------- ### TxRxBox Sink start_send Method Source: https://docs.rs/aggligator/latest/aggligator/io/struct.TxRxBox.html Initiates sending a 'Bytes' item through the TxRxBox Sink. A preceding 'poll_ready' call must return 'Poll::Ready(Ok(()))'. ```rust fn start_send(self: Pin<&mut Self>, item: Bytes) -> Result<()> ``` -------------------------------- ### Acceptor Methods Source: https://docs.rs/aggligator/latest/aggligator/transport/struct.Acceptor.html Methods for initializing and managing the Acceptor instance. ```APIDOC ## Acceptor Methods ### Description Methods to create and configure the Acceptor for handling incoming connections. ### Methods - **new()**: Creates a new acceptor using default configuration. - **wrapped(wrapper)**: Creates a new acceptor with a single connection wrapper. - **add(transport)**: Adds a new transport to the acceptor. - **is_empty()**: Checks if any transports are present. - **accept()**: Asynchronously waits for and accepts an incoming connection. - **link_errors()**: Returns a receiver for subscribing to link error events. ``` -------------------------------- ### Get Connection ID from OwnedConnId Source: https://docs.rs/aggligator/latest/src/aggligator/id.rs.html Retrieves the underlying `ConnId` from an `OwnedConnId` wrapper. ```rust pub fn get(&self) -> ConnId { self.0.id } ``` -------------------------------- ### IoBox::new Source: https://docs.rs/aggligator/latest/aggligator/io/struct.IoBox.html Creates a new instance of IoBox with provided reader and writer. ```APIDOC ## IoBox::new ### Description Creates a new instance. ### Method `pub fn new(read: impl AsyncRead + Send + Sync + 'static, write: impl AsyncWrite + Send + Sync + 'static) -> Self` ### Parameters #### Request Body - **read** (impl AsyncRead + Send + Sync + 'static) - The reader component. - **write** (impl AsyncWrite + Send + Sync + 'static) - The writer component. ``` -------------------------------- ### Get Connection Identifier Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxTask.html Retrieves the unique identifier for the connection managed by the BoxTask. ```rust pub fn id(&self) -> ConnId ``` -------------------------------- ### Get Connection Link Handles Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxControl.html Retrieves handles to all links associated with the connection. ```rust pub fn links(&self) -> Vec> ``` -------------------------------- ### Connector Methods Source: https://docs.rs/aggligator/latest/aggligator/transport/struct.Connector.html Methods for initializing, configuring, and monitoring the Connector. ```APIDOC ## Connector Methods ### new() Creates a new connector using the default configuration. ### wrapped(wrapper: impl ConnectingWrapper) Creates a new connector using the default configuration and a single connection wrapper. ### add(transport: impl ConnectingTransport) Adds a transport to the connector. Returns a `ConnectingTransportHandle`. ### channel() Waits for the connection to be established and obtains the aggregated link channel. Returns `Option`. ### control() Obtains the connection control of the aggregated connection. Returns `BoxControl`. ### available_tags() Gets the current set of available link tags. Returns `HashSet`. ### available_tags_watch() Watches the set of available link tags. Returns `Receiver>`. ### set_disabled_tags(disabled_tags: HashSet) Sets the set of disabled link tags. ### link_errors() Subscribes to the stream of link errors. Returns `Receiver`. ``` -------------------------------- ### Get Owned Type Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/util/struct.NetworkInterface.html Associated type representing the owned version of the data. ```rust type Owned = T ``` -------------------------------- ### Server Initialization and ID Access Source: https://docs.rs/aggligator/latest/src/aggligator/connect.rs.html Methods to create a new server instance and retrieve its unique identifier. ```rust pub fn new(cfg: Cfg) -> Self { let server_id = ServerId::generate(); Self { server_id, inner: Arc::new(Mutex::new(ServerInner::new(Arc::new(cfg), server_id))) } } /// The server id. pub fn id(&self) -> ServerId { self.server_id } ``` -------------------------------- ### GET /link_errors Source: https://docs.rs/aggligator/latest/src/aggligator/transport/acceptor.rs.html Subscribes to the stream of link errors occurring within the transport system. ```APIDOC ## GET /link_errors ### Description Subscribes to the stream of link errors. Returns a broadcast receiver that yields BoxLinkError objects. ### Method GET ### Endpoint /link_errors ### Response #### Success Response (200) - **receiver** (broadcast::Receiver) - A receiver handle for the link error broadcast channel. ``` -------------------------------- ### Box::new_uninit Source: https://docs.rs/aggligator/latest/aggligator/transport/type.LinkTagBox.html Constructs a new Box with uninitialized contents. ```APIDOC ## Box::new_uninit ### Description Constructs a new box with uninitialized contents. Available on non-`no_global_oom_handling` only. ### Method Associated function (called as `Box::new_uninit()`) ### Endpoint N/A (Rust function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ### Response #### Success Response (200) Returns a `Box>`. #### Response Example (Conceptual, as this is a Rust function) ```rust // Returns a Box> ``` ``` -------------------------------- ### connect Source: https://docs.rs/aggligator/latest/src/aggligator/connect.rs.html Initializes a new connection for outgoing links, returning the task, outgoing handle, and control interface. ```APIDOC ## connect(cfg: Cfg) ### Description Starts building a new connection consisting of outgoing links only. Incoming links cannot be added to this connection. ### Parameters #### Request Body - **cfg** (Cfg) - Required - The configuration for the new connection. ### Response Returns a tuple containing: - **Task** - The task managing the connection. - **Outgoing** - The handle to the outgoing connection. - **Control** - The interface to control the connection (e.g., adding links). ``` -------------------------------- ### Get Transmitter Polling Time Source: https://docs.rs/aggligator/latest/src/aggligator/agg/link_int.rs.html Returns the time when the transmitter was last polled for readiness. ```rust pub(crate) fn tx_polling(&self) -> Option { self.tx_polling } ``` -------------------------------- ### Function: connect Source: https://docs.rs/aggligator/latest/aggligator/connect/fn.connect.html Initializes a new connection instance that supports outgoing links. The returned Task must be executed to process the connection. ```APIDOC ## connect ### Description Starts building a new connection consisting of outgoing links only. Incoming links cannot be added to this connection. The returned Task manages the connection and must be executed (e.g., using tokio::spawn) for the connection to function. ### Method Rust Function ### Parameters - **cfg** (Cfg) - Required - The configuration for the connection. ### Response - **Task** - The task managing the connection. - **Outgoing** - Handle used to establish the connection. - **Control** - Handle used to add links via `add` or `add_io`. ``` -------------------------------- ### Get Listener Server ID Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Listener.html Retrieves the unique server ID associated with the listener. ```rust pub fn id(&self) -> ServerId ``` -------------------------------- ### GET local_interfaces Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/util/fn.local_interfaces.html Retrieves a list of local network interfaces, filtering out those deemed useless. ```APIDOC ## GET local_interfaces ### Description Gets the list of local network interfaces from the operating system. Filters out interfaces that are most likely useless. ### Method GET ### Endpoint aggligator_transport_tcp::util::local_interfaces ### Response #### Success Response (200) - **Result>** - A list of valid local network interfaces. ``` -------------------------------- ### IoRx Implementations Source: https://docs.rs/aggligator/latest/aggligator/io/struct.IoRx.html Provides methods for creating and configuring IoRx instances. ```APIDOC ### impl IoRx #### pub fn new(read: R) -> Self Wraps an IO reader using the default configuration of the integrity codec. #### pub fn with_codec(read: R, codec: IntegrityCodec) -> Self Wraps an IO reader using a customized integrity codec. ``` -------------------------------- ### AcceptorBuilder Initialization Source: https://docs.rs/aggligator/latest/src/aggligator/transport/acceptor.rs.html Initializes a new AcceptorBuilder with a Server instance and default configurations. The task configuration is set to a no-op function by default. ```rust impl AcceptorBuilder { /// Creates a new builder. pub fn new(cfg: Cfg) -> Self { let server = Server::new(cfg); let task_cfg: TaskCfgFn = Box::new(|_| ()); Self { server, task_cfg, wrappers: Vec::new(), no_transport_timeout: Duration::from_secs(30) } } } ``` -------------------------------- ### Get Link Tag Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Retrieves the user-defined tag associated with this link. Aggligator does not process this tag. ```rust pub fn tag(&self) -> &TAG ``` -------------------------------- ### Aggligator Control Module Overview Source: https://docs.rs/aggligator/latest/aggligator/control/index.html Overview of the structs and enums available for managing connections and links. ```APIDOC ## Structs ### Control A handle for controlling and monitoring a connection consisting of aggregated links. ### Link A handle for controlling and monitoring a link. ### LinkIntervalStats Link statistics over a time interval. ### LinkStats Link statistics. ### Stats Connection statistics. ## Enums ### AddLinkError Error adding a link to a connection. ### Direction Direction of a connection or link. ### DisconnectReason The reason for the disconnection of a link. ### NotWorkingReason Reason why a link is not working. ``` -------------------------------- ### GET /stats Source: https://docs.rs/aggligator/latest/src/aggligator/control.rs.html Retrieves the current connection statistics, including buffer space and packet consumption metrics. ```APIDOC ## GET /stats ### Description Returns the current connection statistics, providing insights into buffer usage and packet transmission status. ### Method GET ### Endpoint /stats ### Response #### Success Response (200) - **established** (Option) - Time when the connection was established. - **not_working_since** (Option) - Time since no link of the connection is working. - **send_space** (usize) - Available buffer space for sending data. - **sent_unacked** (usize) - Size of data sent and not yet acknowledged. - **sent_unconsumed** (usize) - Size of data sent and not yet consumed by remote. - **sent_unconsumed_count** (usize) - Number of packets sent and not yet consumed. - **sent_unconsumable** (usize) - Size of data received by remote that cannot yet be consumed. - **resend_queue_len** (usize) - Length of the queue for resending lost packets. - **recved_unconsumed** (usize) - Size of data received and not yet consumed. - **recved_unconsumed_count** (usize) - Number of packets received and not yet consumed. ``` -------------------------------- ### Get Connector Outgoing Channel Source: https://docs.rs/aggligator/latest/src/aggligator/transport/connector.rs.html Retrieves the aggregated outgoing link channel. Returns None if called more than once. ```rust pub fn channel(&mut self) -> Option { self.outgoing.take() } ``` -------------------------------- ### IoTx::new Source: https://docs.rs/aggligator/latest/aggligator/io/struct.IoTx.html Creates a new IoTx instance wrapping an IO writer with the default integrity codec configuration. ```APIDOC ## pub fn new(write: W) -> Self ### Description Wraps an IO writer using the default configuration of the integrity codec. ### Parameters - **write** (W) - Required - The IO writer to be wrapped (must implement AsyncWrite). ``` -------------------------------- ### TlsServer::new Source: https://docs.rs/aggligator-wrapper-tls/0.2.0/aggligator_wrapper_tls/struct.TlsServer.html Creates a new TLS incoming connection wrapper using the provided server configuration. ```APIDOC ## impl TlsServer ### pub fn new(server_cfg: Arc) -> Self Creates a new TLS incoming connection wrapper. Incoming links are encrypted using TLS with the configuration specified in `server_cfg`. ``` -------------------------------- ### Get Direction for TcpLinkTag Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/struct.TcpLinkTag.html Returns the direction of the link represented by the TcpLinkTag. This is part of the LinkTag trait implementation. ```rust fn direction(&self) -> Direction ``` -------------------------------- ### Get Disconnect Reason Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Returns the reason for disconnection if the link is disconnected. Returns `None` if the link is currently connected. ```rust pub fn disconnect_reason(&self) -> Option ``` -------------------------------- ### Establishing Outgoing Connections Source: https://docs.rs/aggligator/latest/src/aggligator/transport/mod.rs.html Demonstrates how to use the Connector to establish outgoing connections to a remote server using a specific transport (e.g., TCP). ```APIDOC ## Establishing Outgoing Connections ### Description Use the `Connector` to initiate outgoing connections to a remote endpoint. This requires a transport-specific connector implementation. ### Usage Example ```rust use aggligator::Connector; use aggligator_transport_tcp::TcpConnector; let mut connector = Connector::new(); connector.add(TcpConnector::new(["server".to_string()], 5900).await?); let ch = connector.channel().unwrap().await?; let stream = ch.into_stream(); ``` ``` -------------------------------- ### Create New Connector Source: https://docs.rs/aggligator/latest/src/aggligator/transport/connector.rs.html Creates a new connector with the default configuration. Use ConnectorBuilder for more customization options. ```rust pub fn new() -> Self { ConnectorBuilder::new(Cfg::default()).build() } ``` -------------------------------- ### Get Transport Name for TcpLinkTag Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/struct.TcpLinkTag.html Returns the name of the transport associated with the TcpLinkTag. This is part of the LinkTag trait implementation. ```rust fn transport_name(&self) -> &str ``` -------------------------------- ### Get interface names for target Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/util/fn.interface_names_for_target.html Returns a set of interface names that are compatible with the provided target socket address. ```rust pub fn interface_names_for_target( interfaces: &[NetworkInterface], target: SocketAddr, ) -> HashSet> ``` -------------------------------- ### Create Wrapped Connector Source: https://docs.rs/aggligator/latest/src/aggligator/transport/connector.rs.html Creates a new connector with default configuration and applies a single connection wrapper. ```rust pub fn wrapped(wrapper: impl ConnectingWrapper) -> Self { let mut builder = ConnectorBuilder::new(Cfg::default()); builder.wrap(wrapper); builder.build() } ``` -------------------------------- ### Box::new Source: https://docs.rs/aggligator/latest/aggligator/transport/type.LinkTagBox.html Allocates memory on the heap and places a value into it. ```APIDOC ## Box::new ### Description Allocates memory on the heap and then places `x` into it. This doesn’t actually allocate if `T` is zero-sized. Available on non-`no_global_oom_handling` only. ### Method Associated function (called as `Box::new(x)`) ### Endpoint N/A (Rust function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let five = Box::new(5); ``` ### Response #### Success Response (200) Returns a `Box` containing the value `x`. #### Response Example (Conceptual, as this is a Rust function) ```rust // Returns a Box ``` ``` -------------------------------- ### Run Server Task Source: https://docs.rs/aggligator/latest/src/aggligator/transport/acceptor.rs.html Executes the main server task for the aggregator. This is typically called once to start the server's operation. ```rust exec::spawn(task.run().in_current_span()); ``` -------------------------------- ### Stream API Source: https://docs.rs/aggligator/latest/aggligator/transport/type.LinkTagBox.html Defines methods for interacting with a boxed stream, including polling for the next item and getting size hints. ```APIDOC ## impl Stream for Box ### Description Provides methods for interacting with a boxed stream. ### Associated Types - `Item`: Values yielded by the stream. ### Methods #### fn poll_next( self: Pin<&mut Box>, cx: &mut Context<'_>, ) -> Poll as Stream>::Item>> Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning `None` if the stream is exhausted. #### fn size_hint(&self) -> (usize, Option) Returns the bounds on the remaining length of the stream. ``` -------------------------------- ### Connect to a host using tcp_connect Source: https://docs.rs/aggligator-transport-tcp/latest/aggligator_transport_tcp/simple/fn.tcp_connect.html Establishes an aggregated TCP connection to a specified host and port. Requires an async runtime like tokio. ```rust use aggligator_transport_tcp::simple::tcp_connect; #[tokio::main] async fn main() -> std::io::Result<()> { let stream = tcp_connect(["server".to_string()], 5900).await?; // use the connection Ok(()) } ``` -------------------------------- ### AcceptedStreamBox::new Source: https://docs.rs/aggligator/latest/aggligator/transport/struct.AcceptedStreamBox.html Creates a new instance of an AcceptedStreamBox. ```APIDOC ## AcceptedStreamBox::new ### Description Creates a new instance of an AcceptedStreamBox using a stream and a link tag. ### Parameters - **stream** (StreamBox) - Required - The stream to be accepted. - **tag** (impl LinkTag) - Required - The link tag associated with the stream. ### Request Example AcceptedStreamBox::new(stream, tag); ### Response - **AcceptedStreamBox** (Struct) - A new instance containing the provided stream and tag. ``` -------------------------------- ### Get and Mark Statistics as Seen Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxControl.html Marks the current connection statistics as seen. This will cause `stats_changed` to wait until a change occurs. ```rust pub fn stats_update(&mut self) -> Stats ``` -------------------------------- ### Aggligator Native Executive Modules Source: https://docs.rs/aggligator/latest/src/aggligator/exec/native/mod.rs.html Overview of the runtime, task, and time modules provided by the aggligator/exec/native crate. ```APIDOC ## Native Executive Modules ### Description Provides re-exports and wrappers for Tokio-based asynchronous primitives. ### Modules - **runtime**: Re-exports `tokio::runtime::Handle`. - **task**: Re-exports `tokio::task::{spawn, JoinError, JoinHandle}`. - **time**: Provides time-based utilities including `sleep`, `timeout`, and `interval_stream`. ### Utility Functions - **interval_stream(period: Duration) -> IntervalStream**: Creates a new `IntervalStream` from a `tokio::time::interval`. ``` -------------------------------- ### Get and Mark Links as Seen Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxControl.html Retrieves handles to all links and marks them as seen. This will cause `links_changed` to wait until a change occurs. ```rust pub fn links_update(&mut self) -> Vec> ``` -------------------------------- ### Get Source of LinkError Source: https://docs.rs/aggligator/latest/aggligator/transport/type.BoxLinkError.html Implements the Error trait's source method for LinkError, returning the underlying error if available. ```rust fn source(&self) -> Option<&(dyn Error + 'static)> ``` -------------------------------- ### Initialize Aggregator Parts Source: https://docs.rs/aggligator/latest/src/aggligator/agg/mod.rs.html Constructs a new `AggParts` instance, setting up internal tasks, channels, and control structures for link aggregation. Requires generic types for transmit (TX), receive (RX), and tag (TAG), along with specific configuration and link details. ```rust impl where RX: Stream> + Unpin + Send + 'static, TX: Sink + Unpin + Send + 'static, TAG: Send + Sync + 'static, { /// Creates a new aggregated connection and returns its parts. #[allow(clippy::type_complexity)] pub(crate) fn new( cfg: Arc, conn_id: OwnedConnId, direction: Direction, server_id: Option, remote_server_id: Option, links: Vec>, link_tx_rx: Option<(mpsc::Sender>, mpsc::Receiver>)>,) -> Self { let (terminate_tx, terminate_rx) = mpsc::channel(1); let (read_tx, read_rx) = mpsc::channel(cfg.recv_queue.get()); let (write_tx, write_rx) = mpsc::channel(cfg.send_queue.get()); let (read_error_tx, read_error_rx) = watch::channel(Some(RecvError::TaskTerminated)); let (write_error_tx, write_error_rx) = watch::channel(SendError::TaskTerminated); let (read_closed_tx, read_closed_rx) = mpsc::channel(1); let (links_tx, links_rx) = watch::channel(links.iter().map(Link::from).collect()); let (link_tx, link_rx) = link_tx_rx.unwrap_or_else(|| mpsc::channel(cfg.connect_queue.get())); let (connected_tx, connected_rx) = oneshot::channel(); let (stats_tx, stats_rx) = watch::channel(Default::default()); let (server_changed_tx, server_changed_rx) = mpsc::channel(1); let (result_tx, result_rx) = watch::channel(Err(TaskError::Terminated)); let remote_cfg = links.first().as_ref().map(|link| link.remote_cfg()); let connected = Arc::new(AtomicBool::new(!links.is_empty())); Self { task: Task::new( cfg.clone(), remote_cfg.clone(), conn_id.clone(), direction, terminate_rx, links_tx, link_rx, connected_tx, read_tx, read_closed_rx, write_rx, read_error_tx, write_error_tx, stats_tx, server_changed_rx, result_tx, links, ), channel: Channel::new( cfg.clone(), remote_cfg, conn_id.get(), write_tx, write_error_rx, read_rx, read_closed_tx, read_error_rx, ), control: Control { cfg, conn_id: conn_id.get(), server_id, remote_server_id: Arc::new(Mutex::new(remote_server_id)), direction, terminate_tx, link_tx, links_rx, connected, stats_rx, server_changed_tx, result_rx, }, connected_rx, } } } ``` -------------------------------- ### Get Next Incoming Connection Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Listener.html Asynchronously retrieves the next incoming connection. The connection can be inspected before acceptance. This function is cancel-safe. ```rust pub async fn next(&mut self) -> Result, IncomingError> ``` -------------------------------- ### Server Connection Methods Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Server.html Methods for establishing and managing connections through the Server. ```APIDOC ## POST /api/users/connect ### Description Starts building a new outgoing connection. Incoming links can be added to this connection. ### Method POST ### Endpoint /api/users/connect ### Parameters #### Query Parameters - **server_id** (ServerId) - Required - The ID of the server to connect to. ### Request Example ```json { "server_id": "some_server_id" } ``` ### Response #### Success Response (200) - **Task** (Task) - Manages the connection and must be executed. - **Outgoing** (Outgoing) - Used to establish the connection. - **Control** (Control) - Used to add links to the connection. #### Response Example ```json { "task_handle": "some_task_handle", "outgoing_connection": "some_outgoing_connection_details", "control_handle": "some_control_handle" } ``` ``` ```APIDOC ## POST /api/users/listen ### Description Starts accepting new incoming connections. Only one `Listener` may be present at a time. ### Method POST ### Endpoint /api/users/listen ### Parameters #### Query Parameters - **server_id** (ServerId) - Required - The ID of the server to listen on. ### Request Example ```json { "server_id": "some_server_id" } ``` ### Response #### Success Response (200) - **Listener** (Listener) - A handle to the listener for accepting incoming connections. #### Response Example ```json { "listener_handle": "some_listener_handle" } ``` #### Error Response (409) - **ListenError** - Returned if a listener already exists. ``` -------------------------------- ### Get Connection ID Source: https://docs.rs/aggligator/latest/aggligator/connect/struct.Outgoing.html Retrieves the unique identifier for an established connection. This method is part of the Outgoing struct's implementations. ```rust pub fn id(&self) -> ConnId ``` -------------------------------- ### Get Available Tags Source: https://docs.rs/aggligator/latest/src/aggligator/transport/connector.rs.html Retrieves the current set of available link tags. Note that this may not reflect the currently connected tags. ```rust pub fn available_tags(&self) -> HashSet { self.tags_rx.borrow().clone() } ``` -------------------------------- ### TcpConnector Creation Methods Source: https://docs.rs/aggligator-transport-tcp/latest/src/aggligator_transport_tcp/lib.rs.html Methods for initializing a new TcpConnector, with or without initial resolution checks. ```rust impl TcpConnector { /// Create a new TCP transport for outgoing connections. /// /// `hosts` can contain IP addresses and hostnames, including port numbers. /// If an entry does not specify a port number, the `default_port` is used. /// /// It is checked at creation that `hosts` resolves to at least one IP address. /// /// Host name resolution is retried periodically, thus DNS updates will be taken /// into account without the need to recreate this transport. pub async fn new(hosts: impl IntoIterator, default_port: u16) -> Result { let this = Self::unresolved(hosts, default_port).await?; let addrs = this.resolve().await; if addrs.is_empty() { return Err(Error::new(ErrorKind::NotFound, "cannot resolve IP address of host")); } tracing::info!(%this, ?addrs, "hosts initially resolved"); Ok(this) } /// Create a new TCP transport for outgoing connections without checking that at least one host can be resolved. /// /// `hosts` can contain IP addresses and hostnames, including port numbers. /// If an entry does not specify a port number, the `default_port` is used. /// /// Host name resolution is retried periodically, thus DNS updates will be taken /// into account without the need to recreate this transport. pub async fn unresolved(hosts: impl IntoIterator, default_port: u16) -> Result { let mut hosts: Vec<_> = hosts.into_iter().collect(); if hosts.is_empty() { return Err(Error::new(ErrorKind::InvalidInput, "at least one host is required")); } for host in &mut hosts { if !host.contains(':') { host.push_str(&format!(":{default_port}")); } } Ok(Self { hosts, ip_version: IpVersion::Both, resolve_interval: Duration::from_secs(10), link_filter: TcpLinkFilter::default(), multi_interface: !cfg!(target_os = "android"), interface_filter: Arc::new(|_| true), }) } ``` -------------------------------- ### TcpConnector Initialization Source: https://docs.rs/aggligator-transport-tcp/latest/src/aggligator_transport_tcp/lib.rs.html Methods for creating and configuring a new TcpConnector instance. ```APIDOC ## TcpConnector::new ### Description Creates a new TCP transport for outgoing connections, verifying that at least one host can be resolved. ### Parameters - **hosts** (impl IntoIterator) - Required - List of IP addresses or hostnames. - **default_port** (u16) - Required - Port to use if not specified in the host string. ## TcpConnector::unresolved ### Description Creates a new TCP transport without performing an initial DNS resolution check. ### Parameters - **hosts** (impl IntoIterator) - Required - List of IP addresses or hostnames. - **default_port** (u16) - Required - Port to use if not specified in the host string. ``` -------------------------------- ### Get Remote User Data Source: https://docs.rs/aggligator/latest/aggligator/control/struct.Link.html Retrieves user data provided by the remote endpoint during link establishment. Aggligator does not process this data. ```rust pub fn remote_user_data(&self) -> &[u8] ⓘ ``` -------------------------------- ### AcceptingWrapper for TlsServer Source: https://docs.rs/aggligator-wrapper-tls/0.2.0/aggligator_wrapper_tls/struct.TlsServer.html Implementation of the AcceptingWrapper trait for TlsServer, providing methods to get the wrapper's name and wrap incoming streams. ```APIDOC ### impl AcceptingWrapper for TlsServer #### fn name(&self) -> &str Name of the wrapper. #### fn wrap<'life0, 'async_trait>( &'life0 self, stream: StreamBox, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, Wraps the incoming stream. ```