Skip to main content

Module mesh_channel

Module mesh_channel 

Source
Expand description

Reliable message channel over the mesh datagram transport.

qualia_core_db::p2p::mesh_datagram frames application payloads as IPv6/UDP datagrams over a WireGuard tunnel, but — like all UDP — delivery is best-effort: datagrams can be lost, reordered, or duplicated. Chat sync needs at-least-once delivery (a published fragment must arrive) with deduplication (a retransmit must not double-apply). This module is that layer: a small, pure reliable-datagram protocol — sequence numbers, acknowledgements, timed retransmission, and receive-side dedup.

It is deliberately a pure state machine: it never touches a socket, a thread, or the clock. The caller supplies the current time (monotonic milliseconds) and moves the produced wire frames in and out via the mesh (SocialWebNet::send_datagram / the decoded inbound payload). That keeps the protocol deterministically unit-testable — including loss, reordering, and duplication — with no I/O, and independent of the (separately-contended) core-db crate.

Wire frame (carried as the datagram payload):

  byte 0    : kind  (0x00 = DATA, 0x01 = ACK)
  bytes 1..5: seq   (u32, big-endian)
  bytes 5.. : payload (DATA only; ACK carries none)

Reliability is per-ReliableEndpoint (i.e. per peer): each endpoint numbers the datagrams it sends and acknowledges the datagrams it receives. Message ordering is not imposed — chat fragments are content-addressed and idempotent, so at-least-once + dedup is effectively exactly-once for them; an app that needs ordering can sequence at its own layer.

Structs§

Inbound
What processing one inbound frame produced.
ReliableEndpoint
The reliable channel to a single peer. Pure: drive it with send, on_datagram, and on_tick, moving the returned frames over the mesh yourself.

Constants§

DEFAULT_MAX_ATTEMPTS
Default maximum send attempts before giving up on a datagram.
DEFAULT_RTO_MS
Default retransmit timeout (ms) — resend an unacked datagram after this long.