Reopen the census socket when the tether reconnects #156

Merged
aluminum-ice merged 1 commit from census-tether-socket into main 2026-11-02 05:40:50 +00:00
Owner

What this PR does

Makes the census plugin open a fresh socket when the phone's Bluetooth tether drops and comes back. A tether that reconnects is a new bnep0 interface under the same name, and the census can sleep through the reconnect between its cycles.

  • _census_dht.UdpTransport records the interface (name and index) it bound to, reads the binding back after opening (a can't bind to bnep0 health note if it doesn't take), and checks before every send that the socket is still bound to that same interface. If it isn't, the send raises LinkDown and sends nothing, so the census pauses briefly and reopens, as it already does when the tether drops mid-cycle.
  • census._link checks the socket at the start of each cycle and opens a fresh one when the tether has reconnected since the last cycle, logging census: the tether reconnected; opening a fresh socket.
  • Tests: a socket bound to lo sends; one whose binding is gone, or whose interface was replaced under the same name, sends nothing; the worker opens a fresh socket and carries on writing after a reconnect between cycles, with nothing more sent on the old one. The new tests fail without the change.
  • docs/user-guide/census-setup.md: a troubleshooting row for paused: the network link went down.

Checklist

  • Lint passes — make lint (ansible --syntax-check, yamllint, shellcheck --severity=error, and the real-data check). The Lint workflow runs this on the PR.
  • Tests pass — make test (the kestrel_pi pytest suite and the real-data check's tests). The Test workflow runs this on the PR.
  • Nothing real: no secrets, no personal information, no real data. Placeholders only (192.0.2.x, 127.0.0.1, the fake DHT).
  • Consent gates intact. The census still ships disabled and enabling it still takes the authorized-use acknowledgment; nothing here touches that.
  • Docs updated in the same PR: docs/user-guide/census-setup.md. GUIDE_MD has no census troubleshooting table, so it's unchanged.
  • Commit messages are short and imperative.

Release impact

  • App-layer-safe — changes only plugins/census.py and its helper plugins/_census_dht.py, plus tests and docs.
  • Reflash-class

Notes for review

  • For 1.0.13-beta.2. On a device, it can be confirmed by turning the tether off and on with the census running: the journal shows the new log line at the next cycle, and the census reports again.
  • The check costs two system calls per packet (read the binding, look up the interface index), negligible next to a read's few hundred packets.

🤖 Generated with Claude Code

## What this PR does Makes the census plugin open a fresh socket when the phone's Bluetooth tether drops and comes back. A tether that reconnects is a new `bnep0` interface under the same name, and the census can sleep through the reconnect between its cycles. - `_census_dht.UdpTransport` records the interface (name and index) it bound to, reads the binding back after opening (a `can't bind to bnep0` health note if it doesn't take), and checks before every send that the socket is still bound to that same interface. If it isn't, the send raises `LinkDown` and sends nothing, so the census pauses briefly and reopens, as it already does when the tether drops mid-cycle. - `census._link` checks the socket at the start of each cycle and opens a fresh one when the tether has reconnected since the last cycle, logging `census: the tether reconnected; opening a fresh socket`. - Tests: a socket bound to `lo` sends; one whose binding is gone, or whose interface was replaced under the same name, sends nothing; the worker opens a fresh socket and carries on writing after a reconnect between cycles, with nothing more sent on the old one. The new tests fail without the change. - `docs/user-guide/census-setup.md`: a troubleshooting row for `paused: the network link went down`. ## Checklist - [x] **Lint passes** — `make lint` (ansible `--syntax-check`, `yamllint`, `shellcheck --severity=error`, and the real-data check). The **Lint** workflow runs this on the PR. - [x] **Tests pass** — `make test` (the `kestrel_pi` pytest suite and the real-data check's tests). The **Test** workflow runs this on the PR. - [x] **Nothing real: no secrets, no personal information, no real data.** Placeholders only (`192.0.2.x`, `127.0.0.1`, the fake DHT). - [x] **Consent gates intact.** The census still ships disabled and enabling it still takes the authorized-use acknowledgment; nothing here touches that. - [x] **Docs updated in the same PR**: `docs/user-guide/census-setup.md`. `GUIDE_MD` has no census troubleshooting table, so it's unchanged. - [x] Commit messages are short and imperative. ## Release impact - [x] **App-layer-safe** — changes only `plugins/census.py` and its helper `plugins/_census_dht.py`, plus tests and docs. - [ ] **Reflash-class** ## Notes for review - For 1.0.13-beta.2. On a device, it can be confirmed by turning the tether off and on with the census running: the journal shows the new log line at the next cycle, and the census reports again. - The check costs two system calls per packet (read the binding, look up the interface index), negligible next to a read's few hundred packets. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reopen the census socket when the tether reconnects
All checks were successful
Test / test (pull_request) Successful in 33s
Lint / lint (pull_request) Successful in 34s
Lint / lint (push) Successful in 34s
Test / test (push) Successful in 33s
16a0b47a59
A phone tether that drops and comes back is a new interface under the
same name. The census transport now remembers the interface it opened on,
checks before each send that its socket is still bound to it, and the
census opens a fresh socket at the start of a cycle when it isn't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch census-tether-socket 2026-11-02 05:40:50 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aluminum-ice/kestrel!156
No description provided.