Files
dawnline/tests/ucode/link.test.uc
T
Aemeath dc0f159447
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
Dawnline 0.14.0
- A device is renamed where its name stands on its card: a click on the
  name, Return or Space on it, or Rename in the ⋯ menu turns it into a
  field with the name selected. Return saves, and the words shimmer until
  the router answers. Esc or a click elsewhere puts the old name back. The
  rename window is gone, and the page no longer redraws under a name being
  edited
- Device names take up to 20 characters: letters of any language, digits,
  spaces and - _ . The router refuses anything else when a device is added
  or renamed, so a name can't carry symbols into configurations, file
  names or the AmneziaVPN key. The portal and the admin turn a character
  like that away as it is typed: the field shakes, its outline goes red
  and a short line says why. Suggested names (a phone's model, "Phone 2")
  are stripped of such characters and cut to fit. Names set before this
  stay as they are
- LAN Bypass: Add a device, in the portal and in the admin, has a switch
  that keeps the device's own local network (printer, TV, NAS) reachable
  while it is connected. It is off by default and stays as chosen; the
  admin's device drawer shows it. With home and internet access the switch
  says which addresses still lead to the home network
- Health warns when a server's home network is on one of the subnets home
  routers come with (192.168.0.x, 192.168.1.x and others). People with
  home access who connect from a network on the same addresses reach your
  home instead of their own, LAN Bypass or not
- The router tells when a device can't connect properly. After the problem
  lasts three minutes, the portal card and the admin drawer name it:
  can't finish connecting (the network may block it), connected but no
  data (an outdated configuration, and the card offers Reconnect), on two
  devices at once, or a connection that keeps dropping. Activity lists
  these under Problems, one line per device per hour, and says when the
  device connects normally again
- The set-up sheet's connection line follows what the device does:
  waiting, can't finish, connected, or connected but no data. The sheet
  closes by itself only once data comes through. On the device itself and
  for a router, the steps regroup to what fixes the problem: "Set it up
  again" when the handshake never finishes, "Add the connection again"
  ("Import the configuration again" for a router) when no data comes
- Set-up in the portal: a QR code too long for a camera to read gives its
  place to a code that opens the set-up link (a LAN Bypass configuration
  or a long AmneziaVPN key can be that long). A TV, box or NAS added from
  a phone gets the steps for setting up from another device. Back from
  "Open on the device" keeps the kind, LAN Bypass and the name typed. The
  packet-size note under the kinds is gone
- The portal on phones keeps its place: nothing jumps when an access row
  opens or folds, a notice comes or goes, or Safari redraws the cards. A
  reload, or coming back from the VPN app, opens where the page was. Cards
  glide to their new height, and an animation interrupted half-way goes on
  from where it is instead of snapping. A double click no longer closes
  the sheet it just opened
- In the admin, a device's drawer has its own MTU and keep-alive (empty
  means the server's), each with a Change dialog. A change touches only
  that device's configuration and restarts nothing on the router. Opening
  the drawer no longer counts as handing out the configuration: "Update
  config" stays until the new configuration is shown as a QR code,
  downloaded or copied ("Show the new configuration"). New keys set the
  device up again, as the portal's Reconnect does
- "Speed now" on a server's Overview is live: one point a second over the
  last two minutes, all there as soon as the Overview opens. The agent
  keeps those two minutes in memory and writes them out only while someone
  is looking
- Disguise values that AmneziaWG refuses or crashes on are stopped before
  they reach the kernel. That covers overlapping H1-H4, Jmin above Jmax,
  broken I1-I5 tags, padding under 12 with header protection, and more.
  Import and restore refuse them. After a hand edit in uci, the server's
  tunnel stays down and Health and the service log say why and what to do.
  Errors are full sentences in the reader's language
- The header protection key no longer shows in the status that read-only
  users can see: the Server page says only that the key is set, and each
  device's configuration still has it. The server no longer turns off
  WireGuard's protection against handshake floods (devices keep
  DisableCookies). A device can't be added with a server's own key
