- 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/
This commit is contained in:
1 parent
6444722d14
commit
29b1d7dfd7
26 files changed
+419
-104
No files matched your search
@@ -97,7 +97,7 @@ function connected(dmp, d, who) {
|
||||
let peer = peer_of(dmp, d);
|
||||
if (!peer || !(peer.handshake > 0))
|
||||
return step(false, `${who} has never connected`, 'There is no session the router could reach.');
|
||||
if (time() - peer.handshake >= live.ONLINE_WINDOW)
|
||||
if (!live.online(dmp, d.id, peer))
|
||||
return step(false, `${who} isn't connected right now`, 'The router reaches it only while its VPN is on.');
|
||||
return step(true, `${who} is connected`, '');
|
||||
}
|
||||
|
||||
@@ -12,7 +12,10 @@ import {
|
||||
} from 'dawnline.util';
|
||||
import * as awg from 'dawnline.awg';
|
||||
|
||||
export const ONLINE_WINDOW = 300;
|
||||
// Online while the WireGuard session lives: it is dropped 180 s after its
|
||||
// handshake, and a device that is there renews it every 2 min (a little slack
|
||||
// for a renewal that needs a retry). One that left goes offline 1-3 min later.
|
||||
export const ONLINE_WINDOW = 190;
|
||||
const KEEP_DAYS = 62;
|
||||
const KEEP_MONTHS = 24;
|
||||
const KEEP_EVENTS = 2000;
|
||||
@@ -82,12 +85,42 @@ function trim_events(ev, pol) {
|
||||
|
||||
/* ---------- live peers ---------- */
|
||||
|
||||
/* ---------- presence (the agent's watcher) ---------- */
|
||||
|
||||
/**
|
||||
* Written by the agent's watcher on every change: { online: { device id: bool },
|
||||
* endpoint: { device id: ip }, rev, people: { person id: rev } }. `rev` moves on
|
||||
* any connect, disconnect, roam or logged change; `people` per person (the portal).
|
||||
*/
|
||||
export const PRESENCE = `${RUN_DIR}/presence.json`;
|
||||
// The agent's heartbeat (dawnline.watchdog.BEAT): its presence counts while it runs.
|
||||
const BEAT = `${RUN_DIR}/agent.beat`;
|
||||
const BEAT_STALE = 180;
|
||||
|
||||
/** What the watcher sees, or null when the agent isn't running. */
|
||||
export function presence() {
|
||||
let beat = +(read_json(BEAT, 0) ?? 0);
|
||||
if (!beat || time() - beat > BEAT_STALE)
|
||||
return null;
|
||||
return read_json(PRESENCE, null);
|
||||
};
|
||||
|
||||
/**
|
||||
* Peers of every tunnel: { ok, ifaces, peers: { public key: { ifname, endpoint,
|
||||
* handshake, rx, tx } } }. See dawnline.awg.
|
||||
* handshake, rx, tx } }, presence }. See dawnline.awg.
|
||||
*/
|
||||
export function dump(m) {
|
||||
return awg.dump();
|
||||
let d = awg.dump();
|
||||
d.presence = presence();
|
||||
return d;
|
||||
};
|
||||
|
||||
/** A device is online: as the agent's watcher says, or (without the agent) by a recent handshake. */
|
||||
export function online(dmp, id, peer) {
|
||||
let p = dmp?.presence?.online;
|
||||
if (p)
|
||||
return !!(peer && p[id]);
|
||||
return !!(peer && peer.handshake > 0 && time() - peer.handshake < ONLINE_WINDOW);
|
||||
};
|
||||
|
||||
export function endpoint_ip(ep) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Dawnline rpcd methods: the Overview status (servers, people, totals, map,
|
||||
// recent activity), the activity log and traffic history.
|
||||
// Dawnline rpcd methods: the live revision, the Overview status (servers,
|
||||
// people, totals, map, recent activity), the activity log and traffic history.
|
||||
|
||||
import { readfile } from 'fs';
|
||||
import { read_json, write_json, ensure_dir, lock, unlock, admin_log, VERSION, RUN_DIR } from 'dawnline.util';
|
||||
@@ -23,7 +23,7 @@ function geo_view(m, usage, dmp) {
|
||||
let rec = usage.devices?.[id];
|
||||
let peer = dmp.peers[d.public_key];
|
||||
let cur = live.endpoint_ip(peer?.endpoint);
|
||||
let online = !!(peer && peer.handshake > 0 && now - peer.handshake < live.ONLINE_WINDOW);
|
||||
let online = live.online(dmp, id, peer);
|
||||
for (let ip, ts in rec?.ips ?? {}) {
|
||||
// Local (LAN / CGNAT) client addresses are not shown on the map.
|
||||
let pl = geo.is_public(ip) ? geo.place(cache, ip) : null;
|
||||
@@ -60,12 +60,15 @@ function with_hosts(ev) {
|
||||
}
|
||||
|
||||
function server_view(m, srv, usage, dmp, rates, days) {
|
||||
let online = 0, peers = 0, now = time();
|
||||
let online = 0, peers = 0;
|
||||
let links = map(core.tunnels(srv), (t) => t.ifname);
|
||||
let ids = {};
|
||||
for (let id, d in m.devices)
|
||||
ids[d.public_key] = id;
|
||||
for (let k, p in dmp.peers)
|
||||
if (index(links, p.ifname) >= 0) {
|
||||
peers++;
|
||||
if (p.handshake > 0 && now - p.handshake < live.ONLINE_WINDOW)
|
||||
if (live.online(dmp, ids[k], p))
|
||||
online++;
|
||||
}
|
||||
let st = srv.private_key ? awg.server_state(srv) : { up: false, uptime: 0 };
|
||||
@@ -221,7 +224,13 @@ function usage_clear(a) {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
/** The live revision (dawnline.live.PRESENCE): pages refresh when it moves; 0 without the agent. */
|
||||
function rev() {
|
||||
return { rev: +(live.presence()?.rev ?? 0) };
|
||||
}
|
||||
|
||||
export const methods = {
|
||||
rev: { call: wrap(rev) },
|
||||
status: { args: { days: 30 }, call: wrap(status) },
|
||||
events: { args: { limit: 300 }, call: wrap(events_list) },
|
||||
logs_clear: { args: { person: '', device: '', category: '', older_days: '' }, call: wrap(logs_clear) },
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
|
||||
|
||||
export const VERSION = '0.4.1';
|
||||
export const VERSION = '0.4.2';
|
||||
/** GitHub repository with Dawnline releases (updates and the installer). */
|
||||
export const REPO = 'tickcount/luci-app-dawnline';
|
||||
export const RUN_DIR = '/var/run/dawnline';
|
||||
|
||||
@@ -37,7 +37,7 @@ export function device_view(m, d, usage, dmp) {
|
||||
disabled: d.disabled,
|
||||
created: d.created,
|
||||
created_by: d.created_by,
|
||||
online: !!(peer && peer.handshake > 0 && ts - peer.handshake < live.ONLINE_WINDOW),
|
||||
online: live.online(dmp, d.id, peer),
|
||||
handshake: hs,
|
||||
endpoint: live.endpoint_ip(peer?.endpoint) || u?.endpoint || '',
|
||||
active: !!peer,
|
||||
|
||||
Reference in new issue
Block a user