Files
Aemeath ac90575b0b
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions
Dawnline 0.20.0
- **Backend rewritten in Go.** One daemon, `dawnlined`, replaces the whole ucode backend: the rpcd plugin, the agent, the CLI and the updater. The package no longer depends on ucode.
- **Per-architecture builds.** The release carries the backend for arm64, ARMv7, mips, mipsle and amd64; the router fetches its own after the package is installed and checks its sha256. Dawnline does not run on other architectures (older ARM, 32-bit x86, RISC-V).
- **Faster on the router.** A firewall sync takes 0.06 s instead of 0.9 s; a full apply takes about 300 ms. The portal is served by the daemon itself, without a CGI process per request.
- **Live pages.** The admin and the portal follow a live stream from the router instead of re-fetching the whole state every 30 seconds.
- **Admin redesigned in the portal's style.** Three sections (Overview · Log · Settings); a server is a page of its own with People, Places and Settings; a device opens as a dialog over its person.
- **Changes wait for «Apply».** Every setting, and a person's access, is staged in one dock before it reaches the router.
- **Configuration rollout.** After a change that makes devices fetch their configuration again, the admin shows how many have fetched it and who has not. Every setting shows beforehand (⟳N) how many devices it will touch.
- **Waiting for a decision.** Overview and People put first the people who need one (access ended, limit reached, a device that does not connect), each with its one action a tap away.
- **Bulk actions on people.** «Select» (or a long press on a card) picks several people to extend by a month, pause or resume at once.
- **Undo.** An action done from a card or a request is undone from its toast.
- **Update dialogs redesigned.** An update is one view from its question to its result; Dawnline's own update runs in it like every other, and the page reloads itself once the new version answers. Other versions are a list, each with its notes and Install on a page of its own.
- **Site to site: networks behind a router.** A router connected as a device can have networks behind it (up to eight, /16 to /30): the server routes them and applies the router's access to them. A network that shares addresses with a tunnel, the router's own networks or another site is refused by name.
- **Routers from the portal.** People can add a router and name its networks on their own page; the admin accepts or declines with a reason, or lets them through without asking.
- **Check access and Health know the networks behind routers.**
- **Usage limits reworked.** A monthly limit no longer follows the calendar. A person's month starts with their first traffic and ends a month later; the next one starts only when they connect again, so time away uses up none of it. Before, everyone's limit reset on the 1st.
- Extra data lasts until that person's month ends; «Reset usage» starts the month anew.
- A limit is for a month or for the whole term; the admin and the portal show when it resets.
- Charts that said «this month» show the last 30 days.
- After the update nobody loses what was counted: the month that was running becomes the person's first and ends on the 1st.
- **Access by time of day removed.** The Hours limit is gone from the admin, the portal and the backend; saved hours are dropped.
- **Expiry simplified.** An end date always stops access, with a heads-up three days before; the per-person choice is gone.
- **No false disconnects from sleeping phones.** A phone or a tablet stays online through ten minutes of silence.
- **Mobile Safari fixes.** Pressing a control no longer sends the page to its top; tab tracks that do not fit scroll; switches animate after a press.
2026-11-13 09:43:50 +03:00