- An AmneziaWG update whose kernel module can't be swapped (another
  AmneziaWG interface holds the old one) no longer fails. It is installed,
  the tunnels come back on the old module, and Health and Components say
  the update starts after a reboot. On apk firmware, an install that apk
  left at the old version counts as failed. A module installed by hand is
  recorded, so after a firmware upgrade Health can tell that it is gone
- Dawnline reads only its own tunnels, each one separately. Another
  AmneziaWG interface on the router no longer slows the agent's
  once-a-second check, has its keys read or breaks Dawnline's reads. A
  portal request reads only that person's server: one process however many
  servers there are
- Fewer false disconnects: a tunnel that netifd sets up again no longer
  logs everyone as leaving and coming back, and a device with a long
  keep-alive stays online between handshakes. One configuration on two
  devices isn't logged as roaming every few seconds, and new keys end the
  old session at once. A tunnel that is missing devices is synced within a
  minute, and traffic across a tunnel restart is no longer undercounted
- Renaming a server no longer restarts its tunnel. If a tunnel's interface
  is edited outside Dawnline (LuCI, uci), the watchdog sets it up again
  with Dawnline's settings and names only the changed options. The routing
  rules for "Internet like a home device" change one at a time, new ones
  first, so traffic never falls between them. Health and the Server page
  warn when the address's AAAA record isn't this router's, or the router
  has no public IPv6: devices that prefer IPv6 fail to connect
- The README screenshots come in English and Russian; the portal's are
  taken from its demo. The demo has a switch beside × in the set-up sheet
  to show each state of the connection line. In Russian, long labels in
  the admin's wide option buttons wrap under their icon. DESIGN.md
  describes the switch, renaming on the card, the shimmer, the shake and
  how the portal scrolls. New tests cover link states, the meter, access,
  Health, firewall rules, network settings and packages
2026-10-22 00:11:50 +03:00

333 lines
18 KiB
Ucode

