mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-12-03 01:37:57 +00:00
beta: ask on every reception, no budget, no backoff, no single slot
An experiment, not a proposed default. Built for rx.on8ar.eu/beta and compiled in only by `REGION_BETA=1 vite build`; a normal build folds the flag to false and drops every branch, which the prod bundle confirms (none of the beta strings survive it). The premise under test, in the requester's words: a moving receiver goes from node to node, so a repeater is never asked often enough to block its own TX window. So this path removes all three throttles at once — the shared one-ask-per-60s airtime budget, the 5/15/30-minute per-target backoff, and the single in-flight slot. Procedure it implements: a reception of a repeater resolves to a full pubkey (advert carries one; discover and path-hash prefixes go through the CoreScope resolve endpoint the app already uses for names), the target is queued, and the queue drains one ask per 2s. A repeater is taken out of rotation only by answering. A target already queued is not queued twice, so the ask rate is the RECEPTION rate rather than a 2s clock; 2s is a floor between transmissions, not a generator. Dropping the single in-flight slot breaks the reply matcher: applyRegionsReply resolves one pending request, and with several outstanding, "something is pending" would file one repeater's regions under another. matchOutstanding keys on the 4-byte tag the companion echoes in its RESP_CODE_SENT ack, an unmatched reply is dropped rather than guessed at, and tags older than 120s are pruned so the map cannot grow without bound. Kept deliberately: the contact-path override (a saved contact with a stale out_path is FLOODed and repeaters ignore flooded requests), and its 20s restore hold. Whether restoring earlier costs the reply is a firmware question, and this experiment is not the place to answer it, so a round that needs an override blocks the queue for 20s. Overrides were needed twice in three field logs. What the field log will have to show, since the per-ask lines roll out of the 200-line buffer: two new header rows carry repeaters answered over repeaters seen, asks sent over replies, and the queue/outstanding/timed-out/unmatched/FLOOD counters. Not addressed here: simple_repeater rate-limits anon requests to 4 per 180s shared across all requesters and all types, so a repeater held in range for minutes will start dropping these. That is part of what the measurement is for. No service worker in this build: it is served from a subdirectory of the production origin, and registering '/sw.js' from there would claim the root scope and serve the experiment to the production URL. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSoyBhrLLtSqLgBMEKMiJV
This commit is contained in:
1 parent
14df2e0438
commit
cf6597cbdb
6 files changed
+387
-7
No files matched your search
+164
-5
@@ -32,6 +32,9 @@ import { buildRfLogRecord } from './capture.js';
|
||||
import { heardKeyAfterVerify } from './advertsig.js';
|
||||
import { buildStatsRequest, parseStats, mergeSample, nextSampleDelay, STATS_CORE, STATS_RADIO, STATS_PACKETS } from './rfstats.js';
|
||||
import { buildRegionsRequest, parseRegionsResponse, parseSentAck, applyRegionsReply, heardAskDecision, pendingExpired, PENDING_TIMEOUT_MS, recordCandidate, commitAsk, undoAsk, SKIP_IN_FLIGHT, SKIP_BUDGET, SKIP_ANSWERED } from './regionreq.js';
|
||||
import {
|
||||
enqueue, dueToSend, takeNext, registerOutstanding, matchOutstanding, pruneOutstanding, markAnswered,
|
||||
} from './regionsprint.js';
|
||||
import { regionsRows } from './regionsview.js';
|
||||
import { uplinkState, uplinkWarning, pushOutcome, regionInertReason, buildLogHeader, REGION_DISCOVERY_MIN_FW } from './uplink.js';
|
||||
import {
|
||||
@@ -86,6 +89,16 @@ const state = {
|
||||
// resolveName returns (see noteRegionsAnswer).
|
||||
answers: [],
|
||||
},
|
||||
// beta: state for the unthrottled experiment (REGION_BETA builds only, see
|
||||
// src/regionsprint.js). queue holds targets heard and not yet asked, outstanding maps
|
||||
// a sent tag to the target that must answer it, answered is the one thing that ever
|
||||
// takes a repeater out of rotation. The counters exist because the 200-line ring
|
||||
// buffer rolls the per-ask lines out long before a drive ends.
|
||||
beta: {
|
||||
queue: [], answered: new Set(), outstanding: new Map(),
|
||||
lastSentAt: null, busy: false, overrideRaw: null,
|
||||
queued: 0, asks: 0, replies: 0, flooded: 0, unmatched: 0, dropped: 0,
|
||||
},
|
||||
// pathResolve: path-hash prefix -> whether it ever resolved to a full pubkey.
|
||||
// A Map, not two counters, because resolvePubkey is called on EVERY reception from
|
||||
// a forwarder and answers from its session cache — counting calls would report the
|
||||
@@ -100,6 +113,10 @@ const REGIONS_ANSWERS_MAX = 200; // display only shows the last 5 (regionsview.j
|
||||
const HEX_COUNT_RES = 10; // fixed res (~90 m cells) for the distinct-hex session counter
|
||||
// Build version, injected from package.json by Vite (see vite.config.js).
|
||||
const VERSION = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : 'dev';
|
||||
// REGION_BETA: the unthrottled region-discovery experiment, compiled in only by
|
||||
// `REGION_BETA=1 vite build` (see vite.config.js). A normal build folds this to false
|
||||
// and drops every branch below it, so the production scheduler is untouched.
|
||||
const REGION_BETA = typeof __REGION_BETA__ !== 'undefined' ? __REGION_BETA__ : false;
|
||||
|
||||
// SNR → colour bucket (LoRa-ish). Returns a CSS colour.
|
||||
function snrColor(snr) {
|
||||
@@ -287,6 +304,131 @@ function commitAndAsk(target, advertTs) {
|
||||
prepareAndAskRegions(target, frame, receipt);
|
||||
}
|
||||
|
||||
// --- BETA: unthrottled ask path (src/regionsprint.js) -------------------------
|
||||
// Compiled in only by REGION_BETA=1. Everything above this block is bypassed: no
|
||||
// airtime budget, no per-target backoff, no single in-flight slot. Every reception of
|
||||
// a repeater queues it, the queue drains one ask per 2s, and a target is dropped only
|
||||
// once it has answered. Replies are matched on the echoed tag, which is the only thing
|
||||
// that can tell several outstanding requests apart.
|
||||
const BETA_ACK_TIMEOUT_MS = 4000;
|
||||
// How long a contact whose path was forced to zero-hop is held that way. Unchanged
|
||||
// from the production path on purpose: whether a restore before the reply arrives
|
||||
// costs the reply is a firmware question this experiment is not the place to answer.
|
||||
// A round that needs an override therefore blocks the queue for this long; overrides
|
||||
// were needed twice in three field logs, so it is rare.
|
||||
const BETA_OVERRIDE_HOLD_MS = 20000;
|
||||
|
||||
// betaEnqueue is the beta twin of maybeAskHeardTarget: it decides nothing, it just
|
||||
// records that this repeater was heard again.
|
||||
function betaEnqueue(target) {
|
||||
if (!state.transport) return;
|
||||
const b = state.beta;
|
||||
if (!featureEnabled(getConfig(), 'regionDiscovery') || !state.regions.supported) { noteRegionInert(); return; }
|
||||
if (enqueue(b.queue, target, b.answered)) b.queued++;
|
||||
}
|
||||
|
||||
// betaTick drains the queue. Called from the one-second monitor tick rather than its
|
||||
// own timer: the app is routinely backgrounded mid-drive, where a setInterval fires
|
||||
// late or not at all, and the tick is already the thing that survives that.
|
||||
function betaTick(now) {
|
||||
const b = state.beta;
|
||||
b.dropped += pruneOutstanding(b.outstanding, now);
|
||||
if (!dueToSend(b.queue, now, b.lastSentAt, b.busy)) return;
|
||||
const target = takeNext(b.queue, b.answered);
|
||||
if (!target) return;
|
||||
betaAsk(target);
|
||||
}
|
||||
|
||||
// betaSendAndReadTag sends one request and resolves with the companion's own
|
||||
// RESP_CODE_SENT ack: { tag, isFlood }, or null when the write failed or no ack came.
|
||||
// The tag is what every later reply is matched against, so an ask whose tag was never
|
||||
// captured is an ask whose answer cannot be attributed to anyone.
|
||||
function betaSendAndReadTag(frame) {
|
||||
return new Promise((resolve) => {
|
||||
if (!state.transport) { resolve(null); return; }
|
||||
const onAck = (dv) => {
|
||||
const ack = parseSentAck(new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength));
|
||||
if (!ack) return;
|
||||
cleanup();
|
||||
resolve(ack);
|
||||
};
|
||||
const timer = setTimeout(() => { cleanup(); resolve(null); }, BETA_ACK_TIMEOUT_MS);
|
||||
function cleanup() { clearTimeout(timer); if (state.transport) state.transport.offFrame(onAck); }
|
||||
state.transport.onFrame(onAck);
|
||||
state.transport.send(frame).catch((e) => {
|
||||
cleanup();
|
||||
dbg('beta: ask never left the phone (' + e.message + ')', 'no');
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function betaAsk(target) {
|
||||
const b = state.beta;
|
||||
b.busy = true;
|
||||
b.lastSentAt = Date.now();
|
||||
let overrode = false;
|
||||
try {
|
||||
const frame = buildRegionsRequest(target);
|
||||
const contact = await getContact(target);
|
||||
if (needsPathOverride(contact)) {
|
||||
localStorage.setItem(RESTORE_STORAGE_KEY, encodePendingRestore(state.companionPubkey, target, contact.raw));
|
||||
const ok = await writeContact(buildOverrideFrame(contact.raw), CONTACT_WRITE_TIMEOUT_MS);
|
||||
if (!ok) dbg('beta: path override for ' + target.slice(0, 12) + '… did not ack — asking anyway', 'no');
|
||||
overrode = true;
|
||||
// The production round tracks one override at a time in state.regions; this path
|
||||
// owns its own restore end to end, so it does not touch that field.
|
||||
b.overrideRaw = contact.raw;
|
||||
}
|
||||
const ack = await betaSendAndReadTag(frame);
|
||||
if (ack == null) {
|
||||
dbg('beta: no send-ack for ' + target.slice(0, 12) + '… — ask not counted', 'no');
|
||||
} else if (ack.isFlood) {
|
||||
b.flooded++;
|
||||
dbg('beta: ' + target.slice(0, 12) + '… went out over FLOOD — repeaters only answer DIRECT', 'no');
|
||||
} else {
|
||||
b.asks++;
|
||||
registerOutstanding(b.outstanding, ack.tag, target, Date.now());
|
||||
dbg('beta → asked ' + target.slice(0, 12) + '… (queue ' + b.queue.length
|
||||
+ ', outstanding ' + b.outstanding.size + ')', 'tx');
|
||||
}
|
||||
if (overrode) {
|
||||
await new Promise((r) => setTimeout(r, BETA_OVERRIDE_HOLD_MS));
|
||||
const restored = await writeContact(buildRestoreFrame(b.overrideRaw), CONTACT_WRITE_TIMEOUT_MS);
|
||||
if (restored) { clearPendingRestore(target); dbg('beta: restored ' + target.slice(0, 12) + '…’s original path', 'st'); }
|
||||
else dbg('beta: restore for ' + target.slice(0, 12) + '… did not ack — will retry on next connect', 'no');
|
||||
}
|
||||
} catch (e) {
|
||||
dbg('beta: ask to ' + target.slice(0, 12) + '… failed: ' + e.message, 'no');
|
||||
} finally {
|
||||
b.overrideRaw = null;
|
||||
b.busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
// betaOnReply is the beta half of onRegionsFrame. Returns whether it consumed the
|
||||
// frame, so the production matcher never sees a reply this path has already filed.
|
||||
function betaOnReply(parsed) {
|
||||
const b = state.beta;
|
||||
const hit = matchOutstanding(b.outstanding, parsed);
|
||||
if (!hit) {
|
||||
b.unmatched++;
|
||||
dbg('beta ← reply tag ' + parsed.tag + ' matches no outstanding ask — dropped, not attributed', 'no');
|
||||
return true;
|
||||
}
|
||||
b.replies++;
|
||||
markAnswered(b.answered, b.queue, hit.target);
|
||||
noteRegionsAnswer(hit.target, hit.regions, hit.truncated);
|
||||
state.queue.add({
|
||||
kind: 'regions', at: new Date().toISOString(), target: hit.target,
|
||||
regions: hit.regions, truncated: hit.truncated, repeater_clock: hit.repeaterClock,
|
||||
rx_pubkey: state.companionPubkey,
|
||||
}).catch((e) => dbg('beta: regions queue failed: ' + e.message, 'no'));
|
||||
dbg('beta ← ' + hit.target.slice(0, 12) + '… declares: ' + (hit.regions.join(',') || '(none)')
|
||||
+ ' (' + b.replies + ' of ' + b.asks + ' asks answered)', 'ok');
|
||||
return true;
|
||||
}
|
||||
|
||||
// abandonAsk hands a target back everything commitAsk charged it, for a request that
|
||||
// never reached the radio: a BLE write that threw put nothing on the air, so it must
|
||||
// cost neither an attempt (which triggers the 5/15/30-minute backoff), nor the shared
|
||||
@@ -499,6 +641,7 @@ function onRegionsFrame(dv) {
|
||||
const bytes = new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength);
|
||||
const parsed = parseRegionsResponse(bytes);
|
||||
if (!parsed) return;
|
||||
if (REGION_BETA && betaOnReply(parsed)) return;
|
||||
const result = applyRegionsReply(state.regions.pending, parsed);
|
||||
if (!result.accepted) {
|
||||
// Do NOT clear pending either way: the real reply for the current target may
|
||||
@@ -659,7 +802,8 @@ function monitorTick() {
|
||||
// The only region-discovery work left on the clock: free a timed-out ask, so the
|
||||
// slot is available to the very next repeater heard instead of one tick later. The
|
||||
// asking itself happens on receptions (maybeAskHeardTarget), never on a timer.
|
||||
expireStalePendingAsk(now);
|
||||
if (REGION_BETA) betaTick(now);
|
||||
else expireStalePendingAsk(now);
|
||||
// A session that started without config must be able to heal without a restart:
|
||||
// retry once a minute (not per tick) for as long as it is missing.
|
||||
if (!getConfig() && (state.lastConfigTryAt == null || now - state.lastConfigTryAt >= 60000)) {
|
||||
@@ -891,7 +1035,8 @@ async function processFrame(dv) {
|
||||
const regionsCfg = getConfig();
|
||||
if (featureEnabled(regionsCfg, 'regionDiscovery') && hk.src === 'advert' && pkt.advertType === ADV_TYPE_REPEATER && pkt.advertTs != null) {
|
||||
const key = recordCandidate(state.regions.candidates, hk.heardKey, pkt.advertTs);
|
||||
maybeAskHeardTarget(hk.heardKey, key);
|
||||
if (REGION_BETA) betaEnqueue(hk.heardKey);
|
||||
else maybeAskHeardTarget(hk.heardKey, key);
|
||||
}
|
||||
// Discover responses are the common case (47h advert intervals mean real adverts are
|
||||
// rare) but carry only an 8-byte pubkey prefix in practice — resolve to the full
|
||||
@@ -905,7 +1050,9 @@ async function processFrame(dv) {
|
||||
if (!pk) return;
|
||||
// The effective key, never the null offered — see recordCandidate. Passing the
|
||||
// null would re-ask a repeater that already answered via a real advert.
|
||||
maybeAskHeardTarget(pk, recordCandidate(state.regions.candidates, pk, null));
|
||||
const key = recordCandidate(state.regions.candidates, pk, null);
|
||||
if (REGION_BETA) betaEnqueue(pk);
|
||||
else maybeAskHeardTarget(pk, key);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -931,7 +1078,9 @@ async function processFrame(dv) {
|
||||
resolvePubkey(hk.heardKey).then((pk) => {
|
||||
state.pathResolve.set(hk.heardKey, !!pk);
|
||||
if (!pk) return;
|
||||
maybeAskHeardTarget(pk, recordCandidate(state.regions.candidates, pk, null));
|
||||
const key = recordCandidate(state.regions.candidates, pk, null);
|
||||
if (REGION_BETA) betaEnqueue(pk);
|
||||
else maybeAskHeardTarget(pk, key);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1326,6 +1475,12 @@ window.addEventListener('DOMContentLoaded', async () => {
|
||||
attempted: state.pathResolve.size,
|
||||
resolved: Array.from(state.pathResolve.values()).filter(Boolean).length,
|
||||
},
|
||||
beta: REGION_BETA ? {
|
||||
queued: state.beta.queued, asks: state.beta.asks, replies: state.beta.replies,
|
||||
answered: state.beta.answered.size, queue: state.beta.queue.length,
|
||||
outstanding: state.beta.outstanding.size, flooded: state.beta.flooded,
|
||||
unmatched: state.beta.unmatched, dropped: state.beta.dropped,
|
||||
} : null,
|
||||
lineCount: lines.length,
|
||||
lineCap: LOG_LINE_CAP,
|
||||
});
|
||||
@@ -1355,7 +1510,11 @@ window.addEventListener('DOMContentLoaded', async () => {
|
||||
window.addEventListener('online', () => {
|
||||
retryConfig().finally(() => { drain().then(refreshCounters).catch(() => {}); });
|
||||
});
|
||||
if ('serviceWorker' in navigator) {
|
||||
// The beta build is served from a subdirectory of the SAME origin as the production
|
||||
// app. Registering '/sw.js' from there would claim the ROOT scope and start serving
|
||||
// the beta bundle to everyone on the production URL, so the experiment ships without
|
||||
// a service worker at all: no offline shell, one less thing to explain in its log.
|
||||
if (!REGION_BETA && 'serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js').catch(() => {});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
// BETA scheduler for region discovery: ask every repeater, every time it is heard,
|
||||
// until it answers. Built as a measurement, not as a replacement for src/regionreq.js.
|
||||
//
|
||||
// What it deliberately does NOT do, all of which the production scheduler does:
|
||||
// - no shared one-ask-per-60s airtime budget
|
||||
// - no per-target retry backoff (5/15/30 minutes)
|
||||
// - no single in-flight slot: several requests may be outstanding at once, so a
|
||||
// reply can no longer be matched by "the one pending request" and is matched on
|
||||
// the 4-byte tag the companion echoes back instead
|
||||
//
|
||||
// The premise under test is that a moving receiver passes from node to node, so the
|
||||
// same repeater is never asked often enough to matter. Two things can falsify it and
|
||||
// this module is instrumented for both: simple_repeater rate-limits anon requests to
|
||||
// 4 per 180s shared across all requesters and all types, and a target parked in range
|
||||
// is re-queued on every single reception.
|
||||
//
|
||||
// Everything here is pure: no DOM, no transport, no timers. app.js does the wiring.
|
||||
|
||||
export const ASK_SPACING_MS = 2000; // minimum gap between two transmitted asks
|
||||
export const OUTSTANDING_TTL_MS = 120000; // how long an unanswered tag stays matchable
|
||||
|
||||
// enqueue adds one target to the back of the queue. A target already queued is not
|
||||
// added twice: it would be asked twice in a row with nothing heard in between, which
|
||||
// measures the queue rather than the mesh. A target that has answered is never queued
|
||||
// again this session — that is the one rule this beta keeps.
|
||||
export function enqueue(queue, target, answered) {
|
||||
if (answered.has(target) || queue.includes(target)) return false;
|
||||
queue.push(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
// dueToSend gates the worker: one ask at a time, at most one per ASK_SPACING_MS.
|
||||
// `busy` covers the whole round including the contact-path override hold, so a
|
||||
// round that has to restore a contact's path cannot be overtaken by the next ask.
|
||||
export function dueToSend(queue, now, lastSentAt, busy, opts = {}) {
|
||||
if (busy || !queue.length) return false;
|
||||
return lastSentAt == null || now - lastSentAt >= (opts.spacingMs ?? ASK_SPACING_MS);
|
||||
}
|
||||
|
||||
// takeNext pops the next target that has not answered in the meantime. A target can
|
||||
// answer while it is still sitting in the queue (a reply to an earlier ask arrives
|
||||
// late), and asking it again would spend airtime on an answer already in hand.
|
||||
export function takeNext(queue, answered) {
|
||||
while (queue.length) {
|
||||
const target = queue.shift();
|
||||
if (!answered.has(target)) return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function registerOutstanding(outstanding, tag, target, now) {
|
||||
outstanding.set(tag, { target, sentAt: now });
|
||||
}
|
||||
|
||||
// matchOutstanding attributes a reply to the request whose tag it echoes. With several
|
||||
// requests in flight the tag is the ONLY evidence of who answered: matching on "some
|
||||
// request is outstanding" would file one repeater's declared regions under another and
|
||||
// store it as fact. An unmatched reply is dropped rather than guessed at.
|
||||
export function matchOutstanding(outstanding, parsed) {
|
||||
if (!parsed || parsed.tag == null) return null;
|
||||
const hit = outstanding.get(parsed.tag);
|
||||
if (!hit) return null;
|
||||
outstanding.delete(parsed.tag);
|
||||
return {
|
||||
target: hit.target,
|
||||
regions: parsed.regions,
|
||||
truncated: parsed.truncated,
|
||||
repeaterClock: parsed.repeaterClock,
|
||||
};
|
||||
}
|
||||
|
||||
// pruneOutstanding drops tags too old to still be answered. Unbounded growth is the
|
||||
// real risk here: this beta transmits up to 30 asks a minute and most go unanswered.
|
||||
// Returns how many were dropped.
|
||||
export function pruneOutstanding(outstanding, now, ttlMs = OUTSTANDING_TTL_MS) {
|
||||
let dropped = 0;
|
||||
for (const [tag, rec] of outstanding) {
|
||||
if (now - rec.sentAt >= ttlMs) { outstanding.delete(tag); dropped++; }
|
||||
}
|
||||
return dropped;
|
||||
}
|
||||
|
||||
// markAnswered records the answer and takes the target out of the queue, so a reply
|
||||
// that lands while the target is queued again cancels that pending ask too.
|
||||
export function markAnswered(answered, queue, target) {
|
||||
answered.add(target);
|
||||
const at = queue.indexOf(target);
|
||||
if (at >= 0) queue.splice(at, 1);
|
||||
}
|
||||
+12
-1
@@ -112,7 +112,7 @@ export function regionInertReason({ config, supported, fwVer }) {
|
||||
export function buildLogHeader(info) {
|
||||
const {
|
||||
version, nowISO, config, fwVer, regionsSupported,
|
||||
companionName, companionPubkey, uplink, pending, lineCount, lineCap, pathResolve,
|
||||
companionName, companionPubkey, uplink, pending, lineCount, lineCap, pathResolve, beta,
|
||||
} = info;
|
||||
const row = (k, v) => k.padEnd(10) + ' ' + v;
|
||||
const onOff = (b) => (b ? 'on' : 'off');
|
||||
@@ -153,6 +153,17 @@ export function buildLogHeader(info) {
|
||||
+ (unresolved > 0 ? ' (' + unresolved + ' ambiguous or unknown)' : '')));
|
||||
}
|
||||
|
||||
// The unthrottled experiment lives or dies on these ratios, and its per-ask lines are
|
||||
// the first thing the ring buffer rolls out: it transmits far more than the
|
||||
// production scheduler ever did. Two separate denominators on purpose — how many
|
||||
// repeaters answered at all, and how many asks that took.
|
||||
if (beta) {
|
||||
lines.push(row('beta', beta.answered + ' of ' + beta.queued + ' repeaters answered, '
|
||||
+ beta.asks + ' asks sent (' + beta.replies + ' answered)'));
|
||||
lines.push(row('beta q', beta.queue + ' queued, ' + beta.outstanding + ' awaiting a reply, '
|
||||
+ beta.dropped + ' timed out, ' + beta.unmatched + ' unmatched replies, ' + beta.flooded + ' sent as FLOOD'));
|
||||
}
|
||||
|
||||
if (companionPubkey) {
|
||||
lines.push(row('companion', (companionName ? companionName + ' · ' : '') + companionPubkey.slice(0, 20) + '…'));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
enqueue, dueToSend, takeNext, registerOutstanding, matchOutstanding,
|
||||
pruneOutstanding, markAnswered, ASK_SPACING_MS, OUTSTANDING_TTL_MS,
|
||||
} from '../src/regionsprint.js';
|
||||
|
||||
const A = 'aa'.repeat(32), B = 'bb'.repeat(32);
|
||||
const reply = (tag) => ({ tag, regions: ['be'], truncated: false, repeaterClock: 100 });
|
||||
|
||||
test('enqueue takes a repeater the first time it is heard', () => {
|
||||
const q = [];
|
||||
assert.equal(enqueue(q, A, new Set()), true);
|
||||
assert.deepEqual(q, [A]);
|
||||
});
|
||||
|
||||
test('enqueue does not queue the same target twice while it is still waiting', () => {
|
||||
// A repeater in range is heard many times a minute. Queuing each reception would
|
||||
// ask it twice in a row with nothing heard in between, which measures the queue
|
||||
// rather than the mesh. It is re-queued by the NEXT reception after it is asked.
|
||||
const q = [A];
|
||||
assert.equal(enqueue(q, A, new Set()), false);
|
||||
assert.deepEqual(q, [A]);
|
||||
});
|
||||
|
||||
test('enqueue never re-queues a repeater that already declared its list', () => {
|
||||
const q = [];
|
||||
assert.equal(enqueue(q, A, new Set([A])), false);
|
||||
assert.deepEqual(q, []);
|
||||
});
|
||||
|
||||
test('dueToSend holds the 2s spacing and refuses while a round is running', () => {
|
||||
const q = [A];
|
||||
assert.equal(dueToSend(q, 1_000_000, null, false), true, 'nothing sent yet');
|
||||
assert.equal(dueToSend(q, 1_000_000, 1_000_000 - 1999, false), false, 'inside the spacing');
|
||||
assert.equal(dueToSend(q, 1_000_000, 1_000_000 - ASK_SPACING_MS, false), true);
|
||||
assert.equal(dueToSend(q, 1_000_000, null, true), false, 'a round is still running');
|
||||
assert.equal(dueToSend([], 1_000_000, null, false), false, 'nothing queued');
|
||||
});
|
||||
|
||||
test('takeNext skips a target that answered while it sat in the queue', () => {
|
||||
const q = [A, B];
|
||||
assert.equal(takeNext(q, new Set([A])), B);
|
||||
assert.deepEqual(q, []);
|
||||
});
|
||||
|
||||
test('takeNext returns null once the queue holds nothing askable', () => {
|
||||
const q = [A];
|
||||
assert.equal(takeNext(q, new Set([A])), null);
|
||||
});
|
||||
|
||||
test('a reply is attributed by the tag it echoes, not by "something is outstanding"', () => {
|
||||
// Several requests are in flight at once here, so the tag is the only evidence of
|
||||
// who answered. Getting this wrong files one repeater's regions under another.
|
||||
const out = new Map();
|
||||
registerOutstanding(out, 0x1111, A, 1_000_000);
|
||||
registerOutstanding(out, 0x2222, B, 1_000_002);
|
||||
const hit = matchOutstanding(out, reply(0x2222));
|
||||
assert.equal(hit.target, B);
|
||||
assert.equal(out.has(0x2222), false, 'the answered tag is consumed');
|
||||
assert.equal(out.has(0x1111), true, 'the other request stays matchable');
|
||||
});
|
||||
|
||||
test('a reply whose tag matches nothing outstanding is dropped, not guessed at', () => {
|
||||
const out = new Map();
|
||||
registerOutstanding(out, 0x1111, A, 1_000_000);
|
||||
assert.equal(matchOutstanding(out, reply(0xdeadbeef)), null);
|
||||
assert.equal(out.size, 1);
|
||||
});
|
||||
|
||||
test('pruneOutstanding drops tags too old to still be answered', () => {
|
||||
const out = new Map();
|
||||
registerOutstanding(out, 0x1111, A, 1_000_000);
|
||||
registerOutstanding(out, 0x2222, B, 1_000_000 + OUTSTANDING_TTL_MS);
|
||||
assert.equal(pruneOutstanding(out, 1_000_000 + OUTSTANDING_TTL_MS), 1);
|
||||
assert.deepEqual(Array.from(out.keys()), [0x2222]);
|
||||
});
|
||||
|
||||
test('markAnswered also cancels the ask this target has queued', () => {
|
||||
const q = [B, A];
|
||||
const answered = new Set();
|
||||
markAnswered(answered, q, A);
|
||||
assert.deepEqual(q, [B]);
|
||||
assert.equal(answered.has(A), true);
|
||||
});
|
||||
@@ -251,3 +251,29 @@ test('no path-hash prefix tried yet prints no row at all rather than a misleadin
|
||||
assert.doesNotMatch(buildLogHeader({ ...BASE, pathResolve: { attempted: 0, resolved: 0 } }), /path keys/);
|
||||
assert.doesNotMatch(buildLogHeader(BASE), /path keys/);
|
||||
});
|
||||
|
||||
// --- BETA header rows (REGION_BETA builds only) -------------------------------
|
||||
// The unthrottled experiment transmits far more than the production scheduler, so its
|
||||
// per-ask lines roll out of the 200-line ring buffer long before a drive ends. The
|
||||
// ratios that decide whether it works have to survive in the header.
|
||||
|
||||
test('buildLogHeader reports the beta counters when the experiment is running', () => {
|
||||
const h = buildLogHeader({
|
||||
version: '1.14.0-beta-sprint', nowISO: 'now', config: null, fwVer: 13, regionsSupported: true,
|
||||
uplink: 'ok', pending: 0, lineCount: 1, lineCap: 200,
|
||||
beta: {
|
||||
queued: 22, asks: 61, replies: 7, answered: 7, queue: 3,
|
||||
outstanding: 5, flooded: 1, unmatched: 2, dropped: 12,
|
||||
},
|
||||
});
|
||||
assert.match(h, /beta {7}7 of 22 repeaters answered, 61 asks sent \(7 answered\)/);
|
||||
assert.match(h, /beta q {5}3 queued, 5 awaiting a reply, 12 timed out, 2 unmatched replies, 1 sent as FLOOD/);
|
||||
});
|
||||
|
||||
test('buildLogHeader leaves the beta rows out of a production build', () => {
|
||||
const h = buildLogHeader({
|
||||
version: '1.14.0', nowISO: 'now', config: null, fwVer: 13, regionsSupported: true,
|
||||
uplink: 'ok', pending: 0, lineCount: 1, lineCap: 200, beta: null,
|
||||
});
|
||||
assert.doesNotMatch(h, /beta/);
|
||||
});
|
||||
+11
-1
@@ -4,8 +4,18 @@ import { readFileSync } from 'fs';
|
||||
// Inject the package.json version so the app can display which build is running.
|
||||
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
||||
|
||||
// REGION_BETA=1 builds the unthrottled region-discovery experiment (src/regionsprint.js)
|
||||
// instead of the production scheduler. It is a separate deployment (rx.on8ar.eu/beta),
|
||||
// never the default: a normal build compiles the flag to false and drops that code.
|
||||
const beta = process.env.REGION_BETA === '1';
|
||||
|
||||
export default defineConfig({
|
||||
// The beta is served from /beta/ on the same host as the production app, so its
|
||||
// asset URLs have to be rewritten. Set here rather than passed as --base=/beta/,
|
||||
// which Git Bash on Windows rewrites into a filesystem path before Vite sees it.
|
||||
base: beta ? '/beta/' : '/',
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(pkg.version),
|
||||
__APP_VERSION__: JSON.stringify(pkg.version + (beta ? '-beta-sprint' : '')),
|
||||
__REGION_BETA__: JSON.stringify(beta),
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user