Skip to main content

Crate offline_protocol_transport

Crate offline_protocol_transport 

Source
Expand description

Transport abstraction layer for the Offline Protocol SDK.

This crate defines the Transport trait and the transport state machines for BLE, the peer stream (the wifi_direct slot), Internet, Nostr, and Reticulum, plus the one Rust implementation of the peer-stream framing (stream_framing).

§This crate performs no network or radio I/O

No sockets are opened and no radios are touched here. Each transport is a thread-safe protocol/queue engine — status, send/receive queues, metrics, and (for BLE) fragmentation state — driven from two sides:

  • The protocol engine talks to the Transport trait: send() enqueues an outbound message, receive() dequeues an inbound one.
  • A platform bridge (Swift/Kotlin via the UniFFI bindings, or any host program) owns the actual sockets, relays, and radios. It drains the outbound queue (get_next_message() / get_next_signed_event() / get_next_fragment()), performs the real I/O, reports the outcome (confirm_sent() / report_send_failure()), injects inbound bytes (on_data_received() / on_fragment_received()), and drives availability (on_status_changed()).

Without a platform bridge attached, send() queues messages that never go anywhere — and, BLE excepted, start() never makes a transport Available in the first place, so send() returns TransportNotAvailable. A pure-Rust consumer must play the bridge role itself: mark the transport available, drain the queues, and do its own I/O.

Most transports signal pending outbound work through a set_on_messages_available callback instead of requiring a poll timer; InternetTransport is the exception and must be polled.

All code in this crate is 100% safe Rust with no unsafe blocks.

Re-exports§

pub use ble::BleTransport;
pub use ble::BleTransportBuilder;
pub use ble::FragmentEvictionCallback;
pub use ble::FragmentEvictionInfo;
pub use ble::PeerDevice;
pub use constants::DEFAULT_MAX_MESSAGE_SIZE;
pub use error::Error;
pub use error::Result;
pub use internet::InternetConfig;
pub use internet::InternetTransport;
pub use nostr::NostrConfig;
pub use nostr::NostrTransport;
pub use nostr::NostrTransportBuilder;
pub use nostr::SignedNostrEvent;
pub use nostr_crypto::routing_tag_for_address;
pub use nostr_crypto::NostrEvent;
pub use nostr_crypto::NostrKeypair;
pub use reticulum::ReticulumTransport;
pub use stream_framing::frame;
pub use stream_framing::CloseReason;
pub use stream_framing::PeerStreamReader;
pub use stream_framing::PreambleVerifier;
pub use stream_framing::StreamEvent;
pub use traits::Transport;
pub use traits::TransportStatus;
pub use types::LinkQuality;
pub use types::SharedCallback;
pub use types::TransportMetrics;
pub use types::TransportType;
pub use wifi_direct::WifiDirectConfig;
pub use wifi_direct::WifiDirectPeer;
pub use wifi_direct::WifiDirectTransport;

Modules§

ble
Bluetooth Low Energy (BLE) transport queue engine.
constants
Constants used throughout the offline-protocol-transport crate.
error
Transport layer errors.
internet
Internet transport (TCP/WebSocket relay) queue engine.
nostr
Nostr relay transport queue engine.
nostr_crypto
Nostr event creation and BIP-340 Schnorr signing.
reticulum
The gateway daemon transport’s queue engine.
stream_framing
Peer-stream framing: where a frame ends, and who the peer is.
traits
Transport trait definitions.
types
Transport types and data structures.
wifi_direct
The peer-stream transport: the queue engine behind the wifi_direct slot.