// dawnline.link: what a device's counters say about its link, on synthetic
// sequences of one read a second, run the way the agent's watcher runs them
// (observe, the set-up state at once, then classify and settle when
// something happened or CHECK_EVERY passed); and the pieces on their own.
import * as link from 'dawnline.link';
const T0 = 1800000000;
const A = '203.0.113.7:41821', B = '198.51.100.4:50123';
/*
* `seconds` reads from T0. `at(s)` gives what happened in second s: { drx,
* dtx (bytes in, out), hs (a handshake completed), ep (the endpoint now),
* gone (the peer is not in the tunnel) }. Returns the history, the changes
* of what is shown: [ { s, from, to, since (seconds from T0), ev } ], those of
* the set-up state: [ { s, state } ], and the seconds where the set-up state
* kept by setup() was not what setup_state() gives then (it should never be).
*/
function run(seconds, at, opts) {
opts ??= {};
let ka = opts.ka ?? link.KEEPALIVE, window = opts.window ?? 190;
let h = link.fresh(T0);
let peer = { endpoint: opts.ep ?? A, handshake: opts.hs0 ?? 0, rx: 1000, tx: 1000 };
let changes = [], raws = {}, setups = [], lag = [];
for (let s = 0; s < seconds; s++) {
let t = T0 + s, x = at(s) ?? {};
peer.rx += x.drx ?? 0;
peer.tx += x.dtx ?? 0;
if (x.hs)
peer.handshake = t;
if (x.ep)
peer.endpoint = x.ep;
let on = peer.handshake > 0 && t - peer.handshake < window;
let moved = false;
if (x.gone)
link.gone(h);
else
moved = link.observe(h, peer, t, ka);
if (link.setup(h, t, on, moved))
push(setups, { s, state: h.setup?.state ?? null });
if (link.setup_state(h, t, on).state != (h.setup?.state ?? null))
push(lag, s);
if (!moved && t - h.checked < link.CHECK_EVERY)
continue;
h.checked = t;
link.prune(h, t);
h.raw = link.classify(h, t, on);
if (h.raw)
raws[h.raw] ??= s;
let ch = link.settle(h, h.raw, t, on);
if (ch)
push(changes, { s, from: ch.from, to: ch.to, since: h.since ? h.since - T0 : 0,
ev: link.event_for(ch, { id: 'd_1', person: 'p_1' }, on)?.type ?? null });
}
return { h, changes, raws, setups, lag };
}
// A phone in use: keep-alive 25 s, new keys every ~125 s (the initiation in
// one second, the packet that confirms it in the next), something sent or
// received now and then.
function phone(s, busy) {
let x = {};
if (s % 125 == 3)
x = { drx: 148, dtx: 92 };
else if (s % 125 == 4)
x = { hs: true, drx: 32 };
else if (s % 25 == 0)
x = { drx: 32 };
if (busy && s % 30 < 4)
x = { ...x, drx: (x.drx ?? 0) + 1400, dtx: (x.dtx ?? 0) + 9000 };
return x;
}
test('no state for a phone in use', () => {
let r = run(1800, (s) => phone(s, true));
eq(r.changes, [], 'half an hour of normal use');
eq(r.raws, {}, 'not even for a moment');
});
test('no state for a sleeping phone', () => {
eq(run(1800, (s) => phone(s, false)).changes, [], 'keep-alives and new keys only');
// Then it stops sending at all (deep sleep, out of range): it goes offline, nothing else.
let r = run(1200, (s) => s < 300 ? phone(s, false) : {});
eq(r.changes, [], 'silent after five minutes');
eq(r.raws, {}, 'silence is no failure');
// The same with the disguise's content padding: keep-alives of 42-132 bytes.
eq(run(1800, (s) => s % 25 == 0 ? { drx: 42 + (s % 90) } : phone(s, false), { ka: 132 }).changes, [], 'padded keep-alives');
});
test('no state for a phone that left with traffic still coming', () => {
// Online and busy until 100 s, then gone; the internet keeps sending to it for a while.
let at = (s) => s < 100 ? phone(s, true) : (s % 3 == 0 ? { dtx: 1400 } : {});
eq(run(900, at).changes, [], 'the online window ends it');
eq(run(900, at, { window: 400 }).changes, [], 'a long keep-alive window: no handshake within DROP_HS ends it');
});
test('trying: knocks that never finish connecting', () => {
// Never connected: an initiation every 5 s for 90 s, then a pause, again and again.
let knocking = (s) => (s % 120 < 90 && s % 5 == 0) ? { drx: 148, dtx: 92 } : {};
let r = run(600, knocking);
// The first read is the baseline: the knocks count from 5 s.
eq(r.raws.trying, 15, 'from the third accepted initiation');
eq(r.changes[0], { s: 195, from: null, to: 'trying', since: 15, ev: 'device_failing' }, 'shown once it held 3 minutes');
eq(length(r.changes), 1, 'and kept through the pauses');
// It gets through at 400 s: working again at once.
let r2 = run(600, (s) => s < 400 ? knocking(s) : (s == 400 ? { hs: true, drx: 148 + 1400, dtx: 4000 } : phone(s, true)));
eq(r2.changes[1], { s: 400, from: 'trying', to: null, since: 0, ev: 'device_recovered' }, 'connected: recovered');
// It gives up (the app was turned off): the state goes without a "recovered".
let r3 = run(1200, (s) => s < 300 ? knocking(s) : {});
eq(r3.changes[1].to, null, 'cleared');
eq(r3.changes[1].ev, null, 'nobody saw it work');
// The last knock at 295 s: it ages out of TRY_SPAN by 415 s, and HOLD passes by 595 s.
eq(r3.changes[1].s, 595, 'only after the knocks aged out and HOLD passed');
});
test('trying after a session that ran out', () => {
// Online until 200 s; then its new keys never complete (the answers are lost).
let at = (s) => s < 200 ? phone(s, true) : (s % 5 == 0 ? { drx: 148, dtx: 92 } : {});
let r = run(900, at);
eq(r.changes[0].to, 'trying', 'after the online window');
ok(r.changes[0].s > 129 + 190, 'not while the old session still counted');
});
test('shared: one configuration on two devices', () => {
// Each takes the session from the other every 20 s; the endpoint flips with every packet.
let r = run(600, (s) => ({ hs: s % 20 == 0, drx: 2000, dtx: 6000, ep: s % 2 ? B : A }));
eq(r.raws.shared, 60, 'from the fourth handshake');
eq(r.changes[0], { s: 240, from: null, to: 'shared', since: 60, ev: 'device_failing' }, 'shown once it held');
eq(r.raws.unstable, null, 'never taken for a breaking connection');
// Two devices behind one NAT: one address, two ports.
let r2 = run(600, (s) => ({ hs: s % 20 == 0, drx: 2000, dtx: 6000, ep: s % 2 ? '203.0.113.7:1111' : '203.0.113.7:2222' }));
eq(r2.changes[0]?.to, 'shared', 'told apart by port');
});
test('unstable: connecting over and over from one place', () => {
let r = run(600, (s) => ({ hs: s % 20 == 0, drx: s % 20 < 5 ? 3000 : 0, dtx: s % 20 < 5 ? 9000 : 0 }));
eq(r.raws.unstable, 60, 'from the fourth quick handshake');
eq(r.changes[0], { s: 240, from: null, to: 'unstable', since: 60, ev: 'device_failing' }, 'shown once it held');
// Moving once (wifi to mobile) while it breaks is still the connection, not a second device.
let r2 = run(600, (s) => ({ hs: s % 20 == 0, drx: 3000, dtx: 9000, ep: s < 100 ? A : B }));
eq(r2.changes[0]?.to, 'unstable', 'one move is no alternation');
// It settles down: working again once the quick handshakes left the span.
let r3 = run(1200, (s) => s < 300 ? { hs: s % 20 == 0, drx: 3000, dtx: 9000 } : phone(s, true));
eq(r3.changes[1]?.to, null, 'cleared');
eq(r3.changes[1]?.ev, 'device_recovered', 'online: recovered');
// Normal key renewals never churn, even at RekeyAfterTime's shortest (100 s).
eq(run(1800, (s) => ({ hs: s % 100 == 0, drx: s % 25 == 0 ? 32 : 0 })).changes, [], '3.1 timers');
});
/*
* An old address after renumbering: every packet it sends is dropped after
* decryption (not counted in rx), the router answers with a keepalive every
* ~10 s, the device renews its keys every ~125 s (the first packet under them
* is data, so only the initiation shows in rx).
*/
function renumbered(s) {
if (s % 125 == 3)
return { drx: 148, dtx: 92 };
if (s % 125 == 4)
return { hs: true };
return s % 10 == 7 ? { dtx: 32 } : {};
}
test('dropped: connected, but nothing it sends gets through', () => {
let r = run(900, renumbered, { hs0: T0 - 30 });
// Classified on the router's next answer after DROP_SPAN (187 s).
eq(r.raws.dropped, 187, 'once DROP_SPAN passed without data');
eq(r.changes[0], { s: 367, from: null, to: 'dropped', since: 187, ev: 'device_failing' }, 'shown once it held');
// Imported again at 500 s: data flows, working at once.
let r2 = run(900, (s) => s < 500 ? renumbered(s) : (s == 500 ? { hs: true, drx: 3000, dtx: 9000 } : phone(s, true)), { hs0: T0 - 30 });
eq(r2.changes[1], { s: 500, from: 'dropped', to: null, since: 0, ev: 'device_recovered' }, 'recovered');
// With the disguise's padding the router's answers are bigger; still under DROP_TX.
let r3 = run(900, (s) => { let x = renumbered(s); if (x.dtx == 32) x.dtx = 32 + 1400; return x; }, { hs0: T0 - 30, ka: 132 });
eq(r3.changes[0]?.to, 'dropped', 'padded answers');
// Not before the history covers DROP_SPAN (the agent just started).
eq(run(170, renumbered, { hs0: T0 - 30 }).raws, {}, 'too early to tell');
});
test('counters that restart are a new baseline', () => {
let h = link.fresh(T0);
let peer = { endpoint: A, handshake: T0, rx: 50000, tx: 90000 };
link.observe(h, peer, T0, 32);
peer.rx = 148;
peer.tx = 92;
link.observe(h, peer, T0 + 1, 32);
eq([ h.rx, h.tx, length(h.knocks), h.data ], [ 148, 92, 0, 0 ], 'the peer was added again: no knock, no data');
link.gone(h);
eq(h.rx, null, 'not in the tunnel');
eq(link.observe(h, { ...peer, rx: 5000 }, T0 + 2, 32), false, 'back: a baseline, nothing counted');
eq(h.data, 0, 'no data from the jump');
});
test('knock and bare', () => {
eq([ link.knock(148), link.knock(296), link.knock(444) ], [ true, true, true ], 'one to three initiations');
eq([ link.knock(592), link.knock(180), link.knock(0) ], [ false, false, false ], 'too many, with something else, nothing');
eq([ link.bare(32, 32, false), link.bare(0, 32, false), link.bare(180, 32, true), link.bare(124, 32, true), link.bare(92, 32, true) ],
[ true, true, true, true, true ], 'keepalive, nothing; in a handshake\'s second: initiation + keepalive, response + keepalive, response');
// Plain data is 32 + a multiple of 16: an IPv4 header alone is 64, a TCP ACK 80 or 96.
eq([ link.bare(64, 32, false), link.bare(80, 32, true), link.bare(96, 32, false), link.bare(1480, 32, true), link.bare(5000, 32, false) ],
[ false, false, false, false, false ], 'data');
eq([ link.bare(180, 32, false), link.bare(124, 32, false), link.bare(92, 32, false) ], [ false, false, false ],
'handshake messages only count in the second a handshake completed');
// Padding makes it fuzzy: in a handshake's second anything up to three initiations, a response and a
// padded keepalive; in any other second one padded keepalive, never more.
eq([ link.bare(100, 132, false), link.bare(148 + 132, 132, true), link.bare(3 * 148 + 92 + 132, 132, true), link.bare(3 * 148 + 92 + 133, 132, true) ],
[ true, true, true, false ], 'padded keepalives');
eq([ link.bare(133, 132, false), link.bare(148 + 52, 132, false), link.bare(668, 132, false) ], [ false, false, false ],
'small packets on Maximum: data');
});
test('keepalive_max', () => {
eq(link.keepalive_max(null), 32, 'no server');
eq(link.keepalive_max({ obf: {} }), 32, 'no disguise');
eq(link.keepalive_max({ obf: { content_padding_addition: '10-100' } }), 132, 'content padding');
eq(link.keepalive_max({ obf: { content_padding_addition: '40' } }), 72, 'a fixed padding');
eq(link.keepalive_max({ obf: { content_padding_addition: '10-100', random_trailers: 'on' } }), 132, 'content padding wins over trailers');
eq(link.keepalive_max({ obf: { random_trailers: 'on' } }), 1532, 'random trailers: up to a full packet');
let m = { servers: { s_1: { obf: { content_padding_addition: '10-100' } } }, people: { p_1: { server: 's_1' } },
devices: { d_1: { person: 'p_1' }, d_2: { person: 'p_gone' } } };
eq(link.keepalive_sizes(m), { d_1: 132, d_2: 32 }, 'per device');
});
test('settle holds a state before it shows', () => {
let h = link.fresh(T0);
eq(link.settle(h, 'trying', T0, false), null, 'new: waits');
eq(link.settle(h, 'trying', T0 + link.HOLD - 1, false), null, 'still waits');
eq(link.settle(h, 'trying', T0 + link.HOLD, false), { from: null, to: 'trying' }, 'held: shown');
eq([ h.state, h.since ], [ 'trying', T0 ], 'since it began');
eq(link.settle(h, 'unstable', T0 + 200, true), null, 'another state waits too');
eq(link.settle(h, 'trying', T0 + 210, true), null, 'and is forgotten when the first comes back');
eq(h.pend, null, 'nothing pending');
eq(link.settle(h, null, T0 + 220, true), { from: 'trying', to: null }, 'online and fine: at once');
eq([ h.state, h.since ], [ null, 0 ], 'nothing shown');
eq(link.shown({ d_1: h, d_2: { state: 'shared', since: 5 } }), { d_2: { state: 'shared', since: 5 } }, 'only what shows');
eq(link.event_for({ from: 'shared', to: null }, { id: 'd_2', person: 'p_1' }, true),
{ type: 'device_recovered', person: 'p_1', device: 'd_2', detail: 'shared' }, 'recovered event');
eq(link.event_for({ from: null, to: 'dropped' }, { id: 'd_2', person: 'p_1' }, true),
{ type: 'device_failing', person: 'p_1', device: 'd_2', detail: 'dropped' }, 'failing event');
eq(link.event_for(null, { id: 'd_2' }, true), null, 'no change');
});
// The agent moves the person's revision on every change settle() makes, so a
// state that clears while the device is away (no event) still leaves the page.
test('settle clears a state silently while the device is away', () => {
let h = link.fresh(T0);
link.settle(h, 'trying', T0, false);
link.settle(h, 'trying', T0 + link.HOLD, false);
eq(link.settle(h, null, T0 + 300, false), null, 'it stopped trying: waits');
let ch = link.settle(h, null, T0 + 300 + link.HOLD, false);
eq(ch, { from: 'trying', to: null }, 'then a change: nothing shown');
eq(link.event_for(ch, { id: 'd_1', person: 'p_1' }, false), null, 'without an activity event');
});
/*
* The set-up sheet's states: at once, no HOLD. Each run also checks that the
* state setup() keeps, worked out only when something happened, is what
* setup_state() gives on every read.
*/
test('setup: knocks that never finish connecting', () => {
let knocking = (s) => (s % 120 < 90 && s % 5 == 0) ? { drx: 148, dtx: 92 } : {};
let r = run(300, knocking);
// The first read is the baseline: the knocks count from 5 s.
eq(slice(r.setups, 0, 3), [ { s: 10, state: 'trying' }, { s: 100, state: null }, { s: 125, state: 'trying' } ],
'with the second initiation; gone 15 s after the last one (85 s); back with the next two');
eq(run(130, knocking).h.setup, { state: 'trying', since: T0 + 125 }, 'since it began again');
eq(r.lag, [], 'never behind');
// One initiation that the next second confirms is a connection, not a knock.
let ok1 = run(60, (s) => s == 10 ? { drx: 148, dtx: 92 } : s == 11 ? { hs: true, drx: 32 } : {});
eq(ok1.setups, [], 'one knock, then the handshake: nothing to tell (idle)');
// Knocking again while an older session still counts as online: it is trying now.
let late = run(300, (s) => s < 200 ? phone(s, true) : (s % 5 == 0 ? { drx: 148, dtx: 92 } : {}));
eq(late.setups[length(late.setups) - 1], { s: 205, state: 'trying' }, 'its new keys never complete');
eq(late.lag, [], 'never behind');
});
test('setup: a new device that connects and passes data', () => {
// It knocks at 10 s, the next second its first packets under the new keys carry data.
let at = (s) => s < 10 ? {} : s == 10 ? { drx: 148, dtx: 92 } : s == 11 ? { hs: true, drx: 32 + 1400, dtx: 4000 } : phone(s, true);
let r = run(900, at);
eq(r.setups, [ { s: 11, state: 'flowing' } ], 'flowing with the handshake, and through every new key after');
eq(r.h.setup, { state: 'flowing', since: T0 + 11 }, 'since then');
eq(r.lag, [], 'never behind');
// A first keepalive only, data a few seconds later.
let r2 = run(60, (s) => s == 11 ? { hs: true, drx: 32 } : s == 14 ? { drx: 1400, dtx: 9000 } : {});
eq(r2.setups, [ { s: 14, state: 'flowing' } ], 'with the first data');
// Busy until 300 s, then gone: its session ends 190 s after its last handshake (254 s).
let r3 = run(600, (s) => s < 300 ? phone(s, true) : {});
eq(r3.setups, [ { s: 30, state: 'flowing' }, { s: 444, state: null } ], 'data from 30 s (what came before the handshake does not count); away: nothing');
eq(r3.lag, [], 'never behind');
});
test('setup: idle is not "no data"', () => {
// Connected, keepalives only: the router sends nothing back, nothing to tell.
let r = run(900, (s) => phone(s, false));
eq(r.setups, [], 'a sleeping phone');
eq(r.lag, [], 'never behind');
// The router sends it something now and then, and it answers: data flows.
eq(run(120, (s) => s == 4 ? { hs: true, drx: 32 } : s == 30 ? { dtx: 300, drx: 96 } : {}).setups,
[ { s: 30, state: 'flowing' } ], 'an answer is data');
});
test('setup: connected, but nothing it sends comes through', () => {
// An old address: its first handshake at 4 s, the router's answers to what it drops at 7, 17, 27 s...
let r = run(400, renumbered);
eq(r.setups, [ { s: 19, state: 'nodata' } ], 'SETUP_QUIET after the handshake, with an answer in it');
eq(r.lag, [], 'never behind, through its new keys at 128 s');
// Imported again at 300 s: data flows at once.
let r2 = run(400, (s) => s < 300 ? renumbered(s) : s == 300 ? { hs: true, drx: 3000, dtx: 9000 } : phone(s, true));
eq(r2.setups, [ { s: 19, state: 'nodata' }, { s: 300, state: 'flowing' } ], 'then flowing');
// The router answers only after the quiet span: shown with the answer.
let slow = run(60, (s) => s == 4 ? { hs: true } : s == 25 ? { dtx: 32 } : {});
eq(slow.setups, [ { s: 25, state: 'nodata' } ], 'with the first answer');
eq(slow.lag, [], 'never behind');
});
test('setup: light traffic on Maximum is data', () => {
// Content padding of 10-100: keep-alives of 42-132 bytes. A phone that only sends small packets (a DNS
// query, a SYN, ACKs: 150-600 bytes a second), and an answer now and then in a second it sent nothing.
let at = (s) => s == 3 ? { drx: 148, dtx: 92 } : s == 4 ? { hs: true, drx: 42 } :
s > 4 && s % 3 == 0 ? { drx: 150 + (s % 5) * 100, dtx: 1200 } : s % 7 == 0 ? { dtx: 600 } : {};
let r = run(60, at, { ka: 132 });
eq(r.setups, [ { s: 6, state: 'flowing' } ], 'flowing with its first small packets, never "no data"');
eq(r.lag, [], 'never behind');
// A keep-alive alone in a second is still no data: an idle phone on Maximum stays idle.
eq(run(120, (s) => s == 4 ? { hs: true, drx: 42 } : s % 25 == 0 ? { drx: 42 + (s % 90) } : {}, { ka: 132 }).setups, [],
'padded keep-alives');
});
test('setups', () => {
let h = link.fresh(T0);
eq(link.setups({ d_1: h, d_2: { setup: { state: 'trying', since: 5 } } }), { d_2: { state: 'trying', since: 5 } }, 'only devices with one');
eq(link.setup_state(h, T0, false), { state: null, due: 0 }, 'nothing seen: nothing');
});