The station's interface
What a client (Rabbit Ears on a TV, Mac or phone; the Manager) can rely on from
Antenna Tower (tower/). The Swift-side merge and protocol types live in
Packages/Sources/RelayAdmin/ (AdminMerge.swift, RelayAdmin.swift).
Machine-readable: openapi.yaml. Conformance: the Go tower's
tests and Swift conformance suite (just tower-test, tower/conformance/) pin
each rule below alongside RelayAdminTests (AdminMergeTests, RelayAdminTests).
Finding a tower #
Bonjour service _retrotv-relay._tcp, port 8766, TXT v=1; the instance name
is the tower's name ("Mac mini"). The synced setting relay
({"host": "...", "port": 8766} as JSON in a Data) is tried first, Bonjour
second. Invites carry the host and port too.
Three kinds of caller, three kinds of key #
| Caller | Sends | Gets |
|---|---|---|
| a screen using the relay | X-RetroTV-Token: <household token> |
/v1/hello, /v1/feeds/*, /v1/vod/*, /v1/logs |
| a joined device | X-RetroTV-Admin: <the device's own key> |
/v1/admin/* |
| anything, to join | nothing, a code or the token, in the body | POST /v1/admin/pair, /enroll |
A device's key is 24 random bytes, base64url without padding. The tower keeps
only its SHA-256 (hex). The household token is the synced setting relayToken.
/v1/admin/* skips the token check: it has keys of its own.
Bodies #
/v1/hello, feeds, VOD: JSON. Dates are seconds since 1970./v1/admin/*: binary property lists (application/x-plist) both ways, because settings are UserDefaults values and a plist is the one format that keeps a Data apart from a String, a Date from a number. Request bodies that are empty are fine. An error is a status code with an empty body.- Value types that must survive: string, integer, real, bool, date, data, array, dictionary. A Codable setting is a Data of JSON; the tower never decodes it except to merge (below).
Who may do what #
A device has a list of profiles it can use (null = all). It is a manager
when one of those profiles is a manager (a profile with no manager flag is
one; "main" always exists). Managers may change settings and run commands.
Others may read settings and report what they play.
Not sent to a device with no manager: relay, relayToken, typesafeAPIKey.
Not sent to a screen (?app=screen): sportSettings, eventSchedules,
sportSchedule, sportJudged, sportGuides (the screen plays the sorted
channelSchedules).
Settings and revisions #
Every change to a synced key takes the next number of one counter (seq). A
client remembers the seq and epoch it saw and asks for what changed
since it. A different (or missing) epoch means the tower's history is
gone: it sends everything and the client starts over. A key the tower has
never had a value for is announced empty, with a number of its own, so clients
may change keys they've heard of.
PUT settings/{key} carries the base revision the change was made on. If it
is still the current one, the value (or its absence) is saved and takes the
next number. If not, 409 with the current {key, rev, value}; the client
merges three ways and tries again. Putting the value a key already has takes no
number.
The merge (admin package, AdminMerge.swift) #
base = what the device changed, mine = its value, theirs = the tower's.
Only one side changed: that side. Dictionaries (and JSON objects in a Data)
merge key by key. Lists take the tower's, less what the device removed, plus
what it added at the end; an item is known by its id if it has one, else by
its value; lists of items that have neither (nested lists, dictionaries with
no id) take the device's list. Anything else: the device's. Both tower and
client implement this: they must agree.
Synced keys #
The list is SettingsSync.keys (Packages/Sources/StationCore/Core/SettingsSync.swift).
The Go tower holds the shared source-of-truth JSON in
tower/internal/keys/synced-keys.json, verified against SettingsSync by
conformance tests (tower/conformance/swift_keys_test.go and SettingsSyncTests).
The R2 mirror #
Source: Packages/Sources/RelayAdmin/Mirror.swift, R2.swift;
decisions in ADR 0001. Everything in R2 is a binary plist sealed with
AES-256-GCM in CryptoKit's "combined" layout: 12-byte nonce, ciphertext,
16-byte tag; keys are base64 of 32 bytes. Requests are AWS SigV4, region
auto, service s3; reads send If-None-Match and treat 304 as unchanged.
| Bucket | Object | Written by | Sealed with | Holds |
|---|---|---|---|---|
rabbit-ears-settings |
settings/full |
tower | fullKey |
Snapshot, every key (devices with a manager) |
settings/watch |
tower | watchKey |
Snapshot less the manager-only and station-only keys | |
keys/<outbox> |
tower | the device's secret | KeyBundle (JSON) | |
history/<profile id> |
tower | the profile's key | History: {v: 1, keys: {<key>: {stamp, value?}}}, only keys that have changed |
|
rabbit-ears-outbox |
outbox/<outbox> |
the device | the device's secret | Outbox |
Snapshot (plist): {v: 1, changes: {epoch, seq, changes: [{key, rev, value?}]}, taken: {<outbox>: n}}.
changes is GET settings with since=0; taken is the last outbox entry
the tower took from each device, so a device can drop what's been delivered.
Outbox (plist): {v: 1, entries: [Entry]}, each {n, kind, key, ...} with n
counting up per device. By kind: setting adds baseRev, baseValue?,
value? (the revision and value the change was made to; applied directly if
baseRev is current, else three-way merged); history adds stamp (double,
seconds since 1970) and value?; playing adds stamp and value? (the item,
absent for nothing; believed for 90 seconds); checkIn has
value: {build, settingsVersion}. Only a manager's setting entries are applied,
only for synced keys; entries the tower doesn't understand are skipped.
Giving a device its way in. With the mirror on, GET device adds mirror
and keys (each JSON, as plist Data), and an invite becomes v: 2 with the
same two objects:
"mirror": {"read": {"endpoint": "https://<acct>.r2.cloudflarestorage.com", "accessKeyID": "..", "secret": ".."},
"outbox": {"endpoint": "..", "accessKeyID": "..", "secret": ".."},
"device": "<outbox name>", "secret": "<base64 32 bytes>"},
"keys": {"generation": 2, "settingsPath": "settings/full", "settingsKey": "..", "profileKeys": {"<profile id>": ".."}}
A device's outbox name and secret are made the first time it asks and never
change. Forgetting a device bumps generation, makes new sealing keys,
re-seals every other device's bundle, and deletes the forgotten device's
keys/ and outbox/ objects.
In the Go tower #
History (GET history, GET/PUT history/{key}, the history/<profile>
objects and outbox history entries) is kept in history.sqlite beside the
database (key, value as a wrapped plist, stamp real): the Swift tower used
UserDefaults, which can't be shared. A copy is taken only if its stamp is newer.
A device may only touch the keys of its own profiles (403 otherwise).
On when R2 keys are present: put r2-import.json (the Swift tower's format)
beside station-keys.json; with none, the mirror is off and GET device
carries no mirror or keys. Settings are written when the settings, the
entries taken or the keys change; outboxes are read every thirty seconds; a
device whose outbox doesn't open with its secret is ignored. Checked against
the real Swift code: CryptoKit opens what Go seals and the reverse, SigV4
matches AWS's worked example, and the real Mirror.swift decodes Go's
Snapshot, access and key bundle and wrote the Outbox fixture Go parses.
Historical migration note (Swift tower → Go tower). When migrating an
existing station from the retired Swift tower, the Go tower read the Swift
tower's station-keys.json as is (exported from the Mac Keychain item of the
same name); a fresh key file would make existing devices' outboxes fail to open.
On Demand in the Go tower #
hello.vod is true (vodPlay too, for the jobs). The catalog is built by the tower itself (no Swift jobs):
every login's whole movie and series lists (xtreamAccount, iptvProviders),
every Plex movie and TV library (plexSettings), merged by TMDB id then
cleaned name and year, only the categories onDemand.kept lists and the
languages onDemand.languages names, never adult ones. Refreshed daily, when
kept changes, and at start if a login has no part yet; a source that fails or
answers with nothing keeps its last copy. Kept on disk as vod-catalog.json
and vod-archive.json (shows and plots) beside the database.
| Route | Answer |
|---|---|
GET /v1/vod/sources |
[SourceSummary]; 404 until there is a catalog |
GET /v1/vod/sources/{id}/titles?category= |
[Title] in name order; the copy you browsed to stays when its source is hidden |
GET /v1/vod/search?q= |
at most 50 [Title], best first; [] for no match |
GET /v1/vod/shows/{id} |
Show: episodes merged across copies, fetched on first open, kept a day |
GET /v1/vod/titles/{id}/plot?season=&episode= |
{plot}; 404 when none |
GET /v1/vod/rows?n= |
the home screen's [Row] (n clamped to 4...60, default 20) |
GET /v1/vod/shelves |
[ShelfInfo]: every shelf and how much is on it, then each language with 25+ titles |
GET /v1/vod/shelves/{id}?kind=&offset=&limit= |
a shelf's [Title] (limit 1...200, default 60) |
GET /v1/vod/browse?kind=&genre=&service=&decade=&language=&sort=&offset=&limit= |
titles passing every part of the filter (sort: newest, rating, name; language * for all; limit default 120) |
GET /v1/vod/details/{tmdb} |
Details (plot, genres, runtime, cast...), looked up from a provider copy and kept 60 days |
GET /v1/vod/extras/{movies|series}/{tmdb} |
the collection here and the cast with more to watch; 404 without a TMDB key |
GET /v1/vod/people/{tmdb person id} |
the titles of theirs the catalog has |
GET /v1/vod/poster/{file}?w=185|342|500 |
TMDB's image, fetched once and kept; image/heic is its content type, though it is TMDB's JPEG on Linux, as in the Swift tower |
GET /v1/vod/subtitles?name=&lang=&tmdb=&year=&season=&episode= |
SubtitleTrack from OpenSubtitles, kept; 404 when none or no key |
POST /v1/vod/jobs |
starts or joins a fetch job: {port, length} or {refused}; the file is then served ranged at http://<tower>:<port>/<name>.<container> (no token: the player can't send one) |
GET /v1/vod/jobs, GET /v1/vod/jobs/{name}, DELETE /v1/vod/jobs/{name} |
all jobs; how one stands (asking keeps it going); end it and delete what it held |
The JSON is what the Swift Codable types encode (Origin as
{"xtream":{}}, {"xtream":{"provider":"x"}} or {"plex":{"server","section"}};
dates in seconds since 1970). Checked against the real Swift: its decoders read
Go's output, and VODIndex and the Go index agree on a shared catalog title
for title (internal/vod/testdata).
Errors, reports, storage and the tagger #
POST /v1/logs (OTLP/HTTP JSON; 415 for protobuf, 413 over 4 MB, 400 when not
logs) keeps warn and worse; POST /v1/traces is taken and dropped. Both need
the household token. GET errors, GET reports?status=&limit=,
GET/PUT reports/{id}, commands/storage, storage-clear, restart (the
tower quits, its service manager starts it again; 409 when it has none) and
commands/ondemand-tags, ondemand-tag, ondemand-seed are answered. The
tagger asks TypeSafe's Jev about each category once (typesafeAPIKey, or
TYPESAFE_API_KEY) and writes the picks back into the synced onDemand
setting (kept, categories), which the catalog refresh then follows.
The planes feed #
GET /v1/feeds/planes?box=minLat,minLon,maxLat,maxLon serves OpenSky's planes
from a cache, fetched for the boxes screens are watching as often as the day's
credits allow (a box costs 1 to 4 credits by area; 4,000 a day with a login,
400 without). A missing or unreadable box is the whole world, as in the Swift
relay. commands/opensky-login {clientID, clientSecret} saves a login if
OpenSky accepts it (both empty forgets it); it is kept in opensky-login.json
beside the keys, readable only by the tower's user. status carries the Relay
pane's view (relay, JSON: port, the feed's credits, the screens that asked).
Checked against the real Swift #
tower/conformance compiles the Swift clients' own code with swiftc and runs
them against a Go tower in-process: AdminClient (joining, settings and
conflicts, history, devices, invites, status; 27 checks) and RelayClient
with the RetroLineup types it decodes into (hello, planes, every On Demand
route over a catalog built from a fake provider, TMDB, OpenSubtitles and
poster server, and a fetch job read back ranged; 27 checks). They skip when
there is no swiftc.
Event and sports jobs, and the assistant #
The tower runs the station's jobs itself (no separate control room): event
schedules, the sports rules, Jev's review, channel linking and the epgshare01
guides, on the cadence in eventRefreshMinutes, when a Manager asks
(commands/refresh-events, or eventRefreshRequest), and when the lineup
changes. They read and write the synced settings (iptvLineup, sportSettings,
sportSchedule, sportJudged, sportGuides, eventSchedules,
channelSchedules) with compare-and-set, and publish eventRefreshStatus;
status carries events, refreshing and lastRefresh.
The assistant's MCP server listens on 127.0.0.1:8765 (-mcp, STATION_MCP;
off disables it). It serves the control room's full toolset: logins (add_login,
swap_login, remap_feeds), lineup and dial management (add_sport_channel
included), channel modules (MBTA, World, Video Store), On Demand's catalog,
sports, always-on channels, health/diagnostics, and job_status.
Phin Tech docs
Rabbit Ears Manager in the store →