230 lines
70 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# The Go backend and the live stream
Where Dawnline's backend is going, what is built, and the order of the rest. Read with `rules/backend-go.md` (how the Go code is written) and `rules/frontend.md` › Live data.
## Why
Three things are wrong with the ucode backend, and they have one cause: nothing in it stays running with the state in memory.
- **Every page asks for everything.** The admin fetches `status` (the whole model: every server, person, device, counter and the last 60 events) every 30 s and on each move of a revision it polls every 2 s. The answer is one document, so a page cannot know what changed in it and rebuilds what it shows. One open tab costs a `rev` call every 2 s for nothing.
- **The portal pays 140 ms of CPU per request before any work** (a CGI process compiles the module graph), so it does not follow anything: it loads once and polls only while a set-up sheet is open.
- **State is passed between processes as files** (`presence.json`, `meter.want`, `usage.reset`, …), each with its own lock, format and staleness rule.
The target is what podkop-exp did to podkop's shell backend, for the same reasons: **one long-running Go program** that holds the state, with packages that each have one job, and the pages following it over **a stream of changes** instead of asking again.
## Target
```
┌──────────────────────────── dawnlined (Go, procd) ────────────────────────────┐
LuCI admin ── uhttpd /ubus ── rpcd ACL ── ubus ──┤ api ──┐ │
(shared/live) calls + event stream │ ├── hub ◄── producers: watch, usage, log, │
portal ───────── HTTPS (own listener) ───────────┤ portal┘ ▲ people, servers, health, … │
(shared/live) calls + event stream │ │ │
dawnline CLI ──── unix socket ───────────────────┤ ctl └── model ◄── uci (/etc/config/dawnline)
│ apply ──► awg, nft, netifd, fw │
└──────────────────────────────────────────────────┘
```
- **`hub`** holds the live state as named documents (*topics*) and publishes each change as a numbered event. It knows no transport and owns no data.
- **Producers** own the data: one goroutine each, or one supervisor loop for everything that changes the router (one writer per resource, as today, without lock files).
- **`api`** (admin, over ubus) and **`portal`** (people, over its own HTTPS listener) are doors onto the hub plus the commands. The admin stays a LuCI page: its login, sessions and access lists are rpcd's.
- The settings stay `/etc/config/dawnline` in today's format. Nothing a user has changes with the backend's language.
## The stream
The same protocol over both doors; `web/src/shared/live` is its client.
**Topics.** A topic is a JSON document: `people`, `servers`, `traffic`, `meter`, … A list of things that have an id is published as a *keyed list*, `{ "order": [ids], "items": { id: {…} } }`, so one entry changing does not resend the list. A daily series is keyed by its `day` the same way: on a real router the arrays of days were most of what a minute's refresh resent.
**Events.** Every change of every topic is one event, numbered from 1 in the order it happened: `{ seq, topic, op, data }`.
| `op` | `data` | |
|---|---|---|
| `put` | the document | first time, or it is not an object |
| `patch` | a JSON Merge Patch (RFC 7396) | only the fields that changed; `null` removes one. Documents hold no `null` |
| `append` | `{ items, keep }` | new entries of a list (a log, the meter's points); the list holds its newest `keep` |
| `drop` | — | the topic is gone |
A producer puts a whole document as often as it likes; the hub works out the patch and publishes nothing when nothing changed. Producers never write patches by hand.
**Following.** A page takes a snapshot once (`sync` with no position → `{ epoch, seq, docs }`), then applies events in order. The next event is always `seq + 1`. Anything else (a number skipped, another `epoch`: the backend restarted) means *ask where we are*: `sync { epoch, seq }` answers with the events missed (the last 512 are kept) or a new snapshot. A page is therefore never wrong for longer than it takes to notice, and never needs "refresh everything" logic of its own.
**Two transports, same events, same numbers:**
- **Event stream** (SSE): `GET /ubus/subscribe/dawnline` with the session as a Bearer token. uhttpd turns the object's ubus notifications (`event`, and `ping` every 15 s of silence, carrying the current `seq`) into `text/event-stream`. Used where uhttpd can hold one.
- **Held call** (long poll): `wait { epoch, seq, timeout }` answers when there is an event. Works through any web server LuCI runs on.
`hello` says which to use. **uhttpd before 2026-08-03 leaks every subscription's connection** (fixed upstream in `3c48b9e`; the 24.10.6 and 25.12.3 images ship a uhttpd from before it, 25.12.5 one from after) and stops serving once `max_connections` of them are open, so the stream is used only where the installed uhttpd has the fix; a page also gives a stream up for the held call after it fails twice. Today the choice is `dawnlined -stream sse|poll` and defaults to `poll`; stage 2 has the init script set it from the installed uhttpd's version. Not WebSocket: uhttpd has none, and nothing here is said from the page to the router that a plain call does not say better.
**Only while someone looks.** Each question renews a 30 s lease on the topics it names; subscribers count too. Producers that cost something (the 1-second meter) run only for topics under a lease (`watch { topics }`, renewed by the page every 10 s). No page open: nothing is read for the pages at all. **The meter is the exception since 2026-11-12:** its points cost nothing more to make (the watcher looks at the tunnels every second whoever is there), so the `meter` topic is kept current always and a page has the last two minutes in the answer that starts its look; only the old `meter.json` file is still written under a lease.
**Commands** (creating a device, changing a setting) are calls that answer with their result and the `seq` their change is visible at. The page does not refetch after a command: the change arrives on the stream like anyone else's.
### On the page
- `signal.ts`: signals (`signal`, `computed`, `effect`, `batch`). A text node, an attribute or a list reads the signals it shows inside an effect; only that effect runs when one moves.
- `store.ts`: the topics' documents. `store.at('people', 'items', id, 'online')` is a signal for that one place. Patches are applied with structural sharing, so a part that did not change is the same object and its readers are not told.
- `follow.ts`: the rules above over a `Transport`; pauses while the page is hidden, catches up when it is shown.
This is what replaces "fetch `status`, rebuild the box": a person's card binds its name, its state and each device's `online` to their places, and a device connecting changes one dot.
### Loading: pending, ready, stale
Every topic has a state the page can read (`store.state(topic)`), and that is the whole model for what a page shows before and without data:
| state | means | the page shows |
|---|---|---|
| `pending` | nothing came yet | the page waits under its section row, then comes in whole; not "empty" and not a spinner over the whole page |
| `ready` | the router's document, followed live | the data |
| `stale` | the last document seen, and the stream is down | the data, marked as old; **never** hidden behind a wait the page does not need |
With it the admin's `load()` no longer waits for `status` under LuCI's spinner: the section row stands at once and the page comes in when its answer has come, its blocks rising as the portal's do (`DESIGN.md` › Motion › 16, `rules/frontend.md`). The admin had skeletons (skullet) for a day, 2026-11-12; the owner had them taken out the same day in favour of that entrance. A backend that was just started used to tell its first topics only with the bridge's next Refresh (measured after a deploy, 2026-11-12: every question answered by 2.6 s, the stream's first events at 22 s); that is fixed in the bridge (*Told as the router is at that moment*, below: about 1 s now). The page keeps its own guard all the same: while it waits for its first status it asks for the snapshot itself every 700 ms (`state/stream.ts streamStatus`: `refresh` + `sync`) and takes whichever comes first. The portal's first paint can go further: the backend can put the person's state into the HTML it serves, so there is nothing to wait for (stage 3).
## Stages
Each stage ships and runs on the router; the ucode it replaces is deleted in the same stage.
| | Stage | State |
|---|---|---|
| 1 | **The stream.** `dawnlined` with `ubus`, `hub`, `api`; topics filled by `bridge`, which asks the ucode backend (`luci.dawnline status`, `meter`) once for all pages, only on a change, and republishes the answer cut into topics. Client: `shared/live`. | **Done.** |
| 2 | **The admin on the stream.** | **Half done:** the backend runs on the router as the service's `backend` instance (deploy builds it for the router's processor); `api.status` and `api.meter` are answered from the stream and `state/live.ts` follows it instead of polling `rev` (`state/stream.ts`, `transport.ts`, `join.ts`), with the old asking kept for a router without the backend. **Left:** pages bind to the store directly instead of reading a whole `Status` (then `join.ts`, the pollers and the fallback go); the other answers pages still ask for (`health`, `service_log`, `events`, `settings_get`, `updates_status`) become topics; the release packages carry the backend for every architecture. |
| 3 | **The portal in the backend.** `dawnlined` serves the portal itself (HTTPS with Go's TLS, the assets, the API, the person's stream): no CGI, no second uhttpd, no `openssl`/libustream dependency for it. | **Serving on the development router, behind a marker** (`/etc/dawnline/backend-portal`; the init script then starts no portal uhttpd and hands the port, the certificate and the process count to `dawnlined`). `backend/portal`: the door (what is no personal link gets the bare 404 or the redirect from this process, nothing is started for a scanner), the ucode portal behind it as CGI exactly as uhttpd ran it (a few at a time), the certificate read again when its file changes (a renewal restarts nothing), and **the page's stream** `GET /<code>/api/live`: the page's state whole (`put`), then a merge patch of what changed (`patch`), `gone` when the link stops working. The state is the ucode portal's own `/api/state` for that visitor, asked again only when the person's revision, the settings, a set-up or (once a minute) the counters moved. The page follows it when its shell says a stream waits (`data-live`, `web/src/portal/live.ts`); before, it asked once and never again. Held by a test against the real ucode portal in both OpenWrt rootfs images (`scripts/backend-container.sh`). The binary grew from 4.1 to 7.3 MB with `net/http` and TLS. **Left:** the API itself in Go (stage 5: then no CGI), the portal's loading states, making it the default. |
| 4 | **The watcher.** `awg` (the tunnels' peers), presence, link trouble, the meter, usage and the activity log move from the agent into producers; their files in `/var/run/dawnline` and the bridge's `status` call go. | **In charge on the development router, behind a marker:** `backend/watch` runs `awg`, `presence`, `link`, `meter`, `usage` and `journal` every second and writes what the ucode that remains reads; the agent's watcher stands by while `backend.beat` is fresh and takes everything back within a second of it going stale (`/etc/dawnline/backend-watch` turns it on; `backend-shadow` instead only compares). Each part is held to ucode's own output (`scripts/ucode-golden.sh`: the model on two fixtures, the link step for step over 36 000 made-up reads, the counters after 400 made-up looks). **Left:** make it the default once it has run for days on real traffic; then `status` is put together from the topics instead of asked from ucode, and the files go with the ucode that reads them (stage 5). |
| 5 | **The model and apply.** `uci` and `model` (read and the one writer), then `apply` (awg, nft, netifd, firewall, the netns path) under one supervisor loop; the RPC methods move from `luci.dawnline` to `dawnline` as their part lands. The ucode agent, rpcd plugin and CLI are deleted. | **Begun:** `backend/uci` reads the file as libuci does; `backend/model` reads it exactly as `dawnline.core load()` does, held to ucode's own output on two fixtures (`scripts/ucode-golden.sh`), and works out a server's address, MTU and DNS as `dawnline.core` does (`derived.go`); `backend/ipnet` reads and collapses networks as `dawnline.util` and `dawnline.net` do; `backend/handout` makes a device's configuration and its fingerprint, character for character what `dawnline.awg client_config` and `config_fingerprint` make for 24 devices across plain WireGuard, the junk-only disguise and the 3.1 one, every kind of access, a device with its own network kept outside, and home networks from two interfaces made up in the golden's container. `backend/state` says where a person stands (paused, past the end date, over the limit, no server, server off) and what they used of what limit, as `dawnline.core person_state` does for 10 people at 10 moments. `backend/netview` finds the router's interfaces, its WAN and LAN and each person's home networks as `dawnline.net` and `core.person_home` do, from what a router made up in the golden's container said (a bridge with ports, a guest interface, a VPN client, a placeholder). With the watcher on, `backend/roster` makes the people of every `status` ucode answers from these and compares the two field by field (topic `roster`, and the log where they differ for three looks): on the development router, 2026-11-12, three people and six devices, no difference; the same for the router's sums, its 60 days and its last 24 hours, and what of a server's view follows from the settings, the tunnels and the counters (its peers and who of them is online, its MTUs, address, DNS, its people's days). While they agree, **the stream's `people` topic is Go's own**: put the moment the watcher sees someone come, leave or move (no call to ucode stands between the event and the page), and again with each status for the counters; the bridge leaves that topic alone (`bridge.Own`), and takes it back the moment a difference holds for three looks. The same now holds for `traffic`, `services`, `circles` and `recent` (the log's newest sixty, with home names): Go's own, on the same terms. So are the `places` (a point for each address a device was seen from, the router's own addresses left out: 35 points on the development router, the same as ucode's). And the `servers`, whole (their interface's state from netifd, their home interfaces, their disguise as shown, the proof that the port is reached from outside), while none of them is kept down: why one is, is a sentence in the reader's language that only ucode writes yet, and with one kept down the topic is ucode's again. And **what changes only those no longer asks ucode anything** (`bridge.Quiet`): someone coming or going, the counters, a line of the log. And the `router` and `clock` topics (the version, the hostname, the offset from UTC, the settings as shown, the home-like path's state from `loop.json`, what of AmneziaWG is installed and loaded, what it can do as ucode last worked it out in `awg-caps.json`, the public address): on the development router the topic Go put was byte for byte the one ucode's status gave. **With every topic Go's own, ucode's `status` is no longer asked for the pages at all**: Go tells its topics again every 30 s while someone looks (`bridge.Tell`: the counters, the uptimes and the clock move with no event), and ucode is asked only when the settings or the configurations handed out change and every 10 minutes (`bridge.Audit`), to be compared with (on the development router: not once in 70 s with a page open, where it was every 30 s). Why a server is kept down and why the home-like path was refused are worded by Go too, as ucode words them for a reader with no language (`roster/router.go`), the disguise values AmneziaWG cannot take named one by one: `backend/disguise` is `obf_unsafe`, sentence for sentence on 32 made-up sets of values. What AmneziaWG can do is worked out by Go itself (`backend/awg/caps.go`: the protocol script, the tool, the module's package version, an update that waits for a reboot; `gen`, `pending` and `running_gen` held to ucode on 14 versions and 144 runs), the same on the development router as ucode's. **Nothing of `status` is ucode's alone any more.** It is still asked on a change of the settings and every 10 minutes, only to be compared with. **Left:** the comparison and the bridge go once the roster has run for days; then the RPC methods, the writer and apply. **The methods move one by one** (`backend/methods`): the Go object answers a question with the arguments and the answer `luci.dawnline` has for it, a failure as `{ error }` in the page's language; `hello` names the questions it answers (`methods`), and the admin's one `call()` then asks them of `dawnline` instead (`web/src/admin/api.ts`), so a router without the Go watcher keeps asking ucode. The access list names each (read: `events`, `person_usage`; admins only: `person_links`). First three, 2026-11-12: `events`, `person_usage`, `person_links`; on the development router 17 questions asked of both backends (filters, limits, every person, an unknown one in Russian) got the same answers. The language is Go's own reading of LuCI's catalogs (`backend/i18n`: the lookup and the plural rules as `luci.core` answers from two catalogs made for the test). Then `device_config` (admins only; the server's IP for the apps that take no name comes from `backend/resolve`: the public resolvers before the router's own, A and AAAA at once, answers kept five minutes), `service_log` (the watchdog's targets in the file's order, their names in the page's language) and `backup_list`: ten more questions, every device's configuration among them, the same from both. Then `settings_get` (the settings as written and as they take effect, the packages a feature misses, the portal's certificate and when it ends as `openssl` writes it, the TCP ports taken and by whom from `netstat` and the firewall's forwards, what the log and the history hold) and `backup_read` (admins only): six questions, the same from both, 14 taken ports and the ACME certificate among them. Known difference: a port forward with neither a name nor a section name is called by its place, not by libuci's made-up name. Then `server_ports` (the UDP ports a server cannot take: the other servers, the router's own tunnels, what `/proc/net/udp` has bound and whose it is, forwards; the networks a tunnel network must not overlap): 15 UDP ports, 14 TCP ports and 3 networks, the same from both. Then `interfaces`: `backend/netview` now makes the whole of `dawnline.net`'s snapshot (each interface's category, whether it is up, its bridge and a bridge's ports, its addresses, its firewall zone by device or by network, every zone's name) and what a server uses of it (`ServerNet`: its WAN, its home interfaces with their zones, a saved one that is gone), the same as ucode on the golden's router with two more zones made up for it, and on the development router's ten interfaces through netifd. Then `updates_status` (the firmware, the last check and job as the updater left them, a job whose worker no longer holds the update lock read as failed, the policy, what is kept for a rollback and still on disk, the translations installed, the history's newest twelve, the AmneziaWG tunnels): the same from both. Then `setup_defaults` (what a new server starts from: a free id, interface name, port and network, the address to reach the router by and where it came from, the zones, the portal's port): the same from both but for the port and the network, which each backend draws at random once the usual ones are taken. Then the three that ask GitHub, `updates_releases`, `updates_notes` and `updates_changes` (`backend/github`: the API over Go's own HTTPS, answers kept ten minutes in the files the ucode backend keeps its own in, so the two share GitHub's hourly allowance; a rate limit and an API error told as ucode tells them): eight questions, each backend fetching for itself, the same answers. The binary is 8.2 MB with it. Then `endpoint_probe`: `backend/endpoint` is `dawnline.health`'s facts about a public address and their words (a name that does not resolve, Cloudflare, CGNAT, a private WAN, a name that points elsewhere, AAAA records that are not the router's, an IPv6-only name), fact for fact and sentence for sentence on 26 made-up reads; on the development router twelve questions got the same verdicts, with one known difference: a name with several addresses lists them in the order Go's resolver sorts them, not the DNS answer's, and a name behind a load balancer may answer each backend with another address. **Health** (`backend/health`: every check a pure function of what is read on the router, so each way a check fails is made up in a test, 41 of them; `methods/health.go` reads the router). Its three harder inputs are held to ucode on a settings file broken on purpose (`testdata/broken.uci`): what is wrong with people and devices (`ModelErrors`, 16 sentences), who is loaded into each tunnel (`TunnelDevices`) and how a tunnel stands against that (`PeerDiff`); the proxies' diverts and the reply table (`ProxyDiverts`, `ReplyScript`) are tested in Go only. On the development router all of ucode's 18 checks come out the same from Go, in the same order, in English and in Russian, with the watchdog's state and the log beside them; all of them pass there, so no failing sentence has been held to ucode's on a real router. `portal_info` with it (the addresses the portal could use, best first, and Health's checks of the portal): the same from both. Then `home_hosts` (leases, static hosts and what umdns hears, inside a server's home networks; a device's services in the order of their type and name, where ucode has umdns's own order) and `export` (admins only), the same from both on the development router (seven hosts, eleven sections; umdns does not run there). `export` is the first method of Go's that writes the service log: `backend/servicelog` is `dawnline.util`'s `slog` and `syslog` (an entry a line of JSON in `service.log`, the same in words in syslog at the admin's level), and its line in syslog was ucode's, letter for letter. Then `access_check` (`backend/access`: the walk through the same rules the access table and a device's configuration apply, each step a sentence), held to ucode on a household made up for it (`testdata/access.uci`: three servers with circles, every device reaching each other, and none; twelve people with every kind of access, a paused one, home services, home networks of their own; fourteen devices) on the golden's router: 580 connections, step for step and sentence for sentence. On the development router 256 connections between its six devices, the router, home and the internet, in English and in Russian: the same from both. **Every question is Go's now: twenty-one methods.** `luci.dawnline` is asked only to change something. **The first methods that change something** are those that touch neither the settings nor the tunnels: `logs_clear` and `service_log_clear` (admins only). What they leave on disk is held to ucode file for file (`journal/testdata/clear.uc`: eleven filters over a live log and an older copy on flash, seven cuts of the service log), under the same lock the watcher writes the log under, and what went is written in the service log as ucode writes it. They are never run against a real router's data to compare: there only their refusals were asked of both (an unknown person, an unknown category, a bad age), the same. That golden holds the container's clock, so it changes with every run and CI does not diff it. Then `usage_clear` (the watcher forgets in its own counters at once and puts them on flash, `Watcher.ResetUsage`, where ucode left a request for the agent's next minute and edited the live file meanwhile), `geo_clear` and `backup_delete`: tested in Go, and on the development router only their refusals were asked of both, the same. **The writer's ground is laid, and nothing uses it yet.** `backend/uci` writes the settings file byte for byte as libuci commits it (`Format`: the model's two fixtures as a commit leaves them) and changes it as a cursor does (`Set`, `SetList`, `Delete`, `Add`, `DeleteSection`: twenty changes in a row, the file after each the same as libuci's, an option that changes kind keeping its place, an empty value removing it); options keep the order they stand in (`Section.Order`). `backend/store` is `dawnline.store`'s transaction: under the same `config.lock` the ucode backend takes, against the settings read inside the lock, written whole under a hidden name beside the file and renamed over it, mode 0600; a change that is refused or does not reach flash writes nothing. **The first methods that change the settings are Go's**: `service_set` and `service_delete` (`methods/write.go`), on `store.Transact` with the checks `dawnline.rpc.home` makes. Putting a change into effect is still ucode's: Go asks it for its runtime sync over ubus (`luci.dawnline sync`, a method added for this and gone with the port of apply) and passes on its warning; then the watcher reads the settings anew and the topics are put again, so a page sees its change at once (`Deps.Told`). Held to ucode on access's household (`methods/testdata/write.uc`): sixteen changes and refusals in a row, the settings file after each byte for byte the one the ucode method leaves, each refusal in its words. On the development router a service nobody has was added, changed and removed through Go: the stream had it and lost it at once, and the settings file ended byte for byte what it was, mode 0600, no temporary file left. Then `circle_set` and `circle_delete` the same way (twelve more steps of the golden: a new circle with members of whom one is on another server and one unknown, a colour out of range either way, a name another circle of the server has in other letters, removal with its members let go; an id made at random is taken from the golden's file for the comparison). On the router a circle nobody is in was added, changed and removed: in the stream and out of it at once, the file as it was, three lines in the service log (added, changed, removed) as ucode writes them. Then `person_pause`, the first that writes the activity log: its event goes in with the names it carries and, being about the system, into syslog too (`journal.Level`, `journal.Line`: `dawnline.live` `event_level` and `event_line`). Five more steps of the golden, a pause of someone already paused among them, which writes nothing and refuses nothing. On the router only its refusal was asked: nobody real was paused. (The watcher's own events are all about connections, which stay out of syslog in ucode too; a limit reached or a pause that ends is still the ucode agent's to log.) Then `person_delete` (five more steps: someone with one device, with three, someone already gone, a device's id, a server's): on the router only its refusal was asked. Then `person_update` and `people_update` (`methods/person.go`: `dawnline.core`'s `update_person`, field by field in its order, and `bulk_changes`): 68 more steps of the golden, 106 in all. They hold what no reading of the code would have: a number is read as ucode's unary plus reads it (`' 7 '`, `'3.9'` cut to 3, `'1e1'`, `'0x10'`), a small one is written as C's `%g` writes it (`1e-05`), a day that does not exist is no end date, a move to another server gives every device the first free address there and drops the circle and the home networks, and **a list that replaces a list goes to the section's end** while an option that becomes a list keeps its place (the cursor's own ways; `uci.SetList` follows them now). Extra data (`bonus_gb`) above zero writes a moment that depends on the clock, so the golden has only its refusals and its clearing. On the router a note was put on a person and taken off again through Go: written, the person answered the same as ucode's for the same call (the methods' world is now the completed one, `roster.Complete`, with what each device was last given), six refusals the same, the settings file byte for byte what it was. Then `person_create` and `person_regen` (nineteen more steps, 125 in all): an id from the name (`slugify` over `handout.Translit`, `_2`, `_3` for a name taken, `user` for a name of no letters), a personal code of three words of three syllables, the moment; a new link with the devices the old one handed out taken away when asked, and no sync when none is. The code and the moment are ucode's dice and clock, so the test hands Go the ones the golden's file has. All people's methods are Go's with them. On the router a person with no device was added, given a new link and removed: in the stream and out of it at once, the settings file byte for byte what it was; three lines stay in the activity log. Then `device_update` and `device_delete` (`methods/device.go`, twenty-five more steps, 150 in all): a name by `valid_device_name`'s rule (letters of any language, no symbols, twenty characters), a name another device of the person has, off and on, an MTU and a keep-alive of its own and the server's again, LAN Bypass; a change of the link values alone writes and asks for no sync, as in ucode. On the router only their refusals were asked, the same: a real device renamed or given other link values would show as changed to its owner. Then `device_create` and `device_rotate` (thirteen more steps, 163 in all; the golden's container has no AmneziaWG, so there the settings they leave are `dawnline.core`'s `create_device`, `set_device_kind`, `set_device_link` and `rotate_device` called with keys made up for it). The keys are made in Go, with no tool: a Curve25519 private key clamped as `awg genkey` clamps it, its public key, 32 random bytes to share (`crypto/ecdh`). The configuration given out is marked in `issued.json` and a device set up again in `reconnect.json`, under ucode's locks. All devices' methods are Go's with them. On the router a device was added to a person made for it, given new keys and removed with them: the public key was the one `awg pubkey` makes of the private key both times, the sync loaded it into the tunnel and took the old one out, the configuration came back, the marks were written, and the settings file ended byte for byte what it was. Then `settings_update` (`methods/save.go`: `dawnline.schema`'s `validate` for every kind of setting, and `check_portal`; 57 more steps, 220 in all): each kind at its edges, a value back to its default, the list of log categories that stands for the older switch, the portal's port against the router's own ports, the next port for plain HTTP links, a port another program holds or a forward sends on. Two things differ from ucode by design: the settings of one call are taken in the schema's order, not the caller's (the bus hands them over as a map), and a change that restarts the portal runs the service's reload a second after the answer is out, since that reload may restart this very process. The golden corrected the list rule once more: **a list of one entry goes to the section's end whatever was there, a longer one keeps the place of what was there** (`uci.SetList`). On the router a setting was changed and put back through Go: saved, told in syslog as ucode tells it (`admin changed settings · log_keep_days: default → 41`), answered as `settings_get`, six refusals the same as ucode's, the settings file byte for byte what it was. A change that restarts the portal was not tried there. Then `server_update` (`methods/server.go`, 33 more steps, 253 in all): a name, a public address, a port against what holds UDP ports, on and off, who reaches whom, MTU and keep-alive, DNS servers of either family, and a new tunnel network that must be private and free, with every device given an address in it, lowest first. It ends in ucode's full apply (`luci.dawnline apply` over ubus, a minute at most), whose answer is passed on. That apply notes a migration in the settings the first time it runs, which the test puts where apply puts it. **On the router only refusals with an id that does not exist are asked of a server's methods.** On 2026-11-12 a probe meant to be refused (`subnet: 192.168.1.0/24` on the real server) was accepted, since that network is free there: the tunnel network changed and every device was renumbered, until the settings were put back from the pre-deploy backup 80 minutes later. A value-dependent refusal is held in the golden's container, never on a real server. Then `server_interfaces` and `server_delete` (fifteen more steps, 268 in all, on the golden's router: a bridge's port refused for the bridge, an interface in no firewall zone refused as WAN, the WAN refused as a home network, a saved name that is gone kept, the zones kept in step), and `backup_create` (`methods/backup.go`: a tar.gz written in Go with the paths ucode's restore unpacks, whole or not at all, the oldest of each kind beyond its number removed; `server_delete` makes one first). On the router a backup made by Go was read by `tar`, held the settings as they are, was listed by ucode as the newest, and was removed again; the servers' methods were asked only with an id that does not exist. Then `server_obfuscation`: `backend/disguise` makes a method's values as `awg.obf_preset` does (`Preset`: none, AmneziaWG 2.0's with DNS-shaped signature packets of the server's own, 3.1's with a header protection key) and checks them as `obf_errors` does (`Errors`, on 39 made-up sets the same sentences as ucode). What the dice decide cannot be compared value for value: a Go preset has the names, the order and the shapes of forty presets ucode drew, passes its own check, and ucode's pass it too (`testdata/presets.uc`, which CI does not diff; nor the methods' golden, whose ids, codes and moments are ucode's dice and clock). The golden's container has no AmneziaWG, so there only no disguise can be set and the others are refused in ucode's words (six more steps, 274 in all); with an AmneziaWG that runs them the method is tested in Go. Then `server_create` (eighteen more steps, 292 in all), the wizard's last step: an id, an interface name and a port that are free, a private tunnel network that overlaps none, every fault of the definition told at once, the keys made in Go, the disguise of its method, the portal as asked and checked as it will be; then ucode's full apply, and the service turned on and restarted in the background (`Deps.Restart`: this very process restarts with it). For the golden ucode's own method runs on a copy of ucode with the one check taken out that needs AmneziaWG's module loaded, and a stand-in `awg` gives two made-up keys. On the router it was asked only with an id no server can have. **All servers' methods are Go's.** Then `health_fix` (a fix by its name: apply and sync are passed to ucode, a restart of the service or the network runs in the background after the answer, `ifup` only for one of Dawnline's own tunnels), `updates_run` (the target checked as ucode checks it, the ucode updater started with the admin's language, the new job answered once the updater wrote it) and `apply`: tested in Go; on the router four refusals the same as ucode's, and a check for updates started through Go ran and ended. **Fifty methods are Go's.** Then `backup_restore`, `backup_upload` and `import` (`methods/backup.go`): an archive read in Go and held to `check_archive`'s rules (only Dawnline's three files, regular files only, the settings among them, sixteen megabytes at most), the settings in it checked as `dawnline.backup config_errors` checks them (`health.ConfigErrors`: on settings whose servers are wrong in every way, the same thirteen sentences as ucode) before anything is touched, a backup of what is there made first, the settings written first under the config lock, the counters and the log handed back to flash for the watcher to load anew, then ucode's full apply. A backup ucode made with its own tar is read file for file (`testdata/backup.uc`). An import writes a section's options in the order of their names, where ucode keeps the export's order (the bus hands them over as a map). On the router only what cannot be a backup or an export was sent: six refusals the same as ucode's, nothing touched, no backup made. **The apply has begun, with what decides who reaches what.** `backend/nft` makes the table `inet dawnline` as `dawnline.nft` does: who is in which set by each person's state (`AccessSets`), the table's text (`Render`), the script that replaces every set's members at once (`Update`) and the one that replaces the table (`Rebuild`). Held to ucode byte for byte on nineteen tables: access's household under four rows of states and four of what is read from the router (the netns's DNS, the resolver in the netns or on the router, the LAN's DNS, each also as something that is no address), and a second household for what the first has none of (services with ports, one of them no number and one on IPv6, home names, two devices with one address, a server that sends the internet through the LAN, one without keys, one whose interface name will not do, a portal on a port people never reach through the tunnel); a test fails if a set is filled by no case. Nothing loads it yet: the table on a router is still ucode's. **The runtime sync is Go's** (`backend/apply/sync.go`, `dawnline.apply` `sync`): the sets' members replaced at once, the whole table rebuilt when that fails, a failure told once in the service log and kept in `nft.err`; fail closed (with no table at all nobody is loaded into a tunnel); each tunnel given its devices by `awg syncconf`, the file with its key removed again; the hostnames for dnsmasq; people's states in `states.json`; the warning for the admin. Under the same `apply.lock` and with the same remembered files (`nft-sets.json`, `peers-seen.json`) as ucode, so either may run. Held to ucode on the golden's router with stand-ins for `nft` and `awg` that keep what they are given: nine syncs in a row (no table yet, the sets alone, someone paused, a table that will not load while the old one stays, one that will not load when there is none, the same failure again, a tunnel that refuses its devices, a tunnel that is down, all well), and for each the scripts loaded, every tunnel's peers, the hostnames and who may read them, the states and what is answered: the same. On the development router Go's plan of a sync (`sync_plan`, which loads nothing) was the table ucode renders line for line, the same script for the sets, the hostnames dnsmasq reads and the six devices the tunnel holds. It is **turned on there by `/etc/dawnline/backend-sync`** (2026-11-12): what the Go methods change is put into effect by Go's sync, with no call to ucode; a service added and removed left the table, the tunnel and the hostnames as they were. Without the marker the sync is ucode's. **Left of apply:** the full apply (netifd, firewall, the home-like path, the resolver, the reply table), which the servers' methods, a restore and an import still ask of ucode; the agent's own sync every minute is ucode's too. **Left of `dawnline.rpc.*`:** `uninstall`; the apply (`apply.sync`, `apply.apply`); the backups that write settings (`backup_create`, `backup_restore`, `backup_upload`, `import`); `health_fix`; the agent's remaining duties, the CLI. `backend/view` already makes a person and their devices as `dawnline.view person_view` does, field for field for four people and seven devices, the admin's view and the person's own, with a watcher's word on presence and without one (labels that collide, a device set up again, one whose configuration changed since it was handed out, a limit month with extra data). |
| 6 | **Site-to-site** ("Networks behind this device", issue #4), built on stage 5's model and apply. | After the migration, by the owner's decision. |
| 7 | **Updater and health**, last: they change least and are used least. | |
### The full apply (stage 5)
The full apply is Go's own: `backend/apply` holds each part, and every part is held to the ucode module it replaces by a golden taken in the OpenWrt container (`scripts/ucode-golden.sh`, the files after each of a row of changes compared byte for byte, the commands in their order).
| Part | Go | Golden |
|---|---|---|
| Tunnel interfaces in `/etc/config/network` (`dawnline.netifd`) | `netifd.go` · `Router.Netifd` | `testdata/netifd.uc`, 9 steps |
| fw4 zones, forwardings, WAN rules (`dawnline.fw` sync) | `fw.go` · `Router.Fw`, `FirewallDiffers` | `testdata/fw.uc`, 11 steps |
| The table that keeps our answers out of proxies (`sync_reply_routes`) | `reply.go` · `Router.ReplyRoutes`, `ReplyOK` | a test of its own; the script itself is `health`'s golden |
| The Home-only resolver's configuration (`dawnline.resolver`) | `resolver.go` · `Router.Resolver`, `SyncResolver` | `testdata/resolver.uc`, 6 steps |
| "Like a home device": netns, links, policy rules (`dawnline.loop`) | `loop.go` · `Router.LoopEnsure`, `LoopRemove`, `LoopPlanFor` | `testdata/loop.uc`, 15 steps with a stand-in `ip`, and the pure parts |
| The network signature (`net_signature`) | `apply.go` · `Router.NetSignature`, `NetChanged` | `testdata/sig.uc`: the same text, the ucode agent compares it |
| One-time steps for older set-ups (`dawnline.migrate`) | `backend/migrate` | a test of its own |
| All of it under the apply lock (`dawnline.apply` apply) | `apply.go` · `Router.Apply` | the parts' goldens; on the router by `apply_plan` |
**On the router** it runs behind a marker, `/etc/dawnline/backend-apply`: with it, the `apply` method and every method that ends in a full apply run Go's; without it they ask the ucode backend as before. Remove the file to go back.
**`ubus call dawnline apply_plan`** is the full apply with nothing applied: each part runs on copies of the files it would write, commands that only ask the router something are run, the ones that would change it are noted. It answers which lines of `network` and `firewall` would change (keys never shown), which commands would run, and whether the network signature holds. Right after a ucode apply it must find nothing to do; that is how the Go apply was held to the development router before the marker was set (2026-11-12: nothing to change, then a Go apply left `network`, `firewall`, the settings and the access table byte for byte as they were, all six devices in the tunnel).
**`auto-merge` is gone from the access table's interval sets** (`home_<id>`, `tun_nets`), in Go and in ucode: nft 1.1.6 takes about 0.9 s to load a set that has it on an MT7981, and the networks in those sets are collapsed before they are written (`Collapse`: none covers another, so none overlap). A full apply on the development router went from about 1050 ms to about 300 ms.
**The keeper** (`backend/apply/keep.go`, `Keeper.Tick` once a minute from `dawnlined`, with the same marker) is what holds the router to the settings between the admin's changes, the ucode agent's steps "Access rules", "Internet like a home device" and "Router": a runtime sync when people's states changed, the settings' file was written by anyone, the access table is gone, a running tunnel holds other devices than it should, or ten minutes passed; the home-like path, the resolver and the reply table kept in step; everything applied again when the router's networks stay changed for two ticks. The agent leaves those three steps alone while the marker is there and the backend's beat is fresh (`backend_keeping()`), and takes them back within a tick when it is not. Checked on the development router: the access table deleted by hand was back on the keeper's next tick, every device still in the tunnel.
**`uninstall` is Go's** (`backend/methods/uninstall.go`, `Router.Teardown`): no admin method is left to the ucode backend. The order differs from ucode's on purpose: the settings are emptied first (whatever applies in between then works from nothing and puts nothing back), then the router is cleaned from the settings as they were, and the service is stopped last, once the answer is out, since `dawnlined` is part of it. Held by tests (`TestUninstall`, `TestTeardown`: `network` and `firewall` end as they were before Dawnline, an interface of someone else's under a tunnel's name untouched); never run on the development router.
**The minute's other work is Go's too**, with the same marker and the same stand-by of the agent:
- `backend/chores` (`Chores.Tick`): people's states that change on their own (end date, data limit) and an end date's last days go to the activity log, and those people's pages are told (`presence.poke`); a renewed certificate is told and taken, one that runs out within a week is told once; a changed public address is told, with the servers that still hand out the old one; the settings are backed up in the night's third hour when they changed; an automatic update check or install is started when one is due (`Due`). What was told is kept in `notes.json`, the file the agent kept, so neither repeats the other.
- `backend/watchdog` (`Probes`, `Pass`): the same targets, waits and words as `dawnline.watchdog`, the same `watchdog.json` (the Health page reads it either way). One target is gone on purpose: `rpc` (is `luci.dawnline` in rpcd) guarded the plugin that is being retired, and its repair restarted rpcd. A target reads from facts gathered once a pass (`methods.WatchdogFacts`); `Router.NetifdDrift` and `Router.FirewallDrift` are the two that compare a configuration with what an apply would write.
Checked on the development router: the first pass of Go's watchdog found all seven targets well, the chores' first minute told nothing that was not new and started no update.
**And the rest of the agent's minute**, with the same marker:
- the speed record (`chores/rate.go`): `rate.json` and `rate_people.json`, a point a minute from the counters' totals, the same shape the pages read;
- the logs on flash (`Chores.keepLogs`): the service log trimmed and copied (`servicelog.Log.Trim`), the activity log copied as often as Settings says (`journal.Log.Persist`), the places' cache hourly;
- the places for the map (`backend/geo`): the cache, what is stale, the two services, the merge that never pushes out an address still shown (the cases of `tests/ucode/geo.test.uc`), and `Locator`, which runs lookups by itself, three addresses a run, so nothing waits on the network. `dawnlined` takes the watcher's `geo.poke` itself and asks over Go's own HTTP client (no `uclient-fetch`); a place found goes onto the connections logged before it was known (`journal.Log.SetPlaces`).
With the marker set the agent's tick does nothing but stand by: every step is the backend's. It stays as the fallback for a backend that is not alive (its beat), and it still saves on a clean stop.
**The Go side is the default** (2026-11-12). No marker is read any more: where `dawnlined` runs on the router, the init script starts it with its watcher and the portal, and its apply, sync, keeper, chores and watchdog are in charge. One file gives all of it back to the ucode backend for as long as that one is shipped: `/etc/dawnline/backend-off` (then `/etc/init.d/dawnline restart`). The older markers (`backend-watch`, `backend-portal`, `backend-sync`, `backend-apply`) mean nothing now; where this document names one above, read "by default". Checked on the development router with every marker removed and the service restarted as a fresh install starts it.
**The command line is Go's** (`backend/cli`, run as `dawnlined cli …`): `/usr/bin/dawnline` is now a few lines of shell that hand their words to the backend's binary where it runs, and to the ucode command (moved to `/usr/libexec/dawnline/cli`) where it does not or is switched off. What the service itself needs works with no backend running: `apply` (what the init script runs when the service starts, and the updater after an update), `sync` and `iface-event` (the hotplug script, a tunnel coming up or going down), `portal-cert`, `portal-http-port`, `teardown`, `log`, `version`. What an admin types about people and devices (`status`, `health`, `person …`, `device …`, `backup`) goes through the running backend, the same methods and the same topic the pages use, so there is one place a person or a device is made. Checked on the development router against the ucode command: the same certificate, the same people, devices and addresses.
**A sync replaces the table whole** (in Go and in ucode, `rebuild(m, sets, members)`), never a set in place. To add an element to a set that exists, nft first reads the router's whole ruleset, every other program's sets with it: 0.9 s on the development router, whose ruleset is 0.8 MB beside a proxy's lists. Replacing our own table reads nothing: 0.06 s. Nothing reads the table's counters, and the replace is one transaction. `dawnline sync` went from 2.1 s to 0.12 s there, and every change an admin makes ends in one.
**The portal's API is Go's** (`backend/methods/portal.go`, `Portal`, behind `portal.Server.Native`): the door, the count of wrong codes, the shell, the assets, the state, a configuration and every change a person makes through their link are answered by `dawnlined` itself; no ucode process is started for the portal any more, and a page's stream reads its state without one. The device changes are the admin methods' own code with an `Actor` (`DeviceCreateAs`, `DeviceUpdateAs`, `DeviceRotateAs`, `DeviceDeleteAs`): the portal is held to the person's own devices and their limit, cannot touch a device the admin turned off, may bring the browser's public key, and has the new keys of the device a page came through loaded a moment after the answer. Held to the ucode portal three ways: `TestNativeAsUcode` asks both the same 26 things in both OpenWrt rootfs images (`scripts/backend-container.sh`: the page byte for byte, the state and a configuration field for field, every refusal with its status and words, in English and Russian); `TestPortalChanges` and `TestPortalLimits` cover what changes and what is counted; and on the development router the state of each person was the same in every field as the ucode portal's for the same request. The ucode portal answers only where the backend runs without its watcher (`backend-off`).
**The updater is Go's** (`backend/updater`, run as `dawnlined updater …`; `/usr/libexec/dawnline/updater` hands its words over, the ucode one is `updater.uc` beside it): the job with its lock, log and phases in the admin's language, the three checks, the installs of Dawnline (latest, a tag, the same again, the kept version, a translation), of an AmneziaWG build (with the kernel module swapped or left for the next boot, and the record of it) and of the system packages with their families, the automatic run, and the restarts after a job. Under it `backend/pkgmgr` (opkg and apk behind one interface) and verified downloads in `backend/github` (`Download`: GitHub first, a mirror only with a sha256 from the API; Go's own HTTP client, so neither curl nor uclient-fetch and its 4 KB header limit). Held by tests on the cases `tests/ucode` holds the ucode modules to (versions, generations, a pending reboot, package files, what apk left alone) and by whole jobs on a made-up router (`TestCheckAndInstall`, `TestInstallRefusals`, `TestAuto`). On the development router a Go `check` gave the same `update-check.json` as the ucode one in every field, with the same lines in the job's log, in 5 s against 9. **An install was never run on the router by the Go updater**: that part rests on the tests until a release is cut.
**Left in ucode:** the agent as the fallback (a backend that is not alive, or switched off) and the rpcd plugin itself with the temporary `sync` method; the ucode command line, apply, portal and updater stay beside them as that fallback's. `postupdate` (a shell on purpose) still judges a new version by `luci.dawnline` and the agent: it changes with them.
**The backend asks nothing of ucode while it keeps the router** (2026-11-12). The stream's topics are Go's own without being held against a ucode `status` first (`roster.Roster.Sole`, `bridge.Bridge.Sole`: the bridge only has them told again when the settings change, when somebody starts to look, and with the minute; `TestSoleNeverAsks`). Before the switch the two had agreed on the development router with no difference ever logged. The methods' calls to `luci.dawnline apply` and `sync` are gone, and with them the temporary `sync` method of the rpcd plugin. What is left of ucode on a router with the backend is a fallback nothing calls: the agent standing by, the rpcd plugin, and the ucode command line, apply, portal and updater behind `backend-off`.
**Told as the router is at that moment** (2026-11-12). When the bridge has the topics told, the watcher looks first (`daemon`: `tell`), and topics that could not be made stay due: the bridge asks again with its next second and does not put `backend` until they are there (`bridge.Bridge.Tell` answers whether it told). Before, the bridge told from what the watcher knew at its last second, and took for told whatever came of it. Its second comes just before the watcher's, so a page that was open while the backend restarted asked in the first second, was told nothing (the watcher had not looked yet: no world), and got its first documents with the next `Refresh`, half a minute later, unless someone came or went meanwhile; and settings changed on disk were told as they were before, `refresh` included. Measured on the stand (`TestThroughUhttpd`, a restarted backend whose watcher starts 0.3 s late, as on flash): the first documents 32 s after the page asked before, 1 s after. That test now runs the backend's own watcher and topics over a stand's settings and tunnel (`daemon.Options.Tunnels`); it used to wait for the answer of a ucode stand-in nobody asks any more, and failed.
**The ucode backend is removed** (2026-11-12, on the owner's word). Gone from the package: every module under `usr/share/ucode/dawnline`, the rpcd plugin `luci.dawnline`, the agent and its heartbeat check, the ucode command line, updater and portal (with the portal's own uhttpd). Gone from the repository with them: `tests/ucode`, the ucode lint, compile and container scripts, and the script that made the goldens. What stays of that backend is its answers: the goldens in `backend/*/testdata`, fixed, which the Go tests still compare with. What it left to do was taken over first: the service-log line that says why the backend started (a crash, a restart, a boot, an update, a rollback), the beat the Health page reads, the logs and places put on flash on a clean stop (`backend/daemon/life.go`), the version in a file of its own (`usr/share/dawnline/version`), the translations' source (`backend/i18n/messages.js`), and the pages' one call that still went to the rpcd plugin directly (`person_update`). `/etc/dawnline/backend-off` means nothing any more; a router without the binary runs nothing, says so in the log, and fetches it at its next start. Checked on the development router: the service is the backend and the resolver, no ucode file or process is left, `luci.dawnline` is off the bus, Health reads 18 of 18, the settings, `network` and `firewall` are byte for byte as before.
Who this leaves out, knowingly: a router whose architecture has no binary (ARM older than v7, 32-bit x86, RISC-V) and a router installed with no network until its first start with one.
**Before any of the ucode can be deleted, a release has to put `dawnlined` on the router.** The package is `all`-architecture and the binary was built by `scripts/deploy.sh` for the development router alone: a router that installs a release gets no backend, and runs entirely on the ucode fallback.
What is in place for it, whichever way the binary is delivered: the release workflow builds it for five architectures (`backend` job in `.github/workflows/build.yml`: arm64, arm for ARMv7, mips, mipsle, amd64; static, 9 to 11 MB each: more than some routers have free, which the install has to check) and publishes each as `dawnlined-<version>-<goarch>` with its sha256 in `sha256sums.txt`; `updater.GoArch` names the one for a router by its `DISTRIB_ARCH` (none for ARM older than v7, x86 32-bit and RISC-V: those stay on the fallback).
How it gets from the release onto the router: **fetched beside the package** (`/usr/libexec/dawnline/fetch-backend`, a plain shell like `postupdate`, since it runs when no backend does). It asks GitHub's API for the release of the installed version, takes the file for this router's architecture through the API (the same way round uclient-fetch's header limit as the updater's), keeps it only when it matches the sha256 the API gives and runs here as that version, and renames it into place. A binary of another version is always removed, fetched or not: two versions never run side by side, and the service then runs on the ucode backend. It is called by `install.sh` after the package is in, by `postupdate` before a new version starts (and again after a rollback), and by the init script in the background, once a boot, when there is no binary. The package's `prerm` removes the file: the package manager does not own it. Tried against a made-up GitHub in both OpenWrt rootfs images: a fresh router, again, over another version, a file that does not match its sha256, a version with no release, an architecture with none.
This was built without the owner's answer to "per-architecture packages or a fetch beside the package", on the recommendation given; it adds a script and three calls and changes no package. Should the answer be per-architecture packages, `fetch-backend` and its calls go, and the release's binaries become those packages' payload.
What it does not give: an install with no network leaves a router without the backend until its next start with one; ARM older than v7, 32-bit x86 and RISC-V have no binary at all. So the ucode fallback cannot be deleted outright yet: it can go once the owner accepts that those routers are no longer served, or the backend is built for them.
### The watcher's takeover (stage 4)
The agent's 1-second watcher and its counters are the Go backend's while its watcher runs; the agent keeps its minute tick. Who owns what:
| | Go backend (`backend/watch`) | ucode agent (until stage 5) |
|---|---|---|
| Every second | the tunnels' dump; presence, link, meter; a connect, a leave, a move, a link's trouble into the activity log; `backend.beat` | looks at the beat's age, and at `geo.poke` |
| Counters | `usage`: folded on every event and every minute, written to tmpfs, to flash hourly and on stop; `usage.reset` and `usage.reload` honoured | reads `usage.json` at each tick, never writes it |
| Files the ucode that remains still reads | `presence.json` (with its revisions), `link.json`, `setup.json`, `usage.json`, `meter.json` while asked, `events.json` under the `events` lock | `rate.json`, `rate_people.json`, the rest of the tick's |
| Revisions | moves them with each event, and for the people named in `presence.poke` | writes `presence.poke` where it used to save presence (a state that moved on its own, a place that was found) |
| Places | a connect's place from the cache when it is known; the addresses that connected or moved into `geo.poke` | the lookups: at once for `geo.poke`, each minute for what is shown (`geo.json`; the bridge watches it and `events.json`) |
Handing over, both ways, is by the beat alone:
- **The backend starts**: it reads `presence.json` (who was online, the revisions) and `usage.json` as the agent left them, so nobody connects or leaves "again" and no counter is lost. What a link showed starts empty: a state shows again once it held.
- **The backend stops** (or a package without it is installed): it folds the counters once more, writes them to flash and removes the beat; the agent's watcher reads the files back within a second and goes on. If it is killed, the beat goes stale in five seconds and the same happens, with at most a minute of traffic counted from the tunnel's own counters at the next look.
Measured on the development router (MT7981, 2026-11-11): the takeover and the take-back moved no revision and logged no event; the counters file after the first Go write had the same devices, people and fields, with only that minute's traffic added; `dawnlined` with the watcher holds about 6 MB.
### What stage 1 is
```
backend/
ubus/ the wire protocol of ubusd: our object, calls, notifications, reconnect (own implementation)
hub/ topics, merge-patch diff, the numbered journal, wait and follow
api/ the object `dawnline`: hello, sync, wait, watch; the broadcast; who looks
bridge/ `status` cut into topics; asks luci.dawnline only while a page looks
daemon/ the parts joined
cmd/dawnlined/
web/src/shared/live/ signal.ts, patch.ts, store.ts, follow.ts
scripts/backend-container.sh
```
Verified by `scripts/backend-container.sh` on the OpenWrt 24.10 and 25.12 rootfs images, against their real `ubusd`, `rpcd` and `uhttpd`:
- the object, its signature, calls, statuses and notifications, with OpenWrt's own `ubus` tool on the other side;
- a page's whole path: an rpcd session, the package's ACL file, `sync`, a held `wait`, the event stream, the meter under a lease, arguments refused at the door;
- one device coming online reaches the page as a 67-byte patch about 0.6 s after the agent's file moved (the bridge looks once a second; a native producer in stage 4 publishes at once).
Run on the reference router (2026-11-11, OpenWrt 25.12.5, uhttpd 2026.08.24, from `/tmp` beside the real agent, three people and one server):
- the event stream through that uhttpd holds for 50 s with a ping every 15 s of silence, and its connection is gone when the client leaves (the leak of older builds is not there);
- the snapshot is 40 KB in ten topics, where one `status` answer is 48 KB and takes 0.39 s in rpcd;
- a page that follows receives about 240 bytes per 30 s while nothing happens, and about 13.5 KB when the agent's minute tick moves the counters: `places` 8.7 KB (its points are a list without ids, resent whole) and `people` 2.9 KB are what is left to cut, by the producers of stage 4 rather than in the bridge;
- the daemon holds 9.2 MB of memory and used 0.23 s of CPU in 154 s of being followed.
As a service on that router (the same day, deployed with `scripts/deploy.sh`), with Overview open in a browser: the page asks no `rev` and no `status` at all; the bridge asks the ucode backend for one `status` per 30 s for every open tab together (and at once on a change), and for the meter once a second only while a speed is on screen. The backend holds 4 MB of memory there.
A session opened before the backend's object was in the access list does not have it until its next login (rpcd grants a session its access when it logs in): such a page falls back to asking the router, as on a router without the backend.
## Decisions
- **As little ucode as can be** (the owner, 2026-11-12: «Нужно будет максимально уйти от ucode»). The bridge is scaffolding, not a design: a part is ported, held to ucode on fixtures, compared with it on the real router (`roster`), then published by Go, and its ucode call goes. Nothing stays on the bridge once it is ported.
- **Go, not Rust.** Cross-compiles to every OpenWrt architecture with no SDK, the reference (podkop-exp) proves the approach on the same routers, and nothing here needs what Rust would buy. The cost is the binary: stage 1 is 3.4 MB for aarch64 (3.9 MB mipsle; 1.4 MB gzipped) and 9 MB of memory on the router, and both grow with what is ported.
- **No dependencies so far.** ubus, the hub and the API are the standard library only. A dependency is added when it replaces real work (nftables and netlink in stage 5), not for convenience.
- **podkop-exp is studied, not copied.** Its backend is GPL-2.0-or-later and Dawnline is MIT: its patterns are reused (one door per external system, a single loop for router changes, fakes behind interfaces, golden files from the old backend), its code is not. `backend/ubus` is written from ubus's own protocol (`ubusmsg.h`) and, unlike podkop-exp's, also notifies, calls and reconnects.
- **The package stops being `all`.** A Go binary is per architecture. Until stage 2 ships, the binary is built and deployed for the development router only; the release build then follows podkop-exp's matrix (one SDK image per package architecture) and `install.sh` picks the asset by `DISTRIB_ARCH`.
- **The router's time zone is read from `/etc/TZ`** (`backend/zone`). Go looks for the zone in `TZ` or `/etc/localtime`; an OpenWrt service has neither, so a Go program there counts its days in UTC. Found the first night the watcher ran (2026-11-12, MSK): after local midnight the traffic went on into yesterday's UTC day and «Today» read 0 B. Everything that needs local time asks `zone.Local()`; the watcher takes the file again when it changes. A golden made with `TZ=UTC` cannot see this: `usage` and `zone` have their own tests in a zone east of Greenwich.
- **A router stands for the networks behind it** (site to site, issue 4; 2026-11-12). A device of kind `router` may have networks of its own behind it (`list behind_net`), which the tunnel then carries both ways. `model/behind.go` is the one place that says what may be one (a private network from /16 to /30, eight a router) and which are in effect (`BehindOf`: none that shares addresses with a tunnel's subnet, with a network the router has itself, or with one an earlier device has), so a bad line in the file never takes a route away from the router or from another site. Everything else is made from that answer: the peer's `AllowedIPs` (`apply.PeersConf`); the router's routes (`apply/routes.go`: reconciled, every route of ours marked with routing protocol 205, and only into a tunnel that took its devices); the home-like path (the networks keep their direct route, and the netns answers them through the tunnel); the access sets, where a network stands wherever its router's address does, so a host there has exactly its owner's access and is reached by exactly those who reach the router (every run-time set takes intervals for it: the set declarations in the goldens of `nft` and `apply` were edited by hand, the rest of each table is still ucode's byte for byte); and the configurations of the devices that reach it (`model.BehindReach`), whose fingerprint then tells them to import again. `device_networks` sets a router's networks and ends in the full apply, since the home-like path's rules move. None of this is held to ucode: there never was a ucode version. Checked on real `nft` (1.1.1 and 1.1.6, the table loaded and its sets replaced) and `ip` of OpenWrt 24.10. **On the development router** (2026-11-12, OpenWrt 25.12.5, `nft` 1.1.6, iproute2 6.18, one server with six real devices; a person with the internet alone made for it and removed after, so no real device's configuration was touched): the table with its interval sets loaded on the router's own kernel, `fib` rules and all, with the same members as before; a router added with two networks got them in its peer's AllowedIPs, a route each (`ip route get` answers the tunnel), and its place in `inet_ok` and in no home set; changing the list moved the routes and the same list applied nothing; the refusals named the real tunnel's network and the router's own LAN; a router asked for through the person's link waited outside the tunnel with no configuration (409), was turned down, put back and taken, a network asked for later was taken on its own and another taken away by its owner at once; Health said how many networks the tunnel carries and Check access walked a host behind the router. With the person removed the routes, the peers and the sets were as before and the settings file byte for byte what it was. **Not checked there:** packets through a real far router (no second site to test with), and the home-access case, where other people's devices are given the networks.
- **A router and its networks may be asked of the admin** (2026-11-12). On their own page a person adds a router and names the networks behind it; what then happens is the server's rule (`portal_routers`: off, ask, free; `portal_nets`: ask, free; a server starts with ask for both, and the page is told the rule and is not offered a router where it is off). Asked, neither takes effect: the router waits (`waiting`: no device of the tunnel, in no access set, no configuration, no new keys; `health.TunnelDevices`, `nft.AccessSets`, `model.BehindOf` and the methods that hand a configuration out each leave it out) and the networks are only asked for (`ask_net`, `asked`). `device_answer` is the admin's answer: accept (checked now against everything the networks must not share addresses with, refused in a sentence that names whose they are), decline with a reason the person reads (`declined`: one of four words the pages put in their reader's language; `declined_net` for networks; a router turned down stays, waiting, for its owner to read why and remove), or reopen, the undo of either. Taking a network away is the person's own to do, at once (`DeviceWishAs`, the portal's `networks` action). A person is never told whose a network is unless it is their own: while something is only asked, other people's networks are not held against it at all, and the admin's answer is where the clash is said. What moved decides how it is put into effect: the routes (the full apply), who is in a tunnel (the sync), or nothing on the router. The model's goldens gained the two rules on every server by hand.
- **Check access and Health know the networks behind routers** (2026-11-12). An address typed into «Check access» that stands in such a network is a host behind its router: the walk says so first («192.168.2.10 is behind Boris · Dacha») and then goes on as it does for the router itself, since the access table sees the two alike; the router and what is behind it, or two hosts behind one router, need no tunnel between them, and that is the answer. A router that waits for the admin stands for nothing. Health has one more check a server (`sites_<id>`, on the page's Home stage), only where a router has a network written: every network in effect, or which is not and what it shares addresses with (a tunnel, the router's own network, another router's), or the route the last sync could not set (`routes.err`), with the sync as its fix. The household's 580 connections held to ucode come out as before.
- **ucode output is the oracle.** When a part is ported, its Go version is held to the ucode one's answers on the same input (fixtures from `tests/ucode`), as podkop-exp holds its planner to the shell backend's configurations.