Commit graph sonda/internal/federation
Author SHA1 Message Date
tgiachi
7243fe7a04 feat: the seek bar shows the waveform of a friend's track
A friend's server works out the peaks of a track in a shared library and gives
them to a signed friend (GET /peer/tracks/{id}/peaks). This server asks for them
and passes them on to the listener after checking them: 1 to 1000 levels from 0
to 255, as many as the count says (GET /friends/{friend}/tracks/{id}/peaks). The
player uses it for a friend's track, so its bar is no longer flat.
2026-11-13 19:46:37 +01:00
tgiachi
7f38ae038e feat(federation): play a friend's music and show its covers through this server
A listener can now play the music of a friend from the web app.

- GET /friends/{friend}/tracks/{id}/stream and /friends/{friend}/albums/{id}/cover,
  in the group that accepts the access token in the query, like the local ones.
  This server asks the friend with a signed request and passes the bytes on,
  forwarding Range and the conditional headers, so a player can seek. The
  friend sees this server and never the listener.
- Only audio (for a stream) and a JPEG (for a cover) are passed on, with a
  fixed set of headers: Content-Type, Content-Length, Content-Range,
  Accept-Ranges, Last-Modified and ETag. Anything else a friend sends, or
  what a listener's request carries (cookies, authorization), is not passed
  either way, so a friend cannot make this server serve anything else.
- The client of friends can open a streaming answer: no limit on its whole
  length, one only on its beginning, no redirect followed, and it ends when
  the listener leaves.
- The player holds a friend's track next to the local ones. It streams
  through this server, shows the friend's cover, links to the music of the
  friend and not to a local page, is told apart from a local track with the
  same id, and is never reported as a listen: it does not feed taste.
- The songs of a friend have play buttons, the albums their covers.
- OpenAPI paths, contract test, and two real servers checked end to end: the
  bytes of the file arrive unchanged, with ranges, and a song plays in a
  browser from the friend's server through the other one.
2026-11-13 16:11:59 +01:00
tgiachi
29bd46c3ba feat(federation): browse and search a friend's catalogue
A listener can now browse the music that a friend's server shares.

- GET /friends lists the friends both admins agreed to, by id and name; an
  address or a key is for the admin only. It is empty while federation is off.
- GET /friends/{friend}/artists, albums and tracks (q, limit, offset,
  artist_id, album_id) and the one-item routes: this server asks the friend
  with a request signed by its own key and passes the page on. The answer is
  read into this API's own types first, so what a friend adds is dropped and
  the shape is the one in the spec. Nothing is kept, and the ids are the
  friend's own.
- Only the three kinds of thing can be asked, and only the parameters their
  routes take: a listener cannot make this server ask a friend for anything
  else. The friend's address and what the connection said never reach a
  listener.
- A friend that cannot be reached, no longer takes this server for a friend,
  is busy or is not there is told in words, never as an error page.
- The client of friends gets a generic signed GET with a size limit.
- The web app has a Friends entry in the menu, shown only when there is a
  friend to browse, a list of friends and a page for each with artists,
  albums and songs, a search and links from an artist to its albums and from
  an album to its songs, in English and Italian.
- OpenAPI paths and schemas, contract test with a friend that is a whole
  server, and two real servers checked end to end.
2026-11-13 15:59:26 +01:00
tgiachi
89826fcd07 feat(federation): shared libraries and the signed read API for friends
A friend's server can now read what an admin chose to share.

- A library has a shared flag, off by default (migration 0024), set with
  PATCH /libraries/{id}. Changing it never waits for a scan.
- Requests between friends are signed with each server's Ed25519 key: the
  method, the path and query from /api/v1/peer on, a date, a nonce and the
  hash of the empty body. A date more than two minutes off, a nonce used
  before, an unknown or removed key and a bad signature all get the same
  401. A friend still waiting for approval gets 403, and while federation is
  off the routes are missing.
- Routes under /api/v1/peer: info, artists, albums, tracks, covers and
  streaming with Range. The catalogue, the counts and the format come from
  the shared libraries only, and the file served is the one in a shared
  library. No path, library id, listen, taste, user or provider data is part
  of an answer.
- A friend never makes this server build a cover, read an audio file or ask
  a provider: only covers already built from the audio files are served.
- Per-friend limits, set by the admin: parallel streams (default 3) and KiB
  a second (default 4096, 0 for none), shared by all the streams of a friend.
- A log of the last requests friends made (route, status, bytes; never the
  query), kept for 7 days, in GET /federation/requests.
- POST /federation/friends/{id}/check lets the side that pasted an invite
  find out that the other admin approved; a signed call from a friend this
  server is waiting for makes it active too.
- Admin: a Shared with friends switch on each library, which asks first, and
  limits, recent requests and a Check button in the Federation section, in
  English and Italian.
- OpenAPI paths and schemas, contract test, two real servers checked end to
  end with tagged audio files.
2026-11-13 15:04:07 +01:00
tgiachi
695a012f6c feat(federation): keys, invites and pairing between Sonda servers
Two servers can become friends. Federation is off by default; turning it
on makes an Ed25519 key pair, kept in the database and never returned.

- Admin routes: GET and PUT /federation (on or off, name, public address),
  POST /federation/invites, POST /federation/friends (use an invite),
  POST /federation/friends/{id}/approve and DELETE /federation/friends/{id}.
- POST /api/v1/peer/pair, the one route without a login: the code of an
  invite is the proof. An invite works once and expires in 24 hours; only
  a hash of its code is stored. At most 10 attempts a minute.
- The server that uses an invite checks that the key it gets back is the
  one named in the invite. A friend is kept as incoming or outgoing until
  both admins have agreed.
- https only, except plain http on a network of one's own (private,
  loopback or link-local address, or a local name).
- A client of its own for friends, with no redirects, no proxy from the
  environment, a size limit and a time limit; the providers' client stays
  as it is.
- Migration 0023 for SQLite and PostgreSQL, OpenAPI paths and schemas,
  contract test with two real servers.
- Admin > Federation in the web app, in English and Italian, and a
  section in the README.
2026-11-13 14:43:48 +01:00