Build packages / Version (push) Waiting to run
- Connections show up at once: the agent looks at the tunnels every second and, the moment a device connects or roams, writes it to the activity log, updates traffic and the map, and locates the new address - A device counts as gone when its WireGuard session expires (1-3 min after it leaves), so a phone asleep no longer flaps between disconnect and connect - The admin pages follow along within seconds: Overview, People, the person page and the device panel refresh when something happens, with a light check every 2 s instead of reloading everything every 10 s - The personal portal no longer refreshes itself in the background: every request costs the router a CGI process, so it loads once and after the visitor's own changes - Agent guidance and code standards (backend, frontend, shell, UI) now live in the repository: AGENTS.md and rules/
3.0 KiB
3.0 KiB
Backend (ucode on the router)
Read with code-standards.md. Everything here runs on a small router (2 × Cortex-A53 on the reference Cudy WR3000P): cost is part of correctness.
Layers
util,schema(validation) →core(model, allocation) →store(the only writer of/etc/config/dawnline) → domain modules (net,nft,fw,netifd,awg,loop,resolver,live,health,backup, …) →apply(reconciliation) → entry points (rpc/*,portal, thedawnlineCLI, the agent, the updater).- Read models for the UI live in
view; RPC modules translate arguments and call down, they hold no business logic. - The updater is a thin dispatcher over
upd_app/upd_awg/upd_pkgs, with GitHub ingithub, the package manager inpkg, policy/locks/history inupdates. - Live state: the agent's watcher owns who is online (
live.PRESENCE); readers asklive.online(), never re-derive it from handshake ages. Online means the WireGuard session lives (live.ONLINE_WINDOW): traffic silence is no signal, a phone asleep is silent too.
ucode
'use strict'in entry points; modulesimport { … } from 'fs'/'dawnline.x'. Subdirectories map to dots (dawnline.rpc.status→dawnline/rpc/status.uc).- Exported functions end with
};(the compiler requires it). No destructuring. Regexes are POSIX (no(?:),\s\Sclasses, lazy quantifiers); anchor them. - Modules with
exportcannot be loaded withrequire(): imports are static and compiled on every start of the script. - Doc comments (
/** … */) on every export: what it returns, including the null/empty case. - Shell out through one small helper per module (
run()/sh()), with2>&1captured and the exit code checked. - nft changes load as one script (
nft.load(), a transaction); tables Dawnline owns are nameddawnline*and rebuilt whole (table X+delete table X+ the table).
Cost on the router
- The portal is CGI: every request starts ucode and compiles the module graph, about 140 ms of CPU before any work (a full
stateanswer about 180 ms). No periodic polling from the portal; one request per user action. - rpcd keeps the admin backend loaded: LuCI RPC calls are cheap, so the admin UI may poll small methods often (
rev), and the heavy ones (status) only on change or rarely. - Code on the agent's 1-second watcher stays in the low milliseconds: one
awg show all dump(about 4 ms with process start), the model cached by the config file's mtime/inode (core.load()is about 4 ms), files written only when something changed. Slow work (geo lookups, apply) runs only on a transition. - Measure before and after on the router (a loop of 20–200 calls,
/proc/self/statCPU ticks, system busy from/proc/stat) when adding anything periodic.
Checks
scripts/lint-ucode.pyandscripts/check-ucode.sh(compiles on the router) pass before any deploy; new directories and entry points are added to both, and executables to the mode check in.github/workflows/ci.yml.