Repository navigation
Replace the trust callback with is_paired() - #234
Merged
Merged
Conversation
ConnectionTrust (NONE/USER) and on_trust_changed() carried over the owner/user/none trust levels of an early spec draft. The spec now has only paired and unpaired sessions, which is one fact, and a piece of state rather than an event: on_trust_changed() fired each time a connection went operational, changed or not. SendspinClient::is_paired() reports it from any thread. The protocol task stores it each tick in refresh_published_state(), after lowering the connected flag, so a reader that checks is_paired() before is_connected() sees a re-handshake's value only with its activation. The enum, the callback and the pairing note that delivered it are gone, and with the note the last heap allocation between accept and admission. This breaks the public API: a listener overriding on_trust_changed() no longer compiles.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The TUI can hide the Pairing Token while a paired session is disconnected and leave pairing indicators stale because pairing changes do not trigger a redraw.
5 open issues
What changed in this PR
Replaces the legacy trust enum and callback with SendspinClient::is_paired(), aligning the client API with the protocol’s paired/unpaired session model.
Changes:
- Adds a thread-safe pairing-state query and removes trust notifications—a breaking API change.
- Migrates examples and documentation to polling paired-session state.
- Updates encrypted lifecycle checks and lowers expected admission allocations to zero.
| File | Description |
|---|---|
| tests/test_encrypted_lifecycle.cpp | Replaces trust callback assertions with pairing-state checks. |
| tests/test_client_lifecycle.cpp | Updates commentary after trust-event removal. |
| tests/test_allocations.cpp | Sets expected admission allocations to zero. |
| src/inbox.h | Removes trust wording from the pairing-topic comment. |
| src/connection_manager.h | Adds the pairing-state atomic, getter, and contract documentation. |
| src/connection_manager.cpp | Publishes the primary connection’s pairing state. |
| src/client.cpp | Implements the public query and removes deferred trust notifications. |
| include/sendspin/types.h | Removes ConnectionTrust and revises UNAUTHORIZED documentation. |
| include/sendspin/client.h | Replaces the trust callback with the documented is_paired() API. |
| examples/tui_client/tui.h | Replaces stored trust state with a pairing boolean. |
| examples/tui_client/tui.cpp | Polls pairing state and updates pairing-related display conditions. |
| examples/tui_client/README.md | Documents paired-session display and token visibility. |
| examples/tui_client/main.cpp | Removes the trust listener override. |
| examples/source_client/main.cpp | Reports pairing-state changes through polling. |
| examples/basic_client/main.cpp | Polls pairing state and updates session messages. |
| docs/internals.md | Documents pairing-state publication and removes trust-note references. |
| docs/integration-guide.md | Updates listener examples, state queries, and pairing references. |
Review effort: Max
The TUI's redraw check now compares the paired flag, so a rekey that finishes between two polls no longer leaves the Paired row and the token panel stale. The guide's polling snippet reads is_paired() before is_connected(), as its doc asks, and the token panel's docs say it shows while the client has no paired session. TheConnectedFlagRisesOnlyAtTheEndOfTheTick checks is_paired() too: true for the admitted LONG_TERM session, false after a drop, and still true while a re-handshake awaits its server/activate, through a tick that must not raise the connected flag.
kahrendt
added a commit
that referenced
this pull request
Nov 3, 2026
## Summary A coherence review of the allocation series (#225-#234) found the migrated pieces consistent with each other, plus a set of small inconsistencies at their edges. This PR fixes those. No behavior change. ## Change - **Caps:** `MAX_SERVER_INIT_BYTES` moves from `noise_handshake.h` to `crypto/constants.h`, beside `MAX_HANDSHAKE_MESSAGE_BYTES`; each comment names the other. - **Inline text:** - `InlineText::assign()` is `[[nodiscard]]`; each caller checks it, or casts to `(void)` with the reason its text fits (or, for the last-played id, that clearing is the documented behavior). - `set_noise_handshake_result()` and `run_rehandshake_msg1()` take `const IdText&` instead of re-assigning views. `last_played_server_id()` returns `const IdText&`, like `get_server_id()`. - `ResolvedPsk::counterparty_id` is a plain `IdText`, empty for a PSK bound to no server, instead of `std::optional<IdText>`. - `SENTINEL_PSK_ID` is a `constexpr std::string_view` literal instead of a global `std::string` built during static initialization. - The connection's id and name members sit in its "String fields" group. - **`ParsedJsonMessage::extract()`** static_asserts that an extractor does not return a pointer, a `std::string_view`, or a `JsonVariant`/`JsonObject`/`JsonArray`/`JsonString` (alone or in `std::optional`), since the document is released before the caller reads it. - **Comments:** the stale "hub" comments name the real callers (protocol task, `ConnectionManager`, transport threads); the ESP `start()` comment describes when the connection is delivered. - **Naming:** the activation check left over from `ConnectionTrust` is "the admissibility check" in src, docs and tests, matching `admissible()` and `inadmissible_reject_reason()`. ## Tests - Tests build ids through a new `id_text()` helper in `tests/record_test_helpers.h`, which fails a test whose id would not fit. - `CryptoConstants.SentinelPskIdMatchesSpecConstant` now checks that `psk_id_for(SENTINEL_PSK)` derives the literal, so it fails if either drifts. - The `extract()` guard was checked with a probe: an extractor returning a `std::string_view` fails to compile with the new message, one returning an `int` compiles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Replaces
ConnectionTrustandon_trust_changed()withSendspinClient::is_paired(). The enum'sNONE/USERcame from an early spec draft'sowner/user/nonetrust levels. The current spec has only paired and unpaired sessions (README.md "Definitions"), which is one fact, and a piece of state rather than an event:on_trust_changed()fired every time a connection went operational, whether or not anything changed. Removing its pairing note also removes the last library heap allocation between accept and admission.Breaking: the enum and the callback are removed outright, so a listener that overrides
on_trust_changed()no longer compiles.Breaking Change Migration
Delete any
on_trust_changed()override and any use ofConnectionTrust.ConnectionTrust::USERmaps tois_paired()returningtrue,ConnectionTrust::NONEtofalse.Poll
is_paired()where the state was cached from the callback, reading it beforeis_connected():To react the moment a pairing completes, keep using
on_pairing_succeeded();is_paired()turnstrueonce the server's rekey onto the new long-term PSK finishes.Change
is_paired()(any thread): true when the primary admitted connection is keyed by a long-term PSK, false for the Pairing or Sentinel PSK and while nothing is admitted.refresh_published_state()stores it every tick in astd::atomic<bool> paired_next toconnected_, after loweringconnected_, so a re-handshake changes it on the same connection.is_paired()first and then seesis_connected()true knows that session'sserver/activatehas been applied. The public doc says to read it beforeis_connected().ConnectionTrust,on_trust_changed(),note_trust_changed(), theTRUST_CHANGEDnote type andPairingNote::trust.UNAUTHORIZED's description no longer uses trust levels and now covers a revoked record.Tests
is_paired() && is_connected()instead of recording trust callbacks.ADMISSION_ALLOCATIONSis lowered from 1 to 0.