Dawnline 0.8.1
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 / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions

- Fixed: the Overview's map stayed empty after leaving the page and coming
  back (the map freed on leaving was never made again); a map still loading
  when freed no longer draws into a dropped element
- A new connection's city shows within seconds: the agent looks its address
  up the moment the device connects or roams, in a child process so the
  watcher never waits, and open pages refresh once the place is known; the
  connection's entry in the activity log gets its place too. Since 0.7.0 the
  lookup waited for the minute tick and the pages for their 30-second poll
- Device window: each place has a strip of when the device was there (from
  the log's connections) and its share of the time; ▶ replays the period on
  the map: the place it leaves goes gray, a blue shimmer runs along a dotted
  arc to the next one, which lights up. A click or a drag on a strip goes to
  that moment; short visits are folded only past 24 moves. The fixed trail
  line is gone, and place names are no longer cut off at the map's edges
- Overview: the disguise tile's icon is gray when the disguise is Off
- People: "Add device" is a dashed chip with its label; "Send invite" is gone
  from the card (the invite card stays in its ⋯ menu)
This commit is contained in:
Aemeath committed 2026-10-19 00:48:09 +03:00
1 parent 466ca6c7b0
commit 7a6370aa9e
21 files changed
+1241 -193

No files matched your search

@@ -154,41 +154,6 @@ function check_people(m, states, events) {
}
}
let last_home = 0;
// Addresses the watcher saw connect since the last tick: looked up first.
let geo_pending = {};
/**
* Locate client addresses for the admin map: the ones that just connected
* first, then anything still shown that is missing or stale — a few per
* minute, within a time budget, so a slow service never holds the tick.
*/
function check_geo(m) {
if (!m.settings.geo_enabled) {
geo_pending = {};
return;
}
let cache = geo.load();
let ips = keys(geo_pending);
geo_pending = {};
for (let id, rec in usage.devices)
for (let ip in keys(rec.ips ?? {}))
push(ips, ip);
let changed = geo.resolve(m.settings, cache, uniq(ips), 3, 12);
if (time() - last_home > 3600) {
last_home = time();
let wan = live.iface_status('wan')?.['ipv4-address']?.[0]?.address;
changed = geo.resolve_home(m.settings, cache, wan) || changed;
}
if (changed)
geo.save(cache);
}
function place_of(ip) {
let pl = geo.place(geo.load(), ip);
return pl ? join(' · ', filter([ pl.city, pl.org ], (x) => x)) : null;
}
/** Connections from home: the DHCP name of the address, as it is now. */
function named(e) {
let h = net.event_hosts(e, net.lan_names());
@@ -225,6 +190,116 @@ function save_presence(people) {
write_json(live.PRESENCE, { online: last_online, endpoint: last_endpoint, rev, people: person_rev }, 0o600);
}
/* ---------- locations ---------- */
// A lookup run: this many addresses at most, within this many seconds; a run
// still going after GEO_KILL seconds (past every timeout) is given up.
const GEO_PER_RUN = 3;
const GEO_BUDGET = 12;
const GEO_KILL = 60;
let last_home = 0;
// Addresses the watcher saw connect or roam that wait for a run.
let geo_pending = {};
// The run in a child process (uloop.task) and when it started; null when none.
let geo_task = null, geo_since = 0;
/** Every client address still shown on the map (the cache never pushes these out). */
function geo_shown() {
let ips = [];
for (let id, rec in usage.devices)
for (let ip in keys(rec.ips ?? {}))
push(ips, ip);
return uniq(ips);
}
/*
* A run's results: into the cache (the agent is its only writer), onto the
* connections in the activity log that were logged before their place was
* known, and to open pages at once: the revision moves for the people seen
* from those addresses.
*/
function geo_done(found) {
let cache = geo.load();
if (type(found) != 'object' || !geo.merge(cache, found, geo_shown()))
return;
geo.save(cache);
let where = {};
for (let ip, r in found)
if (r)
where[ip] = geo.label(r);
if (!length(keys(where)))
return;
let m = watch_model(), people = {};
for (let id, rec in usage.devices)
for (let ip in keys(where))
if (rec.ips?.[ip] && m.devices[id])
people[m.devices[id].person] = true;
live.set_places(where, time() - 3600);
save_presence(keys(people));
}
/*
* Locate client addresses for the admin map in a child process: a lookup
* waits on the network for seconds, and neither the 1-second watcher nor the
* tick may wait with it. Addresses that just connected go first, at once
* (the watcher calls this on a connect); the tick adds anything still shown
* that is missing or stale (`more`). One run at a time, a few addresses each;
* what just connected and did not fit waits for the next run.
*/
function geo_lookup(m, more) {
if (!m.settings.geo_enabled) {
geo_pending = {};
return;
}
if (geo_task && !geo_task.finished()) {
if (time() - geo_since < GEO_KILL)
return;
geo_task.kill();
}
geo_task = null;
let todo = geo.stale(geo.load(), [ ...keys(geo_pending), ...(more ?? []) ]);
let want = slice(todo, 0, GEO_PER_RUN);
let rest = {};
for (let ip in slice(todo, GEO_PER_RUN))
if (geo_pending[ip])
rest[ip] = true;
geo_pending = rest;
if (!length(want))
return;
let provider = m.settings.geo_provider;
let t = null;
t = uloop.task(() => {
// The child shares the instance lock: it must not keep it past the agent (a restart would find it taken).
instance.close();
return geo.lookup_all(provider, want, GEO_PER_RUN, GEO_BUDGET);
}, (found) => {
if (geo_task == t)
geo_task = null;
geo_done(found);
if (length(keys(geo_pending)))
geo_lookup(watch_model());
});
geo_task = t;
geo_since = time();
}
/** The tick: shown addresses missing or stale get a run; the router's own place about hourly. */
function check_geo(m) {
geo_lookup(m, geo_shown());
if (!m.settings.geo_enabled || time() - last_home <= 3600)
return;
last_home = time();
let cache = geo.load();
let wan = live.iface_status('wan')?.['ipv4-address']?.[0]?.address;
if (geo.resolve_home(m.settings, cache, wan))
geo.save(cache);
}
function place_of(ip) {
return geo.label(geo.place(geo.load(), ip));
}
/*
* One look at the tunnels. Connects (a new handshake from a device that was
* away), disconnects (its session expired: no handshake for live.ONLINE_WINDOW;
@@ -282,16 +357,19 @@ function watch() {
return;
live.collect(m, usage, d);
live.save_usage(usage, false);
// A location lookup waits on the network: never here, on the next tick
// (check_geo). The event carries the place when the cache already knows it.
if (m.settings.geo_enabled)
for (let ip in ips)
geo_pending[ip] = true;
// The event carries the place when the cache already knows it. A new
// address is looked up at once, in a child process (geo_lookup): its place
// goes onto this event and the revision moves again when it is known.
for (let e in events)
if (e.type == 'connect')
e.where = place_of(e.detail);
live.add_events(map(events, (e) => e.type == 'disconnect' ? e : named(e)), live.policy(m.settings.retention));
save_presence(keys(people));
if (m.settings.geo_enabled && length(ips)) {
for (let ip in ips)
geo_pending[ip] = true;
geo_lookup(m);
}
}
// What the service log was already told. On flash: the public address often
@@ -3,8 +3,9 @@
// Client addresses are looked up once with a third-party service (ipwho.is,
// ipapi.co as fallback) and cached: the live copy in RUN_DIR (tmpfs), put on
// flash (DATA_DIR/geo.json) by flush() about hourly, like the usage
// counters. Only the agent performs lookups, on its minute tick and within a
// time budget, never on the 1-second watcher; the UI reads the cache.
// counters. Only the agent performs lookups, in a child process (the network
// may take seconds; neither its watcher nor its tick waits for them) and
// merges them into the cache itself; the UI reads the cache.
import { stat } from 'fs';
import { read_json, write_json, sh_out, q, ensure_dir, ip2int, DATA_DIR, RUN_DIR } from 'dawnline.util';
@@ -13,7 +14,7 @@ const CACHE = `${RUN_DIR}/geo.json`;
const SAVED = `${DATA_DIR}/geo.json`;
const TTL = 30 * 86400;
const RETRY = 86400;
// Entries kept at least; addresses still shown are never pushed out (resolve).
// Entries kept at least; addresses still shown are never pushed out (merge).
const CAP = 500;
// [base, prefix] of ranges with no meaningful location (private, CGNAT, multicast, …).
@@ -99,40 +100,64 @@ export function lookup(provider, ip) {
};
/**
* Resolve up to `max` of `ips` that are missing or stale, within `budget`
* seconds (each lookup may wait on the network). Returns true when the cache
* changed (the caller saves it). `ips` is also what is still shown: the cache
* is kept bounded by dropping other entries only, oldest first, so a lookup
* is never repeated for an address that is still on the map.
* The public addresses of `ips` the cache does not know or knows from too
* long ago (a failed lookup is retried after a day), once each and in order.
* Returns an empty array when there is nothing to look up.
*/
export function resolve(settings, cache, ips, max, budget) {
let now = time(), changed = false, done = 0;
let started = now;
export function stale(cache, ips, ts) {
let now = ts ?? time(), out = [], seen = {};
for (let ip in ips) {
if (done >= max || (budget != null && time() - started >= budget))
break;
if (!is_public(ip))
if (seen[ip] || !is_public(ip))
continue;
seen[ip] = true;
let c = cache.ips[ip];
if (c && ((c.fail && now - c.fail < RETRY) || (!c.fail && c.asn != null && now - c.ts < TTL)))
continue;
let r = lookup(settings.geo_provider, ip);
done++;
changed = true;
if (r) {
delete r.ip;
r.ts = now;
cache.ips[ip] = r;
}
else
cache.ips[ip] = { fail: now };
push(out, ip);
}
let shown = {};
for (let ip in ips)
shown[ip] = true;
return out;
};
/**
* Look up at most `max` of `ips`, within `budget` seconds (each lookup may
* wait on the network). Returns { ip: place, or false when the services had
* nothing } for the ones tried. Network only, no cache: the agent runs it in
* a child process and merges the result itself.
*/
export function lookup_all(provider, ips, max, budget) {
let started = time(), out = {}, done = 0;
for (let ip in ips) {
if (done >= max || (budget != null && time() - started >= budget))
break;
let r = lookup(provider, ip);
done++;
if (r)
delete r.ip;
out[ip] = r ?? false;
}
return out;
};
/**
* Put lookup_all() results into the cache. Returns true when the cache
* changed (the caller saves it). `shown` is what is still on the map: the
* cache is kept bounded by dropping other entries only, oldest first, so a
* lookup is never repeated for an address that is still on the map.
*/
export function merge(cache, found, shown, ts) {
let now = ts ?? time(), changed = false;
for (let ip, r in found) {
if (!is_public(ip))
continue;
cache.ips[ip] = r ? { ...r, ts: now } : { fail: now };
changed = true;
}
let keep = {};
for (let ip in shown)
keep[ip] = true;
let all = keys(cache.ips);
if (length(all) > CAP) {
let other = sort(filter(all, (ip) => !shown[ip]),
let other = sort(filter(all, (ip) => !keep[ip]),
(a, b) => (cache.ips[a].ts ?? cache.ips[a].fail ?? 0) - (cache.ips[b].ts ?? cache.ips[b].fail ?? 0));
for (let i = 0; i < length(all) - CAP && i < length(other); i++) {
delete cache.ips[other[i]];
@@ -159,6 +184,11 @@ export function place(cache, ip) {
return (c && !c.fail) ? c : null;
};
/** "City · ISP" for the activity log; null for no place. */
export function label(pl) {
return pl ? join(' · ', filter([ pl.city, pl.org ], (x) => x)) : null;
};
export function clear() {
save({ ips: {}, home: null });
ensure_dir(DATA_DIR, 0o700);
@@ -395,6 +395,35 @@ export function add_event_merged(e, window) {
unlock(l);
};
/**
* Places for connections logged before their address was located (the
* lookup finishes after the event): connect events since `since` from an
* address in `where` ({ ip: "City · ISP" }) that have no place yet get it.
* Returns true when `ev` changed.
*/
export function fill_places(ev, where, since) {
let changed = false;
for (let i = length(ev) - 1; i >= 0 && ev[i].ts >= since; i--) {
let e = ev[i];
if (e.type == 'connect' && !e.where && where[e.detail]) {
e.where = where[e.detail];
changed = true;
}
}
return changed;
};
/** fill_places() on the live log, written only when something changed. */
export function set_places(where, since) {
let l = lock('events');
let ev = load_events();
if (fill_places(ev, where, since)) {
ensure_dir(RUN_DIR);
write_json(`${RUN_DIR}/events.json`, ev, 0o600);
}
unlock(l);
};
/** Save the log to flash, or drop the flash copy when it is kept in RAM only. */
export function persist_events(pol) {
pol ??= policy();
@@ -4,7 +4,7 @@
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
export const VERSION = '0.8.0';
export const VERSION = '0.8.1';
/** GitHub repository with Dawnline releases (updates and the installer). */
export const REPO = 'tickcount/luci-app-dawnline';
export const RUN_DIR = '/var/run/dawnline';