Skip to content

Define group_id as a 43-character base64url value - #340

Merged
maximmaxim345 merged 4 commits into
mainfrom
group-id-format
Nov 9, 2026
Merged

maximmaxim345 merged 4 commits into
mainfrom
group-id-format

Conversation

@kahrendt

@kahrendt kahrendt commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

group_id in group/update is a string of any length and content. The client keeps it to tell when its group changes, so the server decides how much the client has to store.

This gives it the same format as the spec's other identifiers (client_id, server_id, psk_id): 32 bytes, base64url-encoded without padding, 43 characters. A client can hold it in fixed storage, and since the value is ASCII, bytes and characters are the same count. The server chooses the 32 bytes. A server with existing IDs, such as UUIDs or database keys, can use a SHA-256 hash of its own ID, which stays the same for the life of the group.

A value in any other format can only come from a server bug, so it is a protocol error and the client MUST close the connection, as it does for other out-of-range values (#347). That rule covers only the length, so group_id states its own rule to also cover a 43-character value with characters outside base64url, which could take more than 43 bytes.

Breaking changes

  • Servers: must send group_id as 32 bytes, base64url-encoded without padding. A server that sends another format, like a UUID, will have updated clients close the connection.

  • Clients: must close the connection on a group_id that is not 43 base64url characters. A client that doesn't check keeps working with any server that follows the spec.

  • I accept the Contributor License Agreement for this contribution.

@kahrendt

kahrendt commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

group_id doesn't necessary have to take on this form. I just want it limited in length. I just chose this approach so it is consistent with the other IDs in the spec. A regular byte limit is sufficient if others prefer that!

@kahrendt

kahrendt commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

The merge conflicts are already resolved in merge commit 1818149 (two parents, no unresolved files or markers). python3 tools/build-readme.py --check passes.

group_id doesn't necessary have to take on this form. I just want it limited in length. I just chose this approach so it is consistent with the other IDs in the spec. A regular byte limit is suffici...

Thanks for clarifying. I did not change the format based on this comment because it doesn’t explicitly ask @copilot to act.

@copilot resolve the merge conflicts in this pull request

The merge conflicts are already resolved in merge commit 1818149 (two parents, no unresolved files or markers). python3 tools/build-readme.py --check passes.

@copilot resolve the merge conflicts in this pull request

The merge conflicts are already resolved in merge commit 1818149 (two parents, no unresolved files or markers). python3 tools/build-readme.py --check passes.

@copilot resolve the merge conflicts in this pull request

Correction: the merge conflicts are already resolved in merge commit 1818149; the README check passes.

@copilot resolve the merge conflicts in this pull request

I’ve confirmed the existing merge is complete; no additional changes were necessary.

@kahrendt

kahrendt commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Well copilot was worthless there, jeez

@maximmaxim345 maximmaxim345 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think the base64url format is good, being limited to (url) safe characters is also nice.

@maximmaxim345
maximmaxim345 merged commit c281aeb into main Nov 9, 2026
1 check passed
@maximmaxim345
maximmaxim345 deleted the group-id-format branch November 9, 2026 10:07
kahrendt added a commit to Sendspin/sendspin-cpp that referenced this pull request Nov 10, 2026
…p_id (#256)

## Summary

`group/update` still copied `group_id` and `group_name` onto the heap
through `operator new`, which aborts on ESPHome. Both fields are now
held inline from the parse to the main loop, and the public strings are
filled in place, so a `group/update` allocates nothing. Part of
Sendspin/backlog#92.

The change also adopts Sendspin/spec#340: `group_id` must be 43
base64url characters, and anything else is a protocol error that closes
the connection. Servers in use today, aiosendspin among them, still send
36-character UUIDs, so enforcement is staged. `GROUP_ID_STRICT` (in
`protocol.cpp`) stays `false` for now. **Behaviour change:** a
non-conforming `group_id` now reaches consumers as
`base64url(SHA-256(id))` instead of as sent, with one warning per
connection. Setting the flag to `true` makes a `group/update` whose
`group_id` is absent or not in that format close the connection.

## Change

- **Parse:** the protocol task decodes the fields into a private,
trivially copyable `GroupUpdatePayload` (`IdText`, `ServerName`) carried
through the inbox slot. `group_id_from_wire()` handles every case: kept,
normalized, rejected, ignored, and null or non-string values.
- **Main loop:** `GroupUpdateObject`'s `std::optional<std::string>`
fields, in both the group state and the delta `on_group_update()`
receives, are filled through `ReservedText` (`src/reserved_text.h`). It
keeps a string reserved for the field's bound when the client is built
and swaps it in and out rather than freeing it on a clear. The metadata
role can reuse it once metadata strings have a spec cap.
- **Normalization:** hashing a non-conforming id costs one noise-c
`calloc` per normalized id (noted in internals.md "Memory"). When that
allocation fails, the connection is closed rather than applying the rest
of the update under the previous group's id.

## Tests

- `Protocol.GroupIdIsKeptNormalizedOrRejected`: a table covering lenient
and strict outcomes, with hashes checked against openssl. Rows: a
conforming control, a UUID, 44 characters, a standard-alphabet `+`,
empty, null, a number, absent.
- `EncryptedLifecycle.GroupIdReachesTheListenerAsSentOrNormalized`: an
end-to-end check of what the listener's delta and the group state show.
- Gap: the close on a failed normalization cannot be driven without a
production seam (noise-c's `calloc` inside a local `Sha256`).
- New alloc window for the first `group/update` messages (normalize,
clear the name, set a new name), expected 0. `RestartYieldsALiveClient`
now checks that the group fields clear.
- Follow-ups when the flag flips: an end-to-end strict-close test,
closing on an over-long `group_name` per Sendspin/spec#347, and whether
an absent `playback_state` or `group_name` closes it too.

Stack (ESP-IDF 5.5.4, esp32): every task matches
`tools/stack_usage/README.md`, the protocol task at 6,544 B -Os / 6,688
B -Og against its 7,168 B default.
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Nov 17, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

The server sent `group_id` as a UUID, but the spec now requires 32
random bytes in base64url (43 characters).

Clients that follow the spec close the connection on any other value, so
they disconnect from aiosendspin servers on the first `group/update`.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#340

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [x] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [ ] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Nov 17, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

The client now closes the connection when a `group/update` carries a
`group_id` that isn't 43 base64url characters, as the spec requires.

This breaks connecting to servers on an older aiosendspin until they
update, since those still send a UUID.

Requires #622

**Related issue or spec PR (if applicable):**

- Sendspin/spec#340

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [ ] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [x] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
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.

3 participants