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 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 07:27:49 +03:00
1 parent f63d459865
commit d0092e467a
1 file changed
+121 -83
+121 -83
View File
@@ -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-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-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-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-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-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 | | `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`, gateway, otherwise a local query relay. UI states: `Offline`,
`Observing (Gateway|Query)` (invisible), `Connecting`, `Connected`. `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 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 can talk, is a `voelin_proto::link::Session`, the backend-neutral interface
the session knows about. The trait has one method, that VoelinProtocol defines (`docs/protocol.md` section 1.3), not a
`spawn(options, ctx, cmds, events)`, which starts a connection on its own TeamSpeak connection that the session knows about. Nothing of `voelin-core`
task and returns: 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; UI ── Engine (Command / Event) ── session.rs (merge, dedup, history, contacts)
- `ctx` is a `LinkCtx`: the session id, the event bus the link answers │ LinkCmd ↓ ↑ LinkEvent (crate-private)
requests on (file lists, transfers, offline messages, stream state), the SessionLink (replica, projection, media framing,
bus for the frames of watched streams, and the settings; │ transfers, talk tracker)
- `cmds` carries `LinkCmd`s in: chat, moves, mute, pokes, the encoded │ Arc<dyn Session> + pushes + MediaSink
voice frames from the audio thread, the file and offline-message requests, │ (+ StreamPort for in-process connectors)
`Stream(StreamCmd)` and `Disconnect`; Backends ─────┼──────────────────────────┐
- `events` carries `LinkEvent`s out: `Connected` (name, `BackendInfo`, (scheme registry) ▼ ▼
`Capabilities`, our client id, the server's unique id), `Presence` (a full ts::TsConnector → LinkSession<TsLink> any Connector: FakeConnector
snapshot each time), `OwnChannel`, `Chat`, `Poke`, `Audio` (a received (ts3server, teamspeak, no scheme) (tests), QuicConnector (later)
`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 **The registry.** `voelin_core::Backends` holds the connectors by the scheme of
connection and is sent once, but it is not promised to be the last event: the address: `voelin_proto::link::Connectors` for plain connectors
the stream task of a connection winds down after the connection, so its (`Backends::register`) and the in-process ones that also hand the engine
closing `OwnStream(Ended)` and `StreamAudioEnded` (and the bus events of local ports. An address without a scheme is a TeamSpeak bookmark and is
its streams) may follow it. `TsLink` ends the stream task as the served as `ts3server`. `Engine::start` and `start_with` use
connection's loop ends, which usually puts them first, not always. The `Backends::default()`, which registers a `ts::TsConnector`;
session does not depend on it: on `Disconnected` it ends our own stream and `Engine::start_with_backends(settings, history, backends)` takes any
the audio of watched streams itself, and what the link says after that is registry. An application that sets the main myTeamSpeak account keeps a
ignored like the events of a replaced link. 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<IdentityBlob>` (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<String>` (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, Everything backend-neutral stays in `session.rs`: merging the three sources,
the dedup of a message that arrives twice, the chat history, contacts, the 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 privacy rules, the images and the gateway directory. The answers that need
link with a generation, so events of a replaced one are ignored. A link not pass the session first (file lists, transfers, offline messages, stream
reports what the server can do as `Capabilities`; with `streams` set it also state) go straight to the event bus, and the frames of watched streams to
runs the stream task (`stream.rs`), which the session reaches only through `Engine::subscribe_frames`.
`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.
**The engine holds a `voelin_proto::link::Session`.** The `ServerLink` the **The TeamSpeak module** (`voelin_core::ts`, `src/ts/`) is the TeamSpeak side
session spawns is the engine's own `link::SessionLink` (`link/session_link.rs`, and is what moves to VoelinGateWay (`voelin-gateway-ts`). `ts_link.rs` and
with `project.rs` and `media.rs`). It opens a `Session` through `voice.rs` are the connection of `tsclientlib` (chat, voice, files, pokes,
`link::Backends`, the registry of connectors by address scheme, runs the offline messages and the stream task's requests), `book.rs` its presence from
connect sequence (the server, the HOME, SERVER and LIVE scopes, the seat in the library's book, and `ts_session/` makes a `Session` of it: a
voice), keeps a `voelin_model::replica::Replica` of what the host pushes, `LinkSession` writes the connection's snapshots, messages, pokes and voice as
projects it into the older model the UI still uses (`Presence`, `ClientInfo` v1 entities, pushes and RTP and answers requests with the connection's help,
and so on, with the fix-ups F1 to F10 of [session-seam.md](session-seam.md)), and `TsConnector` makes them for `ts3server://` and `teamspeak://`
frames voice as RTP and derives who is talking from the media, and turns each addresses and addresses without a scheme. The inner trait between them
`LinkCmd` into the `Session` call it stands for. `session.rs` is unchanged. (`ts_link::ServerLink`) is the module's own, and so are the TeamSpeak-typed
`TsLink` stays a `ServerLink` of the older vocabulary and is a `Session` too: options it connects with. `versions` (the signed client versions a
`ts_session.rs` wraps any `ServerLink` in a `LinkSession`, which writes the TeamSpeak client may claim) and `identity` (reading and importing the official
link's snapshots, messages, pokes and voice as v1 entities, pushes and RTP and clients' identities, the security level) are public, with `TsConnector`:
answers requests with the link's help (`TsConnector` makes them for they are the only places of the crate's API that name `tsclientlib` and
`ts3server://` and `teamspeak://` addresses and addresses without a scheme). `tsproto` types.
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.
`Engine::start_with_backends(settings, history, backends)` takes the **Streams.** TeamSpeak 6 streams are peer to peer and not v1 entities yet, so
connectors; `Engine::start_with_link(settings, history, link)` takes a link their commands and events pass the session through a local `StreamPort` that
and reaches it as a `Session` for every address; `Engine::start` and an in-process connector hands over: with `Capabilities::streams` set the
`start_with` use `Backends::default()`, whose TeamSpeak connector has `TsLink` connection runs the stream task (`stream.rs`), which the session reaches
(`ts_link.rs`), the TeamSpeak 3 and 6 connection of `tsclientlib`, inside: it only through `LinkCmd::Stream(StreamCmd)` (start, stop, answer a viewer,
runs `voice.rs` with `book.rs`, `stream.rs`, `versions.rs` and `identity.rs`. watch, layers, frames, friends, the gateway directory, shutdown) and which
`tests/link_fake.rs` reports our own stream's life back as `LinkEvent::OwnStream`. The stream
drives the session with an in-memory link instead: it plays scripted task's requests and the server's stream notifications never leave the
`LinkEvent`s (connect, presence, a message twice, a disconnect, a replaced connection. When the session replaces a connection it gives the old one
connection) and checks the presence, chat, dedup and history the session `StreamCmd::Shutdown` before `Disconnect`.
makes of them, and the commands it gives back, with no TeamSpeak server or
crate involved.
Where this is going: `ServerLink` is this crate's interim seam. `TsLink` and **Tests.** `tests/session_fake.rs` drives the engine through
the modules it owns move to VoelinGateWay (`voelin-gateway-ts`, the `Engine::start_with_backends` on the protocol repository's `FakeHost` and
in-process TeamSpeak gateway), and the QUIC transport of VoelinProtocol `FakeSession`: presence, chat, dedup, history, transfers, a reconnect. The
becomes the other implementation, both behind the backend-neutral unit tests of `link/` and `ts/ts_session/` check the mapping both ways with a
`voelin_proto::link::Session` that the protocol spec defines (the spec recording link inside, run the protocol's conformance suite against
replaces `voelin_core::link::ServerLink` by it, because the gateway `SessionLink` and, against the TeamSpeak development servers
implements the trait and the client depends on the gateway). The seam is not (`VOELIN_LIVE=1`), against `TsConnector`.
backend-neutral yet. What still has TeamSpeak types, or TeamSpeak's shape, and
changes when `TsLink` leaves: 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 - client ids are TeamSpeak's `u16`: our own in `Connected`, `Poke` and
`Talking`, `LinkCmd::Poke`, a chat message's `author_id`, and the viewer `Talking`, `LinkCmd::Poke`, a chat message's `author_id`, and the viewer
and streamer ids of the stream API; 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 server and channel groups, talk power, icons, badges, the myTeamSpeak
avatar; avatar;
- the stream vocabulary of `voelin-stream` (the TeamSpeak 6 stream - 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`, the frames of watched streams, `VideoFormat` in `StreamCmd::VideoFrame`,
and `VideoCodec` and `FrameSource`, which `voelin_core::stream` 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 ## 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 and `BackendInfo::label()` in the status line, and branches on capabilities
only. The TeamSpeak 3 / 6 classification (`voelin_model::ServerFlavor`, from only. The TeamSpeak 3 / 6 classification (`voelin_model::ServerFlavor`, from
the `virtualserver_version` string) happens in the voice source 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 `ServerFlavor` appears in the engine's public API, so another link (a Voelin
server) can fill the same two fields. 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`, own types (its `StreamInfo`, `ViewerInfo`, `StreamSetup`, `SrtpProfile`,
`EndReason`) no longer show in `Command` and `Event`. Still `EndReason`) no longer show in `Command` and `Event`. Still
`voelin-stream`'s in the engine's API are the peer and media vocabulary: `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`), streams), `VideoFormat` and `VideoCodec` (on the `StreamSink`),
`FrameSource`, `SyntheticSource`; they move out of the core with the stream `FrameSource`, `SyntheticSource`; they move out of the core with the stream
task (the decoupling plan's next steps). task (the decoupling plan's next steps).
In `voelin-core` a stream task per voice connection runs `Streams`. The link 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' connection hands it the `MessageEvent`s as notifications and the clients'
channels, and sends its requests; the session talks to it with channels, and sends its requests; the session talks to it with
`LinkCmd::Stream(StreamCmd)`. Encoders push frames through `LinkCmd::Stream(StreamCmd)`. Encoders push frames through