mod.rs

Overview

This file defines core traits and re-exports related to the transport layer abstraction used for sending and receiving ChitchatMessage instances over a network. It provides asynchronous interfaces for transport mechanisms and sockets, enabling modular implementations of different transport strategies such as UDP or in-memory channels. Additionally, it includes a test module to validate the behavior of these transports.

The primary purpose of this file is to establish the contract for transport implementations and to aggregate related modules (channel, transport_layer, udp, utils) for convenient usage elsewhere in the system.

Modules and Re-exports

These modules are publicly re-exported to allow external components to use their functionality via this unified interface.

Traits

Transport

An asynchronous trait that defines the interface for transport mechanisms capable of opening sockets bound to a specific local SocketAddr.

Methods

Usage example

let transport: &dyn Transport = &UdpTransport;
let socket = transport.open("127.0.0.1:8080".parse().unwrap()).await?;

Socket

An asynchronous trait representing a socket capable of sending and receiving ChitchatMessage instances over the network.

Methods

Usage example

let mut socket = transport.open(local_addr).await?;
socket.send(remote_addr, message).await?;
let (sender, received_message) = socket.recv().await?;

Implementation Details and Algorithms

Testing

The tests module contains asynchronous tests that verify:

Two transport implementations are tested: UdpTransport and ChannelTransport.

Interaction with Other Parts of the System

Diagram: Transport and Socket Trait Structure

classDiagram
class Transport {
+max_datagram_payload_size()
+open()
}
class Socket {
+send()
+recv()
}
Transport <|.. UdpTransport
Transport <|.. ChannelTransport
Transport <|.. TransportLayerTransport
Socket <|.. UdpSocket

This diagram illustrates the core traits Transport and Socket and their known implementors as re-exported by this module. The Transport trait exposes methods for opening sockets and querying payload size limits, while the Socket trait provides asynchronous send and receive operations for ChitchatMessage. Implementors like UdpTransport and ChannelTransport realize these abstractions for different underlying transport mechanisms.