Commit Graph
18 Commits
Author SHA1 Message Date
efiten dd512261a4 regions: name the companion's refusal of an ask instead of 'no send-ack'
A companion up to firmware v1.16 answers CMD_SEND_ANON_REQ for a repeater that is not a
contact with ERR_CODE_TABLE_FULL when its contact list is full
(BaseChatMesh::allocateContactSlot); v1.17 reserves 8 slots for these asks. The app only
listened for RESP_CODE_SENT, so the refusal showed as a 4-second 'no send-ack'. The ask
now resolves on that error, logs the cause, and the header counts the refusals.
2026-11-11 21:22:42 +01:00
efitenandClaude Opus 5.5 5da69305b8 feat: ask a repeater without a CoreScope name for its own name
Field case 2026-10-16: c0cdee59e0db981b answered every discover sweep,
but CoreScope has never seen its advert, so it stayed a bare prefix and
got no regions ask either.

- nodeNames flag (on when config.json exists and omits it, off without
  a config, like regionDiscovery). With it on, discover requests drop
  DISCOVER_PREFIX_ONLY, so replies carry the full 32-byte pubkey
  (+24 bytes each, simple_repeater/MyMesh.cpp:824).
- A repeater heard in range is looked up once per session. Only when
  CoreScope answers without a name is it asked ANON_REQ_TYPE_OWNER
  (MyMesh.cpp:165). The reply is "name\nowner_info"; owner_info is
  dropped.
- Name and regions asks share one queue and one per-encounter budget
  (src/asknext.js): the companion keeps one pending anon request
  (companion_radio/MyMesh.cpp:1570) and the repeater limiter is shared
  across request types. The name is asked first.
- The name replaces the prefix in the recent list and regions card, and
  is published on meshcore/client/{pk}/names as NODE_NAME with the
  companion's fix. New topic; /packets is unchanged.
- Debug header: a names row and nodeNames in the config row.

Not done: CoreScope does not ingest /names yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 09:25:48 +02:00
efitenandClaude Opus 5 8bfadeaac8 feat: pace region discovery by what the radio hears, not by a clock
The scheduler had three limits and four drives showed each one costing answers rather
than protecting anything. All three are gone; what replaces them is bounded by the
repeater firmware's own limiter instead of by a clock of our own invention.

The shared one-ask-per-60s airtime budget. One ask, from wherever, blocked every
repeater heard in the following minute. The 2026-09-11 80 km log has a2cf63b9fd89 asked
at 18:24:55 on rssi -120 and silent, then heard at 18:25:26 on -102 — 18 dB stronger —
and skipped, because the budget had gone on the weaker reception 31 seconds earlier and
that same ask had put it into backoff.

The 5/15/30-minute per-target backoff, counted per session. A repeater asked once from a
bad spot was locked out for the rest of the drive. It is replaced by an encounter: three
unanswered asks at least 30s apart, then left alone until it has been out of earshot for
five minutes, after which the next reception is a new encounter with a fresh run. Three
asks 30s apart is 3 in any 180s window, inside simple_repeater's 4 anon requests per
180s shared across all requesters — the cap is what keeps us there, not the spacing.

The single in-flight slot. It capped the feature at three asks a minute, and at one per
session whenever a request went unanswered. Several requests can now be outstanding, so
replies are attributed on the 4-byte tag the companion echoes back and an unmatched
reply is dropped rather than guessed at: "something is pending" would file one
repeater's declared regions under another and store it as fact.

Measured, not assumed. A build without the three limits sent 15 asks and got 6 answers;
v1.14.0 on a comparable run sent 5 and got 1. That build is the one merged here (the
beta/regions-sprint commits below), with the pacing tightened from 15s/6 asks to
30s/3 asks so one repeater sees strictly less than the firmware allows one client.

Also here: every ask now carries the snr and rssi of the reception that triggered it,
into the reply or into the timeout. Four drives point at a split — every ask at snr
+1.75 dB or better was answered, every one at -1.25 dB or worse was not — that until now
had to be assembled by hand from pairs of log lines the ring buffer rolls out mid-drive.
No signal floor is applied; this is the measurement that would justify one.

Deleted rather than left behind: selectNextTarget's successors (heardAskDecision,
commitAsk, undoAsk, isTargetDue, dueDelayMs, retryBackoffFor, recordCandidate,
applyRegionsReply, pendingExpired) and monitor's regionDiscoverDue/REGION_INTERVAL_MS.
regionreq.js is framing only now; regionsched.js owns the scheduling.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HSoyBhrLLtSqLgBMEKMiJV
2026-09-12 12:59:06 +02:00
efitenandClaude Opus 5 14df2e0438 feat: ask a repeater only while it is being heard, and refund an ask that never left
Twelve minutes of the 2026-09-11 v1.13.0 log: six region requests, one answer. The one
that was answered fired on a live reception and came back in two seconds. The other five
each charged their target an attempt and dropped it into the 5/15/30-minute backoff, so
e3d3f4d7edd0 (heard directly at 12:04:54 and 12:09:32) and 6b8c65b77cf3 (12:03:53,
12:08:02, 12:10:05) could not be asked while they were demonstrably in range.

Two separate causes, both in the ask bookkeeping rather than in the framing or the reply
matcher, and each fixed at its own site.

The 60s timer fallback is removed. selectNextTarget picked from the whole session pool
with no notion of range, which at road speed is a repeater already passed: 12:04:37 to
e470a7fd67fa, last heard 5m45s earlier, and 12:05:38 to 01fa326b4758 are the two clean
examples in the log, neither answered. Since 52b7ff5 those asks also stamp the shared
one-ask-per-60s airtime budget, so a blind ask blocked the heard path for the following
minute as well as backing its target off. maybeAskHeardTarget is now the whole
scheduler, and selectNextTarget, demoted and cursor go with the fallback they served.

A BLE write that throws now costs nothing. commitAndAsk charged attempts, lastAskedAt
and the airtime budget before the write, and askRegions only logged the rejection, so a
request that never reached the radio held the pending slot for its full 20s and then
printed "no reply ... within 20s" — indistinguishable from a repeater that heard us and
stayed silent. Two of the six asks were this: 12:00:00 and 12:02:36, both immediately
after "BLE: reconnecting". commitAsk now returns a receipt and undoAsk restores it,
refusing once the send-ack has captured a tag (that request IS on the air) or once
another target holds the slot. prepareAndAskRegions gained a try/catch for the same
reason: state.transport is nulled on disconnect and askRegions dereferences it, which
rejected unobserved and wedged the slot until it timed out.

Removing the timer removes the only line that narrated the scheduler once a minute, so
heardAskDecision reports why it said no (in flight, budget, answered, backoff, with the
remaining wait) and the heard path logs that at most once a minute. Those four states
were previously indistinguishable from each other and from silence.

Known trade-off, stated in the release notes: the stationary pause stops the discover
sweep, so a parked app now depends on organic traffic to raise a candidate. A repeater
in range that transmits nothing while you are parked next to it is no longer asked.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HSoyBhrLLtSqLgBMEKMiJV
2026-09-11 12:47:02 +02:00
Erwin FitenandClaude Opus 5 506efab11c feat: ask forwarders for their regions, not just nodes that answer discover
A 'rxlog' attribution only happens on a FLOOD route, where path[last] IS the
node that transmitted to us — one radio hop away, which is exactly the direct
neighbour relation a regions request needs. Those receptions were never
candidates. The stated reason was that the packet carries no pubkey to address,
but that is not the obstacle: the discover path has the same gap and closes it
with a CoreScope lookup, and the app already sends these same prefixes to that
endpoint to resolve names. So forwarders now resolve to a full pubkey and become
candidates like any other repeater.

This fills a real hole rather than adding volume. isOrganicHeard backs the
discover sweep off for 15s after any organic reception, so in busy areas — where
forwarder traffic is densest — the sweep is suppressed and yields the FEWEST
discover-sourced candidates exactly where there is the most to hear.

Node type is unknown for a path hash, which is accepted rather than ignored: a
node appears in a path only because it RETRANSMITTED the packet, and companions
and sensors do not forward, so this population is repeaters and possibly room
servers. A non-answerer costs one ask and is then held off by the existing
5/15/30-minute backoff, the same as a repeater that stays silent. No airtime is
added either way — both paths share the one-ask-per-60s budget.

Whether a 2-byte prefix resolves uniquely often enough to be worth it is a
measurement, not a guess, and the app puts the companion in 2-byte path-hash
mode itself, so this is the least favourable case. The log header now carries
"path keys: N of M path-hash prefixes resolved to a pubkey (K ambiguous or
unknown)". It lives in the header because the 200-line ring buffer rolls
per-prefix lines out long before a drive ends, and it counts DISTINCT prefixes:
resolvePubkey is called on every reception from a forwarder and answers from its
session cache, so counting calls would report the busiest node many times over
and say nothing about how many forwarders could be identified.

Adding a third writer to the candidate map exposed a pre-existing bug worth
naming. The map value is the answered-key isTargetDue compares against, and
advert-sourced candidates carry a real advertTs while discover- and
forwarder-sourced ones carry null. A plain set(pk, null) overwrote a known
timestamp, so answered.get(t) !== advertTs for a repeater that HAD answered: it
read as due and was asked again for nothing. That already applied to the
discover path; a third writer would have tripled it. recordCandidate never
downgrades a known timestamp, and returns the EFFECTIVE key so the call site
cannot hand a stale null to the ask decision — which was the same bug by a
second route. A changed timestamp still overwrites; a re-advert is the
documented signal to ask again.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-11 09:30:47 +02:00
Erwin FitenandClaude Opus 5 52b7ff534f fix: one silent repeater killed every later region ask for the session
state.regions.pending is the single in-flight slot, and it was released in only
three places: a FLOOD send-ack, an accepted reply, and disconnect. None of those
is the ordinary outcome for a moving receiver — a request sent DIRECT to a
repeater we have already driven past is simply never answered, and that left the
slot occupied for the rest of the session.

heardAskEligible gates on that slot, so the first unanswered ask disabled the
event-driven path entirely. What remained was the 60s timer picking a candidate
from the whole session pool — exactly the clock-chosen, minute-late ask the
module header says cannot work at speed. A 23-minute commute log shows ~19
repeaters heard, every ask landing on the timer cadence, not one
"heard ... directly" line, and a single reply.

A pending request now carries sentAt and expires after PENDING_TIMEOUT_MS,
swept by the one-second tick rather than a setTimeout — this app is routinely
backgrounded mid-drive, where a timer fires late or not at all. A pending
without a sentAt counts as expired: a wedged slot costs a whole session, an
early expiry costs one ask that the airtime budget already bounds.

Two invariants the timer path documented but never enforced, unnoticed only
because the wedged slot meant the heard path never ran:

- The shared 60s airtime budget is now stamped in commitAndAsk, the one site
  that transmits, so it counts asks from both paths. It was stamped only in
  maybeAskHeardTarget, so timer asks spent airtime for free.
- The timer no longer asks over a live request. Doing so overwrote pending.tag
  and applyRegionsReply then rejected the real reply as a tag mismatch, so the
  fallback path was destroying the answers this feature exists to collect.

OVERRIDE_ROUND_TIMEOUT_MS now derives from the same constant: once the contact
path override is torn down no reply can arrive, so pending must not outlive it.

Also fixes the log line that hid this. "every repeater heard so far has already
answered" was printed whenever the pool came up empty, including when every
candidate was merely waiting out its retry backoff — it read as a finished job
while one repeater of nineteen had answered.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-11 09:30:13 +02:00
efiten 6847e9ca30 fix: trim AES block padding from a regions reply
The ANON_REQ reply payload is encrypted with a block cipher
(Utils::encryptThenMAC -> AES), so the plaintext arrives NUL-padded to a 16-byte
boundary, and the firmware's own length is not carried through to us. We stored
the padding verbatim.

Measured in production: 48 of 65 stored rows carry it. The padding lands inside
the LAST region name, so "belml" is stored as "belml\0\0\0..." — which matches no
observed scope and therefore reads as a region the repeater declares but never
forwards. A systematic false finding, on the last entry of nearly every list.

A wildcard-only answer is the worst shape: 0x2A plus seven NULs is exactly one
block, so even `regions_csv = '*'` compares false in SQL, and the audit can miss
the wildcard entirely and report a contradiction that is not there.

Trim before splitting. Padding is also excluded from the truncation measure — it
is not part of the repeater's answer and must not count toward the byte ceiling.
2026-08-19 15:20:26 +02:00
efiten 80d4779971 fix: an evaluation that asks nobody must not spend the airtime budget
The timer path stamped lastAskAt on every evaluation, including ones that
transmitted nothing. That spent the one-per-60s budget on no-ops and then
blocked the heard-packet path, which is the whole point of the previous commit.

Field log, stationary receiver:
  14:29:08  regions: due this round but no candidate to ask yet   <- stamped
  14:29:27  heard efef7943505052b4 (8B, discover)                 <- blocked
  14:30:09  regions -> asked efef79435050...                      <- 42s late
  14:30:10  regions <- efef79435050... declares: *,eu,bx,be,...

Stationary it only costs 42 seconds. Moving at 50 km/h it is most of a
kilometre, and this request is answered only zero-hop DIRECT.

Split the two clocks: lastEvalAt throttles the timer path's re-entry and its log
line to once a minute; lastAskAt is the airtime budget and is stamped only where
something is actually sent.

Also make the idle message honest — "no candidate to ask yet" read as "nobody
heard" when the real state was usually "everyone heard has already answered".
2026-08-19 14:56:27 +02:00
efiten 6f6285bc81 fix: ask region discovery on the repeater actually just heard
Region discovery only works zero-hop DIRECT, and the receiver is
moving, so a clock-driven ask (picking from every repeater heard this
session) systematically asked repeaters least likely to still be in
range. Fire the ask when a suitable repeater is heard instead of on a
timer, without increasing airtime: the timer path stays as a fallback
for a candidate heard once and not heard again, and both paths share
state.regions.lastAskAt so the existing one-ask-per-60s ceiling holds
regardless of which fires.

heardAskEligible (src/regionreq.js) is the pure per-target decision
(budget free, no ask pending, target due per isTargetDue — extracted
from selectNextTarget so both paths use the identical due() rule).
Round-robin fairness now emerges from hearing different repeaters at
different moments plus the existing per-target backoff; no second
fairness mechanism was added on top.
2026-08-19 14:10:07 +02:00
efiten 0c63c83bf6 fix: back off a repeater that does not answer instead of asking it every minute
Field log showed nine asks to one node in nine minutes. Demotion alone does not
prevent that: it moves a silent target behind the answering ones, but once every
OTHER candidate has answered they are no longer due, selectNextTarget's pool
falls back to "every due candidate", and the silent one is handed straight back
each round.

That is worse than wasted airtime. simple_repeater rate-limits anon requests to
4 per 180s SHARED across all request types and all requesters (MyMesh.cpp:861),
so hammering a node burns the very budget its answer would need — asking more
often makes an answer less likely, not more.

Per-target backoff: 5 min after the first unanswered ask, then 15, then 30 and
held there. It still retries, because silence is ambiguous (out of direct range,
firmware below v13, rate-limited, or simply busy) and dropping a target forever
would lose one that was merely out of range for a stretch.
2026-08-19 13:20:49 +02:00
efiten a1d2244823 fix: say so when a regions request went out as FLOOD and can never be answered
A repeater answers ANON_REQ_TYPE_REGIONS only over a DIRECT route
(simple_repeater/MyMesh.cpp requires isRouteDirect()) and drops a flooded one
without any error. The companion chooses the route, not us: sendAnonReq
(BaseChatMesh.cpp:619) floods whenever the target is a known contact whose
out_path_len is OUT_PATH_UNKNOWN, and only sends direct for a non-contact, where
CMD_SEND_ANON_REQ builds a transient contact with out_path_len = 0.

So asking a repeater already saved as a contact is a guaranteed no-op — which is
what the field log shows: the send succeeds, the ack arrives, and nothing ever
comes back.

The ack already carries the answer and we were discarding it
(companion_radio/MyMesh.cpp:1569: out_frame[1] = SENT_FLOOD ? 1 : 0). Read it,
clear the pending slot instead of waiting out a reply that cannot arrive, and
log it. This does not make the request succeed; it makes a permanent silent
failure legible instead of looking like a repeater that just has not replied yet.
2026-08-18 20:59:40 +02:00
efiten cbf786f2cc fix: accept node-discover responses as region-discovery candidates
Every repeater on this network has a 47h advert interval, so real
adverts are almost never heard and the region-discovery candidate map
stayed empty — selectNextTarget always returned null and no region
request was ever sent (five discover rounds, zero region requests in
the field log).

Node-discover responses are what actually arrives constantly, but they
carry only an 8-byte pubkey prefix and no advert timestamp/type. Fixes:

- meshpacket.js: parsePacket now also extracts discoverType (low
  nibble of the DISCOVER_RESP flags byte, per
  simple_repeater/MyMesh.cpp:801) alongside the existing discoverPubkey.
  Purely additive — deriveHeardKey is untouched and its pinned tests
  stay green unmodified.
- names.js: add resolvePubkey, a sibling of resolveName that resolves
  a prefix to the full 32-byte pubkey via the same endpoint and cache
  discipline (network errors never cached; a full 64-hex key needs no
  request).
- app.js: accept hk.src === 'discover' candidates when discoverType is
  ADV_TYPE_REPEATER, resolved to the full pubkey so a repeater never
  keys twice under prefix and pubkey. advertTs is stored null;
  selectNextTarget's existing due() rule already asks it once per
  session and re-asks automatically once a real advert arrives.
- app.js: maybeQueryRegions now logs the half-rate rounds where a
  region request was due but no candidate existed yet — this bug was
  previously silent.
2026-08-18 20:27:33 +02:00
efitenandClaude Opus 5 e099f3cf93 fix: measure the truncation boundary in wire bytes, not code units
The 139-byte threshold is derived from the firmware's byte budget, but it was
compared against csv.length, which counts UTF-16 code units. RegionMap's
is_name_char accepts every byte >= 0x80, so accented region names are legal and
cost more bytes than code units — meaning a CSV at or past the boundary could
decode to fewer than 139 units and store truncated: false as fact. That is the
same under-flagging the threshold fix was written to close.

Export TRUNCATION_WARN_BYTES so the tests assert against the constant instead of
a copy; the stale 160 in an existing assertion is what let this drift unnoticed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 17:20:14 +02:00
efitenandClaude Opus 5 3657a5b87f fix: final review pass on region-discovery (repo A side)
- Truncation threshold was 160 bytes, missing any dropped name longer
  than 9 chars (be-antwerpen, be-limburg are real names on this
  network). Derived the correct floor from RegionMap.cpp/MyMesh.cpp:
  the delivered CSV can be as short as 139 bytes while still hiding a
  dropped 30-char name, once the trailing-comma trim is accounted for.
- A DEVICE_INFO failure on connect left "Region discovery: on" showing
  while state.regions.supported stayed false — now the catch path
  writes an honest "off — could not read firmware version" line.
- onRegionsFrame's queue.add() was a fire-and-forget promise in a sync
  BLE listener; added the same .catch() pattern used elsewhere.
