Skip to main content

zaun_community_protocol/
client.rs

1//! Sans-IO protocol client (specification §5–§10): one [`Session`] per connection to one host,
2//! plus signing helpers for community owners ([`owner`]) and members ([`member`]).
3//!
4//! The session never performs I/O and never reads a clock: the caller passes every received
5//! transport text to [`Session::receive`] with the current time, drains outbound texts with
6//! [`Session::poll_transmit`], and calls [`Session::poll_timeouts`] periodically (at least
7//! every second or so) to drive retries (§7.3), fragment expiry (§5.2) and acks (§10.5).
8//!
9//! ```text
10//!   app ── hello()/send()/send_signal() ──▶ Session ── poll_transmit() ──▶ transport
11//!   app ◀── Vec<ClientEvent> ── receive(text, now_ms) ◀── transport
12//!   app ── poll_timeouts(now_ms) ──▶ retries, sync.ack, sync.resume
13//! ```
14//!
15//! Lifecycle: [`Session::hello`] → `session.welcome` verified against the configured host and
16//! community ([`ClientEvent::Welcome`]) → commands. After a reconnect the caller calls
17//! [`Session::hello`] again; unanswered commands are then resent with the same `request_id`
18//! and byte-identical body (§6.3, §7.3), and the caller sends [`Session::resume_request`].
19
20mod ack;
21mod config;
22mod cursors;
23mod decode;
24mod error;
25mod event;
26mod inbound;
27mod outbound;
28mod pending;
29mod retry;
30mod session;
31mod welcome;
32
33pub mod member;
34pub mod owner;
35
36pub use config::{ExpectedHost, SessionConfig};
37pub use cursors::{Cursor, CursorTable};
38pub use decode::decode_response;
39pub use error::{BuildError, ClientError, WelcomeError};
40pub use event::{ClientEvent, Gap, ProtocolError, ReceivedEvent, Response};
41pub use retry::RetryPolicy;
42pub use session::{ACK_LINGER_MS, Session, SessionState};
43pub use welcome::VerifiedWelcome;
44
45/// Default per-message text budget in UTF-8 bytes (§5.1). The real value is fixed by the
46/// transport adapter from `simplex_client::limits`; this crate never depends on it.
47pub const DEFAULT_TEXT_BUDGET: usize = 12_000;
48
49/// `type` of the coalesced event batch envelope (§10.5).
50pub const EVENTS_BATCH_TYPE: &str = "events";
51
52/// Capabilities this client offers in `session.hello` (§6.2): fragment reassembly.
53pub const CLIENT_CAPABILITIES: &[&str] = &["frag"];