From d0092e467a6fd383d7e1421d28a3efbb25da68a3 Mon Sep 17 00:00:00 2001 From: faumaray Date: Sat, 24 Oct 2026 07:27:49 +0300 Subject: [PATCH] Describe the session seam in the architecture document "The server link" is "The session seam": the registry, SessionLink and the vocabulary it shares with session.rs (crate-private now), what a session asks for in VoiceOptions, the TeamSpeak module (voelin_core::ts), StreamPort, the tests, and what is still TeamSpeak-shaped. The crate table row of voelin-core follows. Co-Authored-By: Claude Sonnet 5.5 --- docs/architecture.md | 204 +++++++++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 83 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index d6368a1..12374cf 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -72,7 +72,7 @@ fuzz/ cargo-fuzz targets | `voelin-store` | Identities (TeamSpeak, a Voelin key, the signed-in account, each with its account binding, as a `voelin-identity` `KeyStore`; see Identities), bookmarks, settings, chat history (dedupe, paging, sync cursors, where each chat was read), contacts, secrets (keyring / Android Keystore); versioned schema | done | | `voelin-audio` | Capture/playback, Opus, echo cancellation, resampling, jitter buffer, mixer, VAD/push-to-talk; the voice packet types (`TalkerId`, `VoicePacket`, `EncodedVoice`), so it depends on no voice transport | v0 (no AEC yet) | | `voelin-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam; its frame and simulcast layer types are `voelin-media`'s | sessions + transport | -| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, the `ServerLink` seam the voice source sits behind and the `voelin_proto::link::Session` the engine holds (`link/`: `SessionLink`, `Backends`; `ts_session.rs`: `TsLink` as a `Session`; both still in this crate), event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder); the stream types of its API are its own (`stream_types`, see Streams) | done | +| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, the session seam (the `voelin_proto::link::Session` the voice source is, `link/`: `SessionLink`, `Backends`, `VoiceOptions`; the TeamSpeak implementation of it in `ts/`: `TsConnector`, `versions`, `identity`, still in this crate and public as `voelin_core::ts`), event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder); the stream types of its API are its own (`stream_types`, see Streams) | done | | `voelin-ui` | Slint UI and the desktop binary: streams panel, viewer, share dialog, audio / hotkey / codec settings | done (desktop) | | `voelin-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs; the frame and simulcast layer types of a stream (`stream::EncodedFrame`, `LayerSpec`, `LayerId`, `LayerSet`) | done (desktop hardware encoders through FFmpeg loaded at runtime, not run on a GPU yet; MediaCodec not run on a device yet) | | `voelin-platform` | Global hotkeys, notifications, paths, crash reports, notices | done | @@ -87,93 +87,127 @@ the native command only when voice-connected *and* in that channel, otherwise th gateway, otherwise a local query relay. UI states: `Offline`, `Observing (Gateway|Query)` (invisible), `Connecting`, `Connected`. -## The server link +## The session seam A session's voice source, the connection that is visible on the server and -can talk, is a `voelin_core::link::ServerLink`, not a TeamSpeak connection -the session knows about. The trait has one method, -`spawn(options, ctx, cmds, events)`, which starts a connection on its own -task and returns: +can talk, is a `voelin_proto::link::Session`, the backend-neutral interface +that VoelinProtocol defines (`docs/protocol.md` section 1.3), not a +TeamSpeak connection that the session knows about. Nothing of `voelin-core` +above the TeamSpeak module names a TeamSpeak type: `rg 'tsclientlib|tsproto|voelin_query'` +over `crates/voelin-core/src` finds only `ts/` and the three files that +use them privately, `gateway.rs` and `query.rs` (the two observer sources, +which become a second `Session` to a gateway daemon later) and `stream.rs` +(the TeamSpeak 6 stream task, behind the `StreamPort` below). -- `options` is a `ConnectOptions` (the app calls it `VoiceOptions`): address, - nickname, password, channel to join, whether to open the audio devices; -- `ctx` is a `LinkCtx`: the session id, the event bus the link answers - requests on (file lists, transfers, offline messages, stream state), the - bus for the frames of watched streams, and the settings; -- `cmds` carries `LinkCmd`s in: chat, moves, mute, pokes, the encoded - voice frames from the audio thread, the file and offline-message requests, - `Stream(StreamCmd)` and `Disconnect`; -- `events` carries `LinkEvent`s out: `Connected` (name, `BackendInfo`, - `Capabilities`, our client id, the server's unique id), `Presence` (a full - snapshot each time), `OwnChannel`, `Chat`, `Poke`, `Audio` (a received - `VoicePacket`), `Talking`, `OwnStream`, `StreamAudio` (the audio of a watched - stream, for the audio thread's mixer), `StreamAudioEnded` (that stream's - audio is over), `Error` and `Disconnected`. `Disconnected` ends the - connection and is sent once, but it is not promised to be the last event: - the stream task of a connection winds down after the connection, so its - closing `OwnStream(Ended)` and `StreamAudioEnded` (and the bus events of - its streams) may follow it. `TsLink` ends the stream task as the - connection's loop ends, which usually puts them first, not always. The - session does not depend on it: on `Disconnected` it ends our own stream and - the audio of watched streams itself, and what the link says after that is - ignored like the events of a replaced link. +``` +UI ── Engine (Command / Event) ── session.rs (merge, dedup, history, contacts) + │ LinkCmd ↓ ↑ LinkEvent (crate-private) + SessionLink (replica, projection, media framing, + │ transfers, talk tracker) + │ Arc + pushes + MediaSink + │ (+ StreamPort for in-process connectors) + Backends ─────┼──────────────────────────┐ + (scheme registry) ▼ ▼ + ts::TsConnector → LinkSession any Connector: FakeConnector + (ts3server, teamspeak, no scheme) (tests), QuicConnector (later) +``` + +**The registry.** `voelin_core::Backends` holds the connectors by the scheme of +the address: `voelin_proto::link::Connectors` for plain connectors +(`Backends::register`) and the in-process ones that also hand the engine +local ports. An address without a scheme is a TeamSpeak bookmark and is +served as `ts3server`. `Engine::start` and `start_with` use +`Backends::default()`, which registers a `ts::TsConnector`; +`Engine::start_with_backends(settings, history, backends)` takes any +registry. An application that sets the main myTeamSpeak account keeps a +clone of its connector (`Backends::register_teamspeak`, +`TsConnector::set_myts_identity`, `TsConnector::set_myts_data`: every +connection of the connector, and its clones, presents it). + +**What a session asks for.** `Command::ConnectVoice` carries a `VoiceOptions`: +address, nickname, server password, channel to join and its password, +privilege key, whether to open the audio devices, the stream peer's network +settings, an `identity: Option` (a TeamSpeak identity as the key +store keeps it, see `ts::identity::to_blob`; a Voelin key goes the same way) +and a `client_version: Option` (a spec for `ts::versions::resolve`, +which only the TeamSpeak connector reads). `ObserveGateway` takes the identity +blob too, and `ObserveQuery` a `QueryLogin`. + +**SessionLink** (`link/session_link.rs`, with `project.rs` and `media.rs`) is +what `session.rs` talks to. It builds the connect parameters of the options +(`link/connect.rs`), opens the `Session` through `Backends`, runs the connect +sequence (the server, the HOME, SERVER and LIVE scopes, the seat in voice), +keeps a `voelin_model::replica::Replica` of what the host pushes, projects it +into the older model the UI still uses (`Presence`, `ClientInfo` and so on, +with the fix-ups F1 to F10 of [session-seam.md](session-seam.md)), frames +voice as RTP and derives who is talking from the media, copies the files of +transfers itself (progress, cancel, the picture limits) and turns every +`LinkCmd` into the `Session` call it stands for. `session.rs` and SessionLink +speak a vocabulary of their own, `LinkCmd` in and `LinkEvent` out, which is +crate-private (the module documentation of `link/session_link.rs` states its +contract): + +- `LinkCmd`: chat, moves, mute, pokes, the encoded voice frames from the + audio thread, the file and offline-message requests, `Stream(StreamCmd)` + and `Disconnect`; +- `LinkEvent`: `Connected` (name, `BackendInfo`, `Capabilities`, our client + id, the server's unique id), `Presence` (a full snapshot each time), + `OwnChannel`, `Chat`, `Poke`, `Audio` (a received `VoicePacket`), + `Talking`, `OwnStream`, `StreamAudio` (the audio of a watched stream, for + the audio thread's mixer), `StreamAudioEnded`, `Error` and `Disconnected`. + `Disconnected` ends the connection and is sent once, but it is not promised + to be the last event: the stream task of a connection winds down after it, + so its closing `OwnStream(Ended)` and `StreamAudioEnded` (and the bus + events of its streams) may follow. The session does not depend on it: on + `Disconnected` it ends our own stream and the audio of watched streams + itself, and what the connection says after that is ignored, like the + events of a replaced one (every connection has a generation). Everything backend-neutral stays in `session.rs`: merging the three sources, the dedup of a message that arrives twice, the chat history, contacts, the -privacy rules, the images and the gateway directory. The session tags each -link with a generation, so events of a replaced one are ignored. A link -reports what the server can do as `Capabilities`; with `streams` set it also -runs the stream task (`stream.rs`), which the session reaches only through -`LinkCmd::Stream(StreamCmd)` (start, stop, answer a viewer, watch, layers, -frames, friends, the gateway directory, shutdown) and which reports our own -stream's life back as `LinkEvent::OwnStream`. The stream task's requests -and the server's stream notifications never leave the link. +privacy rules, the images and the gateway directory. The answers that need +not pass the session first (file lists, transfers, offline messages, stream +state) go straight to the event bus, and the frames of watched streams to +`Engine::subscribe_frames`. -**The engine holds a `voelin_proto::link::Session`.** The `ServerLink` the -session spawns is the engine's own `link::SessionLink` (`link/session_link.rs`, -with `project.rs` and `media.rs`). It opens a `Session` through -`link::Backends`, the registry of connectors by address scheme, runs the -connect sequence (the server, the HOME, SERVER and LIVE scopes, the seat in -voice), keeps a `voelin_model::replica::Replica` of what the host pushes, -projects it into the older model the UI still uses (`Presence`, `ClientInfo` -and so on, with the fix-ups F1 to F10 of [session-seam.md](session-seam.md)), -frames voice as RTP and derives who is talking from the media, and turns each -`LinkCmd` into the `Session` call it stands for. `session.rs` is unchanged. -`TsLink` stays a `ServerLink` of the older vocabulary and is a `Session` too: -`ts_session.rs` wraps any `ServerLink` in a `LinkSession`, which writes the -link's snapshots, messages, pokes and voice as v1 entities, pushes and RTP and -answers requests with the link's help (`TsConnector` makes them for -`ts3server://` and `teamspeak://` addresses and addresses without a scheme). -TeamSpeak 6 streams are peer to peer, so their commands and events still pass -the session through a local `StreamPort`. See [session-seam.md](session-seam.md) -for the mapping row by row. +**The TeamSpeak module** (`voelin_core::ts`, `src/ts/`) is the TeamSpeak side +and is what moves to VoelinGateWay (`voelin-gateway-ts`). `ts_link.rs` and +`voice.rs` are the connection of `tsclientlib` (chat, voice, files, pokes, +offline messages and the stream task's requests), `book.rs` its presence from +the library's book, and `ts_session/` makes a `Session` of it: a +`LinkSession` writes the connection's snapshots, messages, pokes and voice as +v1 entities, pushes and RTP and answers requests with the connection's help, +and `TsConnector` makes them for `ts3server://` and `teamspeak://` +addresses and addresses without a scheme. The inner trait between them +(`ts_link::ServerLink`) is the module's own, and so are the TeamSpeak-typed +options it connects with. `versions` (the signed client versions a +TeamSpeak client may claim) and `identity` (reading and importing the official +clients' identities, the security level) are public, with `TsConnector`: +they are the only places of the crate's API that name `tsclientlib` and +`tsproto` types. -`Engine::start_with_backends(settings, history, backends)` takes the -connectors; `Engine::start_with_link(settings, history, link)` takes a link -and reaches it as a `Session` for every address; `Engine::start` and -`start_with` use `Backends::default()`, whose TeamSpeak connector has `TsLink` -(`ts_link.rs`), the TeamSpeak 3 and 6 connection of `tsclientlib`, inside: it -runs `voice.rs` with `book.rs`, `stream.rs`, `versions.rs` and `identity.rs`. -`tests/link_fake.rs` -drives the session with an in-memory link instead: it plays scripted -`LinkEvent`s (connect, presence, a message twice, a disconnect, a replaced -connection) and checks the presence, chat, dedup and history the session -makes of them, and the commands it gives back, with no TeamSpeak server or -crate involved. +**Streams.** TeamSpeak 6 streams are peer to peer and not v1 entities yet, so +their commands and events pass the session through a local `StreamPort` that +an in-process connector hands over: with `Capabilities::streams` set the +connection runs the stream task (`stream.rs`), which the session reaches +only through `LinkCmd::Stream(StreamCmd)` (start, stop, answer a viewer, +watch, layers, frames, friends, the gateway directory, shutdown) and which +reports our own stream's life back as `LinkEvent::OwnStream`. The stream +task's requests and the server's stream notifications never leave the +connection. When the session replaces a connection it gives the old one +`StreamCmd::Shutdown` before `Disconnect`. -Where this is going: `ServerLink` is this crate's interim seam. `TsLink` and -the modules it owns move to VoelinGateWay (`voelin-gateway-ts`, the -in-process TeamSpeak gateway), and the QUIC transport of VoelinProtocol -becomes the other implementation, both behind the backend-neutral -`voelin_proto::link::Session` that the protocol spec defines (the spec -replaces `voelin_core::link::ServerLink` by it, because the gateway -implements the trait and the client depends on the gateway). The seam is not -backend-neutral yet. What still has TeamSpeak types, or TeamSpeak's shape, and -changes when `TsLink` leaves: +**Tests.** `tests/session_fake.rs` drives the engine through +`Engine::start_with_backends` on the protocol repository's `FakeHost` and +`FakeSession`: presence, chat, dedup, history, transfers, a reconnect. The +unit tests of `link/` and `ts/ts_session/` check the mapping both ways with a +recording link inside, run the protocol's conformance suite against +`SessionLink` and, against the TeamSpeak development servers +(`VOELIN_LIVE=1`), against `TsConnector`. + +What is still TeamSpeak's shape, and changes when the TeamSpeak module +leaves (the second half of the decoupling): -- `ConnectOptions.identity` and `ConnectOptions.client_version` - (`tsclientlib` types), and the myTeamSpeak account proof in `LinkCtx` - (`myts_identity` of `tsproto`, `myts_data` of `tsclientlib`); - client ids are TeamSpeak's `u16`: our own in `Connected`, `Poke` and `Talking`, `LinkCmd::Poke`, a chat message's `author_id`, and the viewer and streamer ids of the stream API; @@ -181,10 +215,14 @@ changes when `TsLink` leaves: server and channel groups, talk power, icons, badges, the myTeamSpeak avatar; - the stream vocabulary of `voelin-stream` (the TeamSpeak 6 stream - protocol): `PeerConfig` in `ConnectOptions.stream_peer`, `MediaFrame` in + protocol): `PeerConfig` in `VoiceOptions.stream_peer`, `MediaFrame` in the frames of watched streams, `VideoFormat` in `StreamCmd::VideoFrame`, and `VideoCodec` and `FrameSource`, which `voelin_core::stream` - re-exports with them (see Streams, below). + re-exports with them (see Streams, below); +- the TeamSpeak module's ids and uids (`ts/ts_session/ids.rs` and + `entities::user_uid`) are the rule that SessionLink's projection undoes the + few synthetic ids of; it is the one place the engine reaches into `ts/` + besides `Backends::default`. ## What the engine tells of the server's software @@ -197,7 +235,7 @@ kinds, files, offline messages). The UI shows `product` on a server's chip and `BackendInfo::label()` in the status line, and branches on capabilities only. The TeamSpeak 3 / 6 classification (`voelin_model::ServerFlavor`, from the `virtualserver_version` string) happens in the voice source -(`voice.rs::backend_of`), which puts both in `LinkEvent::Connected`; no +(`ts/voice.rs::backend_of`), which puts both in `LinkEvent::Connected`; no `ServerFlavor` appears in the engine's public API, so another link (a Voelin server) can fill the same two fields. @@ -514,13 +552,13 @@ stream task converts what `Streams` reports, and what the UI asks for own types (its `StreamInfo`, `ViewerInfo`, `StreamSetup`, `SrtpProfile`, `EndReason`) no longer show in `Command` and `Event`. Still `voelin-stream`'s in the engine's API are the peer and media vocabulary: -`PeerConfig` (in `ConnectOptions`), `MediaFrame` (the frames of watched +`PeerConfig` (in `VoiceOptions`), `MediaFrame` (the frames of watched streams), `VideoFormat` and `VideoCodec` (on the `StreamSink`), `FrameSource`, `SyntheticSource`; they move out of the core with the stream task (the decoupling plan's next steps). In `voelin-core` a stream task per voice connection runs `Streams`. The link -owns the task (see [The server link](#the-server-link)): the TeamSpeak +owns the task (see [The session seam](#the-session-seam)): the TeamSpeak connection hands it the `MessageEvent`s as notifications and the clients' channels, and sends its requests; the session talks to it with `LinkCmd::Stream(StreamCmd)`. Encoders push frames through