Repository navigation
Share the fixed-size vocabulary across its sibling sites - #245
Merged
Merged
Conversation
- b64url_encode_to() (was protocol.cpp's write_b64url) joins b64url_decode_exact() in platform/base64.h; the handshake encodes its 50-byte msg2 with it, so build_noise_handshake_message() no longer allocates or fails and both callers lose their error branch. - EnumSet moves to its own header with a test, and server/hello's source codecs are an EnumSet<SendspinCodecFormat> instead of a hand-rolled mask. - open_connection_psk_ids() returns an InlineVector of pointers to the connections' psk ids, kept off the JSON dispatch frame, and the record store takes a span of them; the store's id copies are gone. - The artwork role's configured channels are an InlineVector like its streamed ones, hand_flac_header() takes a string_view, and the FLAC decoder's creation says why it is not a PlatformBuffer. - Protocol task stack figures re-derived (default unchanged at 7,168).
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Inserting B2 three times lets an incorrect ^= implementation pass all current test cases, leaving duplicate-insertion behavior insufficiently tested.
1 open issue
What changed in this PR
Consolidates bounded protocol values around shared helpers and inline containers, reducing temporary heap allocation and keeping sibling implementations consistent in sendspin-cpp.
Changes:
- Shares the stack-based base64url encoder across pairing and Noise handshake messages.
- Extracts
EnumSetand uses bounded containers for source codecs, open-connection PSK IDs, and artwork channels. - Updates tests, allocation documentation, and protocol-task stack figures without changing the stack default.
| File | Description |
|---|---|
tools/stack_usage/README.md |
Updates protocol-task stack bounds and margin calculations. |
tests/test_record_store.cpp |
Adapts eviction tests to PSK-ID pointer spans. |
tests/test_protocol.cpp |
Uses EnumSet in source-codec parsing expectations. |
tests/test_enum_set.cpp |
Adds membership, ordering, and duplicate-insertion coverage. |
tests/CMakeLists.txt |
Registers the new EnumSet test file. |
src/record_store.h |
Changes in-use PSK-ID parameters to pointer spans. |
src/record_store.cpp |
Consumes pointer spans and removes temporary ID copies. |
src/protocol.cpp |
Reuses the base64url helper and source-codec set. |
src/protocol_messages.h |
Imports EnumSet and applies it to source-codec support. |
src/player_role.cpp |
Accepts FLAC headers through string_view. |
src/player_role_impl.h |
Updates the FLAC-header helper declaration. |
src/platform/secure_zero.h |
Documents base64 helpers as another buffer-wiping caller. |
src/platform/base64.h |
Adds the shared stack encoder with scratch-buffer wiping. |
src/noise_handshake.h |
Narrows the envelope builder to fixed-size msg2 input. |
src/noise_handshake.cpp |
Removes encoding scratch allocation and its failure branch. |
src/enum_set.h |
Extracts the reusable one-byte enum set. |
src/decoder.cpp |
Adds a comment explaining micro-flac’s internal allocations. |
src/connection.h |
Stores and queries source codecs through EnumSet. |
src/connection.cpp |
Adapts re-handshaking to the void envelope builder. |
src/connection_manager.h |
Declares bounded PSK-ID pointers and their lifetime. |
src/connection_manager.cpp |
Collects connection-owned PSK-ID pointers without copying strings. |
src/artwork_role_impl.h |
Stores configured artwork channels in an InlineVector. |
docs/internals.md |
Updates allocation details and explains role-set representations. |
CLAUDE.md |
Documents the standalone secure-erasure header. |
Review effort: Max
An odd count let an insert that toggles its bit produce the expected set.
7 tasks done
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
From the second coherence pass on the allocation follow-ups (Sendspin/backlog#92): sibling sites that hold the same bounded values in different shapes. The Noise handshake encoded its fixed 50-byte msg2 into a fallible heap buffer while the pairing fields use a stack encoder; server/hello's source codecs were a hand-rolled bit mask beside
EnumSet; the open-connection psk-id list was the last bounded id list held asstd::vector<std::string>; and a few role members disagreed with their neighbors.Change
b64url_encode_to()(protocol.cpp'swrite_b64url, still wiping its stack buffer) joinsb64url_decode_exact()inplatform/base64.h.build_noise_handshake_message()encodes msg2 with it and returns void, so the handshake and re-handshake lose their allocation-failure branches.src/enum_set.hwith its own test.server/hello'ssource_codecsis anEnumSet<SendspinCodecFormat>;source_codec_bit()is gone. The uint16 role masks stay, andinternals.md"Memory" says why the two role-set shapes differ.open_connection_psk_ids()returns anInlineVectorof pointers to the connections' psk ids, valid for the protocol-task step that asked;store_record_superseding()and the eviction helper take a span of them. Pointers rather thanIdTextcopies keep a ~184-byte temporary offprocess_json_message()'s frame, which every JSON message shares. The store's own id copies are gone.artwork_channelsis anInlineVectorlikestreamed_channels;hand_flac_header()takes astring_view; the FLAC decoder's creation notes that micro-flac allocates internally, so it is not aPlatformBufferlike the Opus state.Tests
EnumSet.VisitsEachMemberOnceInEnumeratorOrder: insertion order, repeats, the eighth enumerator and empty; a shortfor_eachbound and an assigninginsertfail it.Protocol.ServerHelloSourceSupportListsAcceptedCodecsruns on the set; dropping the FLAC requirement fails it.RecordStore.EvictionSkipsRecordsBackingOpenConnectionsandNothingEvictableRejectsTheRecordtake the pointer span; removing the in-use skip fails both.