- maybeQueryRegions committed scheduler state (cursor/demoted/pending)
  before building the request frame, so a throw from
  buildRegionsRequest would leave the scheduler out of sync with what
  was actually sent. Build the frame first.
- Documented regionDiscovery in the README config sample (was only in
  config.example.json), matching the fullRfLog/rfSampler warning shape.
- Bumped the sw.js cache version for the frontend changes above.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 16:49:12 +02:00
efitenandClaude Opus 5 045c97ba32 fix: match region-discovery replies by the echoed tag, not "something pending"
A stray/late PUSH_CODE_BINARY_RESPONSE (the repeater rate-limits and replies
after a delay; a different repeater is asked every 60s) was being accepted as
an answer for whichever target happened to be pending -- attributing one
repeater's declared regions to a different repeater and storing it as an
authoritative observation. The protocol carries a tag precisely to prevent
this (sendAnonReq generates it, the repeater echoes it, parseRegionsResponse
already parsed it out) but nothing compared it.

- src/regionreq.js: RESP_CODE_SENT (verified companion_radio/MyMesh.cpp:77),
  parseSentAck (the [tag] ack for CMD_SEND_ANON_REQ, verified MyMesh.cpp
  :1568-1572), and applyRegionsReply -- a pure state-transition that accepts
  a reply only when its tag matches the pending request's captured tag, and
  otherwise returns accepted:false without mutating `pending` so the real
  reply can still arrive and be matched afterward.
- src/app.js: maybeQueryRegions now seeds pending with tag:null; askRegions
  sends the request and listens for the RESP_CODE_SENT ack to fill it in
  (4s timeout, target-checked against a stale/superseded round); onRegionsFrame
  now goes through applyRegionsReply and only clears/records on accepted:true,
  logging a mismatch at the 'no' debug level otherwise.
- public/sw.js: CACHE v19 -> v20 (the v19 bump in the prior commit predates
  this change to app.js/regionreq.js).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 15:18:43 +02:00
efitenandClaude Opus 5 d16e55de97 feat: round-robin region discovery on the discover clock
Ask exactly one repeater per region-discovery round (half the 30s discover
cadence, so once a minute) for its declared flood-allowed region list, and
compare it later against what CoreScope observes it actually forward.

- src/regionreq.js: selectNextTarget(state) -> pubkey|null, pure round-robin
  selection with demotion for non-answerers (never dropped, since silence is
  ambiguous: out of range, rate-limited, old firmware, or busy).
- src/meshpacket.js: parsePacket now also returns advertTs (the node's own
  re-advert clock, so a repeater is re-asked only after a config edit) and
  advertType (ADV_TYPE_*, so only ADV_TYPE_REPEATER nodes are ever asked --
  only simple_repeater firmware implements the reply).
- src/app.js: wiring only. Candidates are 0-hop adverts (full pubkey, direct
  RF range) from repeaters; maybeQueryRegions() rides the discover clock at
  half rate and sends at most one buildRegionsRequest per round, logged at
  the tx (orange) level; onRegionsFrame is a dedicated listener fed the RAW
  notification (never parseFrame(...).data, which strips the code byte and
  would silently break parseRegionsResponse's bytes[0] check).
- Feature gate: FIRMWARE_VER_CODE >= 13 (CMD_SEND_ANON_REQ's non-contact
  allowance), read via the existing requestDeviceInfo() call at connect;
  when regionDiscovery is configured on but the firmware is too old, the
  feature stays off and Settings shows why.
- config.regionDiscovery defaults to false (config.js, config.example.json).
- index.html: regionsInfo status line in Settings/Diagnostics.
- sw.js: cache buster v18 -> v19 (frontend files changed).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 15:11:02 +02:00
efiten 4ac3ea3ea2 fix: validate pubkeyHex in buildRegionsRequest, throw TypeError on malformed input 2026-08-18 14:57:19 +02:00
efiten d7e29270da feat: region discovery request/response framing 2026-08-18 14:51:14 +02:00