syncspin
A Rust library for the Sendspin protocol: a client and a server. The server owns the clock and the stream, clients render the audio and report their state back. A host supplies the server's frames; it does not turn into a music server.
Status
0.2, both halves. The client is covered by a hermetic test suite, including pairing: the Pairing
PSK flow, the records it writes, the in-band re-handshake and server/unpair, plus the static and
dynamic code flows behind the pairing-code feature. The server accepts clients, owns one group and
its stream, serves the three roles, pairs with all three methods and discovers peers in both
directions. Its suites use a fake client that walks the specification, and one test runs the real
client against the real server so the two halves cannot agree on a bug unnoticed. 0.2 publishes
syncspin-server beside syncspin-core and syncspin-client from the same tag. The API may change
before 1.0. The CPace layer behind the code flows has not been reviewed externally, so it is
unaudited code until it has been.
syncspin is not an official Sendspin implementation and is not affiliated with the Sendspin
project; the name describes only the protocol the code speaks.
Crates
| Path | Contents |
|---|---|
crates/syncspin-core/ |
Noise handshake, framing, messages, clock filter. No transport, no device code. |
crates/syncspin-client/ |
Session loop, Sink trait, event stream, pairing and its Storage trait. |
crates/syncspin-server/ |
Listener, one group, roles, host-fed streams, pairing and discovery. |
examples/player-pipe/ |
Runnable reference player: PCM on stdout, status lines on stderr, pairing. |
examples/server-demo/ |
Runnable reference server: approves the first client and streams a tone. |
syncspin-core never depends on syncspin-client or syncspin-server; every protocol and crypto
decision lives in one place.
Getting started
[]
= "0.2"
= "0.2"
Every release is tagged, and the tag carries the source it was published from. syncspin-core is
published first; the other two depend on it through the registry.
The two examples can talk to each other, with no music server in between. Start the demo server and note the address it prints:
Then point the player at that address:
|
server-demo approves its first client, activates the roles it offered and streams a quiet 440 Hz
tone until Ctrl-C. It holds no files and decodes nothing; its identity is new on every run. The same
player talks to Music Assistant's Sendspin provider when --server names that endpoint instead.
Run cargo run -p player-pipe -- --help for the player name, the identity file and the pairing
store. The first run writes ./identity.key and ./pairing.json with owner-only permissions; later
runs reuse both. To pair the player, print its version-0 pairing token and enter it in the server:
The token is a credential: whoever holds it can pair a server with this client, so hand it over
directly and keep it out of logs and issues. A server that admits unpaired clients still accepts the
player as a guest. --features pairing-code adds --static-code and --open-window for the static
code flow.
Both examples are meant to be read. player-pipe/src/main.rs holds the event loop, the identity
handling and the pairing token, and player-pipe/src/pipe_sink.rs the Sink implementation.
server-demo/src/main.rs holds the approval gate, the event loop and the push data plane.
What works today
A connection reconnects on its own: when an attempt ends, the crate flushes the sink, reports
Event::Disconnected with the delay it applies (2 s at first, doubling up to
ClientConfig::max_backoff, and 1 s again after a session that connected) and tries again with the
same sink, identity, volume and mute state. It stops only when the audio sink fails or when the
handle or event stream is dropped.
ClientConfig::volume and ClientConfig::muted are the level and mute state the first client/state
carries. A host passes the values it restored, so the server never sees an invented baseline; a host
without stored values passes 100 and false. ControlHandle::set_volume returns the level that
was applied, and ControlHandle::volume reports the level in force without a call.
ClientConfig::volume_policy limits a request from the server or from the host. The default policy
is the rule clamp_volume implements: a request to 40 or below is applied as asked, and above 40 one
request may raise the level by at most 20. clamp_volume_with takes a policy, for a device that needs
a different guard. Event::Volume carries both the requested and the applied level, and the
client/state report carries the applied one.
ControlHandle::report_volume is the other direction: a host that reads the level its output is
actually at - because the device applied one at its own control, or because another process changed
it - reports it, and the next client/state carries it unchanged. The policy limits requests, not
the level the device is at, so a device the user raised to 70 while the threshold is 40 reports 70.
A level above the protocol maximum of 100 is refused and nothing is recorded or sent.
ClientConfig::device_info describes the machine the client runs on - product name, manufacturer,
software version and MAC address - and is announced in client/hello, so the server can show the
hardware rather than only the player name. A host that describes no device passes None.
The stream lifecycle is visible on the event stream: Event::StreamStart announces a new format,
Event::StreamEnd reports a pause or a removed player role, and Event::StreamClear reports a seek
with its timestamp. The end and clear events arrive before the client flushes the sink, so a host can
mute, stop or restart its output first; a reconnect flush produces no stream event. Event::Track
carries the now-playing metadata with the position, the duration and the playback speed in per-mille,
where 1000 is normal speed.
The server
syncspin-server listens on a configurable address and path, answers client/init with server/init
and runs the Noise handshake as its initiator over either cipher suite. A client/init it cannot
accept is answered with server/error and a close; a handshake that does not authenticate ends
without a further message. Each connection is reported to the host as it connects, is activated and
leaves.
One group holds every client. All members receive the same frames with the same playout timestamps,
the server answers each client's client/time burst, and a member that stops reading does not hold
up the others. The host pushes audio into a StreamWriter from ServerHandle::open_stream; the server
stamps every chunk from the configured format and fans it out without decoding. A client is given
player@v1 only when its player@v1_support lists that exact format, so nobody is sent a stream it
cannot play. Volume, mute and play/pause/stop belong to the group. The active roles are the three v1
roles a player needs: player@v1, controller@v1 and metadata@v1.
The server has its own pairing: PairingStore holds one record per client_id, an unpaired client
is held at empty activities until the operator approves it, and pair, start_pairing,
submit_code and unpair drive the token, static-code and dynamic-code flows. Discovery runs in both directions:
with a Discovery backend the server advertises _sendspin-server._tcp and dials the clients that
advertise _sendspin._tcp; the mdns feature carries the mdns-sd implementation.
Pairing
Pairing belongs to the host: it supplies a Storage with the
pairing PSK, the records of servers it has paired with, and the calls that read and write them. The
crate draws and persists the PSK on the first run, offers the Pairing PSK method on every connection,
and writes a record after server/pair-finalize; Event::Paired reports it. A record authenticates
the next connection, and the session survives the server's in-band re-handshake without dropping the
stream. server/unpair removes the record and arrives as Event::Unpaired; a server that names a
psk_id the client does not hold produces Event::PairingRequired once per connection. Without a
store the client offers no pairing method and runs as a guest — unless the host passes records
through connect_with_psks, which needs no store and still authenticates against them.
FileStorage is the optional JSON backend behind the storage-file feature, and the example uses
it. The crate writes at most five records into a store it manages, evicting the oldest first and
never the record backing the live connection; a store that already holds more is read as it is. That
order is insertion order, not use order, so a record kept since long ago can be evicted before one
used recently. Storage::store_pairing is the primitive, not the whole rule: calling it directly
skips the live-record pin, and FileStorage trims to five there only as a safety net while a host
backend may not trim at all. A host that writes a record itself calls the exported persist_pairing,
which applies both rules to any store, instead of reimplementing them.
With the pairing-code feature the client also runs the static and dynamic code flows, gated by a
pairing window the host opens or by the process-wide round limit. The dynamic flow shows the operator
a six-digit code or a version-1 token; both flows deliver the long-term key sealed under the CPace
output. The CPace layer is unaudited — see Status.
The server's side is symmetric. ServerConfig::storage is the host's PairingStore, keyed by
client_id; the listener seals a client's first handshake with the record it holds. A client with no
record is reported with approved: false, gets no roles and no audio, and stays that way until
ServerHandle::approve or a completed pairing. Event::PairingRequested asks the operator for a
code, Event::Paired reports the record, and ServerHandle::unpair removes it and disconnects.
Approval lasts as long as the server process; it is not written to a store and a restart asks again.
Discovery
connection.md gives a server two ways to reach a client and a client two ways to reach a server.
Both halves implement both. A server with a Discovery backend publishes
_sendspin-server._tcp with its bound port, path and name and browses _sendspin._tcp for the
clients it dials. The mdns feature carries an mdns-sd implementation for each crate; without a
backend the Discovery trait is the seam, so a test drives advertising with a fake and no multicast
socket is opened.
With the discovery feature the client can take the server-initiated half: instead of dialling a
server it advertises _sendspin._tcp through a host-supplied Discovery and accepts the server that
connects. Inbound carries the backend, the listen address (every interface on 8928 by default) and
the path (/sendspin by default); advertise publishes the record with the bound port and the
path and name TXT records, then serves the inbound WebSocket. An upgrade that carries an Origin
header is refused with a 403, as the spec requires, and the Noise handshake is unchanged: the server
is its initiator in both directions.
One server is served at a time. While ClientConfig::inbound is set the client does not dial, and
connect refuses: the spec lets a client use one of the two methods at a time, never both. A second
server that connects while one is admitted is rejected with client/goodbye reason
concurrent_attempt and closed, as the admission rule requires; it is not left waiting in the
listener's backlog. Nothing browses automatically on the client: the host chooses among the servers
it found and passes one URL to connect, which the spec leaves implementation-defined.
What does not work yet
- Unpaired access. The client always admits it:
client/hellocarriesunpaired_access: { enabled: true }unconditionally, there is no setting that turns it off, and nothing closes an unpaired connection with reasonpairing_required. A deliberate close sendsclient/goodbyewith a reason the host chooses. - Server scope. No queue, library, playlist, decoding, resampling, HTTP API or UI. The host owns the content and writes the frames; the crate owns the connection, clock, group and wire.
- Several groups. One group per server. An unavailable member stays in it and simply receives no
audio; there is no solo group and no
switchcommand cycle. - Roles. Only
player@v1,controller@v1andmetadata@v1. There are no other role versions and noartwork,visualizer,colororsourcerole. - Discovery persistence. Both crates browse and advertise, but the client does not persist the
server it last admitted with
playback, and the server keeps operator approval for its lifetime only. A restart asks the operator again. - Playout lead. Every member shares one timeline whose first sample is 200 ms after the stream
opens. The reported
required_lead_time_msandmin_buffer_msare read but do not move it. - TLS. No TLS stack: a
wss://address is rejected when the client is configured, and nothing is downgraded tows://. A TLS backend is out of scope for 0.2.
Pairing, discovery and the other departures from the specification are tracked with their reasons and the work that closes them in docs/spec-deviations.md.
Integrating a client
A host supplies a Sink: open for a new format, write for
every chunk with the playout deadline the client computed, flush at each boundary the crate
announces, and optionally latency and underruns so the client can hold its buffer and report
timing. The crate owns the connection, the clock and the reconnect loop; the host owns the output
device, the identity file and everything below the pipe. Pairing needs a
Storage as well; without one the client offers no pairing
method, and a host that already holds records can pass them to connect_with_psks instead.
let = connect.await?;
while let Some = events.next.await
handle.control() returns the play/pause/skip, volume and mute controls; dropping the handle or the
event stream ends the connection.
Integrating a server
A host supplies the server's identity, an optional
PairingStore and an optional
Discovery. Server::start binds the listener and hands
back a handle and an event stream. The host writes frames into the StreamWriter that
open_stream returns and follows the connections through the events:
let mut server = start.await?;
let mut events = server.events;
let mut stream = server.open_stream;
stream.write;
while let Some = events.next.await
An unapproved client reaches ClientConnected { approved: false } and gets no roles until
server.approve(&client_id).await?; a paired client arrives already approved.
server.set_volume, play, pause and stop change the group, and pair, start_pairing,
submit_code and unpair drive the pairing flows. examples/server-demo is the smallest complete
host, including the approval call; its source is short enough to read next to this section.
Related projects
Nothing to list yet. A sibling open-source client built on syncspin-client will be linked here
once it is public.
Documentation
docs/ indexes the protocol design, every known spec deviation and the testing
handbook.
Requirements
- MSRV 1.85, edition 2021.
- On the ARMv7 / glibc 2.24 target build with
cargo zigbuild --target armv7-unknown-linux-gnueabihf.opensslandringare out: the crypto stack issnow,x25519-dalek,elligator2and the RustCrypto primitives (chacha20poly1305,sha2,hmac) the pairing code flows need.
Licence
MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.