Expand description
Pubsub watch — the receiver side of v1.3’s :gsoc-mine and
:pss-target writer verbs. PSS topic subscriptions and GSOC
(owner, identifier) subscriptions both connect to a Bee
WebSocket and emit message frames whenever a publisher hits the
corresponding /pss/send / SOC-upload endpoint.
The S15 Pubsub screen renders a merged timeline of all active
subscriptions; this module owns the subscription metadata + the
PubsubMessage shape that flows between the background watcher
tasks and the screen via an mpsc channel in App.
Structs§
- History
File - State backing the optional pubsub-history JSONL file. Tracks the
current write offset so the writer can rotate at a configured
size threshold without an extra
metadata()syscall per append. Held inside anArc<Mutex<_>>so every watcher task shares the same file handle + offset and serialises through the mutex. - Pubsub
Message - One delivered message — what the screen renders as a row.
Encodes both PSS (topic-keyed) and GSOC (address-keyed) variants
in a single shape so the merged timeline can render them
together, distinguished by
PubsubKindin the row glyph.
Enums§
Constants§
- MAX_
MESSAGES - Maximum number of messages the screen retains. Older messages
are evicted from the front (
VecDeque-style) so the cockpit’s memory stays bounded even on a noisy topic.
Functions§
- ascii_
preview - Convert a small byte payload to a printable-ASCII preview.
Replaces non-printable bytes with
.. Caps atcapcharacters. Used by the screen renderer for the inline content peek. - gsoc_
sub_ id - hex_
preview - Hex-prefix preview for binary payloads (when ASCII is mostly
dots). Caps at
capcharacters of hex (socap/2bytes). - open_
history_ writer - Open
pathfor append (O_CREATE | O_APPEND), creating it if it doesn’t exist.rotate_size_bytesandkeep_filesconfigure rotation: when a fresh append makes the file cross the size threshold, the active file is renamed topath.1(older rotations shift to.2,.3, …,.keep_files; oldest is dropped) and a new empty file takes its place. Passrotate_size_bytes = 0to disable rotation. Errors are surfaced to the caller so cockpit startup can log a clear “history file disabled:” message and keep the live tail going. - parse_
history_ line - Parse one JSONL history line into a
PubsubMessage. Public only for tests; the writer’s format is the contract. - pss_
sub_ id - Identity for an active subscription. Used as the key in
App’spubsub_subshashmap so re-issuing:pubsub-pss <topic>for an already-subscribed topic is detectable + cancellable. - replay_
history_ file - Read a previously-written pubsub history file back into a vector
of
PubsubMessages for replay onto the S15 timeline. Lines that fail to parse are logged + skipped so a single corrupt line doesn’t kill the whole replay. Caps the return atMAX_MESSAGES(the most recent N lines), since the screen can only render that many anyway. Returned in chronological order (oldest → newest). - smart_
preview - Pick the smarter of
ascii_preview/hex_previewfor a payload — ASCII when ≥ 75% of the bytes are printable, hex otherwise. Pure for testability. - spawn_
gsoc_ watcher - Spawn a background task that drives a GSOC subscription’s
recv()loop. Same shape asspawn_pss_watcher. - spawn_
pss_ watcher - Spawn a background task that drives a PSS subscription’s
recv()loop and forwards every delivered message intotxas aPubsubMessageuntilcancelfires. Returns immediately aftersubscribesucceeds; the actual recv loop runs on tokio.historyis the optional shared writer that appends every frame to a JSONL file on arrival.
Type Aliases§
- History
Writer - Optional history-file handle shared by every active subscription.
Nonewhen[pubsub].history_fileis unset;Some(handle)when the operator opted in. JSONL appends and rotation are serialised through the mutex so concurrent watchers don’t tear lines.