Initial import: ICE-NET research docs and Rust workspace (v0.4)
Some checks failed
rust-ci / checks (push) Has been cancelled

- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI)
- Sim: fix false Delivered after a route cut, derive traffic class from
  payload size, per-link airtime slots (link capacity, queueing)
- Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers,
  drop unimplemented seed claims, uncheck store-and-forward
- License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
This commit is contained in:
Loki 2026-11-13 12:28:48 +01:00
commit 2e61688eb3
Signed by: boba
GPG key ID: 6CDE87BC9A778D97
141 changed files with 13993 additions and 0 deletions

View file

@ -0,0 +1,8 @@
[package]
name = "icenet-transport"
version.workspace = true
edition.workspace = true
license.workspace = true
[dependencies]
icenet-core = { path = "../icenet-core" }

View file

@ -0,0 +1,56 @@
//! Dependency-free transport boundary, in-memory and UDP adapters.
#![forbid(unsafe_code)]
#![warn(missing_docs)]
use std::collections::VecDeque;
mod udp;
pub use udp::UdpTransport;
/// Largest draft frame accepted by these adapters (payload cap plus wire header).
pub const MAX_DATAGRAM_BYTES: usize = 4_096 + 14;
/// Errors produced by a transport implementation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TransportError {
/// This implementation will not accept a frame of this size.
TooLarge,
/// The socket is temporarily unable to send or receive.
Unavailable,
}
/// A small synchronous transport interface for early experiments.
pub trait Transport {
/// Sends one bounded frame; ownership moves into the transport.
///
/// # Errors
/// Returns an error if local transport limits reject this frame.
fn send(&mut self, frame: Vec<u8>) -> Result<(), TransportError>;
/// Receives the next available frame without blocking.
///
/// # Errors
/// Returns `Unavailable` when the socket fails; `Ok(None)` means no frame
/// is ready yet.
fn recv(&mut self) -> Result<Option<Vec<u8>>, TransportError>;
}
/// A loopback transport used only for controlled tests.
#[derive(Debug, Default)]
pub struct MemoryTransport {
queue: VecDeque<Vec<u8>>,
}
impl Transport for MemoryTransport {
fn send(&mut self, frame: Vec<u8>) -> Result<(), TransportError> {
if frame.len() > MAX_DATAGRAM_BYTES {
return Err(TransportError::TooLarge);
}
self.queue.push_back(frame);
Ok(())
}
fn recv(&mut self) -> Result<Option<Vec<u8>>, TransportError> {
Ok(self.queue.pop_front())
}
}

View file

@ -0,0 +1,68 @@
//! Non-blocking UDP adapter for one connected peer.
use std::io;
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
use crate::{MAX_DATAGRAM_BYTES, Transport, TransportError};
/// A non-blocking UDP socket connected to one peer address.
#[derive(Debug)]
pub struct UdpTransport {
socket: UdpSocket,
}
impl UdpTransport {
/// Binds a local address and makes the socket non-blocking.
///
/// # Errors
/// Returns the underlying socket error when binding or configuration fails.
pub fn bind(address: impl ToSocketAddrs) -> io::Result<Self> {
let socket = UdpSocket::bind(address)?;
socket.set_nonblocking(true)?;
Ok(Self { socket })
}
/// Connects this socket to one peer.
///
/// # Errors
/// Returns the underlying socket error when connecting fails.
pub fn connect(self, peer: impl ToSocketAddrs) -> io::Result<Self> {
self.socket.connect(peer)?;
Ok(self)
}
/// Returns the local socket address, including an OS-assigned port.
///
/// # Errors
/// Returns the underlying socket error when the address is unavailable.
pub fn local_addr(&self) -> io::Result<SocketAddr> {
self.socket.local_addr()
}
}
impl Transport for UdpTransport {
fn send(&mut self, frame: Vec<u8>) -> Result<(), TransportError> {
if frame.len() > MAX_DATAGRAM_BYTES {
return Err(TransportError::TooLarge);
}
match self.socket.send(&frame) {
Ok(_) => Ok(()),
Err(_) => Err(TransportError::Unavailable),
}
}
fn recv(&mut self) -> Result<Option<Vec<u8>>, TransportError> {
let mut buffer = [0_u8; MAX_DATAGRAM_BYTES];
match self.socket.recv(&mut buffer) {
Ok(size) => Ok(Some(buffer[..size].to_vec())),
Err(error)
if matches!(
error.kind(),
io::ErrorKind::WouldBlock | io::ErrorKind::TimedOut
) =>
{
Ok(None)
}
Err(_) => Err(TransportError::Unavailable),
}
}
}

View file

@ -0,0 +1,11 @@
use icenet_transport::{MemoryTransport, Transport};
#[test]
fn memory_transport_preserves_frame_order() {
let mut transport = MemoryTransport::default();
transport.send(vec![1]).unwrap();
transport.send(vec![2]).unwrap();
assert_eq!(transport.recv(), Ok(Some(vec![1])));
assert_eq!(transport.recv(), Ok(Some(vec![2])));
assert_eq!(transport.recv(), Ok(None));
}

View file

@ -0,0 +1,45 @@
use std::time::{Duration, Instant};
use icenet_transport::{Transport, TransportError, UdpTransport};
fn connected_pair() -> (UdpTransport, UdpTransport) {
let first = UdpTransport::bind("127.0.0.1:0").expect("bind first");
let second = UdpTransport::bind("127.0.0.1:0").expect("bind second");
let first_addr = first.local_addr().expect("first address");
let second_addr = second.local_addr().expect("second address");
(
first.connect(second_addr).expect("connect first"),
second.connect(first_addr).expect("connect second"),
)
}
fn receive(transport: &mut UdpTransport) -> Vec<u8> {
let deadline = Instant::now() + Duration::from_secs(2);
while Instant::now() < deadline {
if let Some(frame) = transport.recv().expect("recv") {
return frame;
}
std::thread::sleep(Duration::from_millis(5));
}
panic!("no UDP frame within the deadline");
}
#[test]
fn udp_transport_round_trips_frames() {
let (mut first, mut second) = connected_pair();
first.send(b"hello over udp".to_vec()).expect("send");
assert_eq!(receive(&mut second), b"hello over udp");
}
#[test]
fn udp_transport_rejects_oversized_frames() {
let (mut first, _second) = connected_pair();
let oversized = vec![0; 8_192];
assert_eq!(first.send(oversized), Err(TransportError::TooLarge));
}
#[test]
fn empty_udp_socket_returns_no_frame() {
let (mut first, _second) = connected_pair();
assert_eq!(first.recv().expect("recv"), None);
}