Skip to content

Read the device's record before send_anon_req changes its path - #131

Merged
fdlamotte merged 1 commit into
meshcore-dev:mainfrom
hamsolodev:anon-req-keep-radio-path
Nov 22, 2026
Merged

fdlamotte merged 1 commit into
meshcore-dev:mainfrom
hamsolodev:anon-req-keep-radio-path

Conversation

@hamsolodev

Copy link
Copy Markdown
Contributor

What was wrong (#119, B4)

  • When meshcore's own copy of a contact said flood (out_path_len == -1), send_anon_req set a zero-hop path on the radio, sent the request, then called reset_path.
  • If the radio held a direct path that meshcore's copy didn't know about, the radio was left with no path. The path could have been set by another app, or by the radio since the last contact read.

What changed: when the copy says flood, send_anon_req first reads the radio's record by key (get_contact_by_key), then:

  • The radio holds a path: that path is used for the request and the reply path, and left alone. No zero-hop change, no reset. The path is also copied into meshcore's contact, which was out of date.
  • The radio holds flood: zero-hop, send, reset to flood, as before. The zero-hop write now goes from the radio's own record rather than meshcore's copy, so nothing else in the record (name, position) is overwritten with older values.
  • The radio doesn't hold the contact (ERR_CODE_NOT_FOUND): it's sent like any unknown destination, zero-hop, rather than first added to the radio by the zero-hop write.
  • The record can't be read (timeout): nothing is changed or sent; it returns ERROR with reason: contact_read_failed.

I chose to read rather than skip the change outright, because a flood record still needs the zero-hop for the server to answer (it gates these behind isRouteDirect()). This costs one extra round trip, only when the copy says flood. Two existing tests in test_error_handling.py now mock the read.

Verified

  • Unit tests in tests/unit/test_anon_req_device_path.py. They fail on current main.
  • The whole suite passes on 3.11 and 3.14.
  • Against companion v1.18.0 under MeshBench, with a repeater beside it. meshcore's copy said flood while the radio held a direct path (… 00). On current main:
sent     16 03                 (device query, from change_contact_path)
sent     09 bd38…a4fc 02 00 00 …  (zero-hop)
sent     39 bd38…a4fc 02 00
answered 06 …                  (MSG_SENT)
sent     0d bd38…a4fc          (reset_path)
answered 8c …                  (the owner reply)
read back by key: out_path_len ff

On this branch:

sent     1e bd38…a4fc
answered 03 bd38…a4fc 02 00 00 …  (the radio holds a direct path)
sent     39 bd38…a4fc 02 00
answered 06 …
answered 8c …
read back by key: out_path_len 00

With the radio holding flood, this branch sends 1e, 16 03, 09 (zero-hop), 39, 0d, as current main does. The reply arrives, and the record reads ff again afterwards.

Part of #119.

When meshcore's copy of a contact said flood, send_anon_req set a zero-hop
path on the device, sent, then reset the path to flood. If the device held
a path the copy didn't know about (set by another app, or since the
contacts were last read), it was left with none.

It now reads the device's record by key first:
- a path the device holds is used for the request and left alone (and
  copied into meshcore's contact);
- a flood record is set to zero-hop, written from the device's own record
  so nothing else in it changes, and reset to flood after sending, as
  before;
- a contact the device doesn't hold is sent to as an unknown destination,
  rather than added to the device;
- if the record can't be read, nothing is changed or sent.

Part of meshcore-dev#119 (B4).
@hamsolodev
hamsolodev marked this pull request as ready for review November 22, 2026 00:15
@fdlamotte
fdlamotte merged commit aa4e162 into meshcore-dev:main Nov 22, 2026
@hamsolodev
hamsolodev deleted the anon-req-keep-radio-path branch November 25, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants