Skip to content

Remove dead code and test-only helpers from the library - #283

Merged
kahrendt merged 6 commits into
mainfrom
trim-dead-code
Nov 21, 2026
Merged

kahrendt merged 6 commits into
mainfrom
trim-dead-code

Conversation

@kahrendt

Copy link
Copy Markdown
Contributor

Summary

Removes code nothing runs: unreferenced functions and constants, parameters that only ever took one value, state that is written and never read, and crypto helpers only the tests called. No behavior changes apart from one log line. Net -209 lines.

Change

  • Time filter: nothing constructed a SendspinTimeFilter with a non-default Config, yet each filter stored the derived values per instance. They are constants in time_filter.cpp; Config, its constructor and the unused get_covariance() are gone.
  • Unreferenced: five SsErr values, MIN_ADVERTISED_AUDIO_BYTES_PER_SECOND, PlatformBuffer::location(), and is_created() on the inbound and outbound rings.
  • Single-value parameters: close_silently() ignored its goodbye reason; EventFlags::wait() was never asked to wait for all bits; NoiseSession::as_responder() was never given a PSK; process_player_stream_object() always required every field.
  • Write-only state: both ws_server implementations stored the SendspinClient* passed to start() and never read it.
  • Test-only crypto: aead_oneshot_decrypt() and the one-shot hmac_sha512() move to the test helpers. sha256_oneshot(), pairing_code_verify_commit() and AEAD_ONESHOT_NONCE_SIZE are deleted.
  • Test seam: get_noise_suite_name() is no longer virtual; the test fake sets the member.

Reviewer notes

  • process_player_stream_object() loses its up-front presence check along with the parameter. The caller's is_complete() check rejects the same messages, so only the log text differs: "incomplete player object" where it said "missing required fields".
  • get_noise_handshake_hash() stays virtual. The test fake cannot hold an active Noise session without encrypting the sends its tests parse.
  • The ESP-only edits (src/esp/ws_server.{h,cpp} and the FreeRTOS half of src/platform/event_flags.h) were not compiled locally; CI is their first build.

Tests

  • The two tests of pairing_code_verify_commit() and the verify rows of its length-guard table are deleted with the function; pairing_code_commit() keeps its length-guard table and known-answer test.
  • The pairing state machine test now recomputes the commitment from the revealed nonce and compares it.
  • The SHA-256 known-answer test keeps its streaming half.
  • Not run: ThreadSanitizer, and the six commits were built only at the tip.

Nothing constructed a SendspinTimeFilter with a non-default Config, yet
every filter stored the derived values per instance. They are constants
in time_filter.cpp now, and the unused get_covariance() is gone.
The unused SsErr values, MIN_ADVERTISED_AUDIO_BYTES_PER_SECOND,
PlatformBuffer::location() and the inbound and outbound rings'
is_created() had no callers.
close_silently() ignored its goodbye reason, EventFlags::wait() was
never asked to wait for all bits, NoiseSession::as_responder() was never
given a PSK, and process_player_stream_object() always required every
field. Its presence check goes with the parameter: the caller's
is_complete() check rejects the same messages.
Both server implementations stored the SendspinClient passed to start()
and never read it.
aead_oneshot_decrypt() and the one-shot hmac_sha512() live in the test
helpers now. sha256_oneshot(), pairing_code_verify_commit() and
AEAD_ONESHOT_NONCE_SIZE are deleted, along with the tests of the
verification the client never performs.
Its only override was a test fake, which sets the suite name member
instead.
@kahrendt
kahrendt marked this pull request as ready for review November 21, 2026 13:58
@kahrendt
kahrendt requested an adaptive review from Copilot November 21, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the unused-code and test-helper cleanup.

No open issues 🎉

What changed in this PR

Removes unused internal code and test-only helpers from sendspin-cpp, reducing library complexity and per-instance time-filter storage. The cleanup preserves intended runtime behavior apart from the documented validation log change.

Changes:

  • Remove unused functions, constants, accessors, parameters, and write-only state.
  • Move test-only crypto helpers into tests and remove an unnecessary virtual test seam.
  • Update affected callers, tests, and playback-sync documentation.
File Description
tests/​wrap_test_helpers.h House the test-only AEAD decrypt helper.
tests/​test_pairing_state_machine.cpp Set the fake’s suite member and recompute commitments directly.
tests/​test_pairing_code.cpp Remove tests for the deleted commitment verifier.
tests/​test_crypto.cpp Use test HMAC helpers and retain streaming SHA-256 coverage.
tests/​test_cpace.cpp Include the test-only HMAC helper.
tests/​record_test_helpers.h Generate peer IDs using streaming SHA-256.
tests/​crypto_test_helpers.h Add a test-only one-buffer HMAC wrapper.
src/​time_filter.h Remove configurable construction, stored tuning values, and an unused accessor.
src/​time_filter.cpp Replace per-instance tuning values with constants.
src/​sync_task.cpp Update event-wait calls to the simplified signature.
src/​source_task.cpp Update the startup event-wait call.
src/​protocol.cpp Remove a fixed-value parameter and redundant presence check.
src/​protocol_task.cpp Update the protocol task’s event-wait call.
src/​platform/​types.h Remove unused error enum values.
src/​platform/​memory.h Remove the unused location accessor.
src/​platform/​event_flags.h Remove wait-all support and update examples.
src/​platform/​crypto.h Remove unused and test-only crypto helpers.
src/​outbound_ring.h Remove the unused creation-status accessor.
src/​noise_session.h Simplify responder construction and its documentation.
src/​noise_session.cpp Remove the unused construction-time PSK path.
src/​noise_handshake.cpp Update responder construction and explanatory comments.
src/​inbound_ring.h Remove unused members and update event waits and comments.
src/​inbound_ring.cpp Update event-wait calls.
src/​host/​ws_server.h Remove the unused client parameter and stored pointer.
src/​host/​ws_server.cpp Simplify server startup accordingly.
src/​esp/​ws_server.h Remove the unused client parameter and stored pointer.
src/​esp/​ws_server.cpp Simplify HTTP server startup accordingly.
src/​crypto/​pairing_code.h Remove the unused commitment-verifier declaration.
src/​crypto/​pairing_code.cpp Remove the unused commitment-verifier implementation.
src/​connection.h Remove a virtual test seam and an ignored close parameter.
src/​connection.cpp Update silent-close calls.
src/​connection_manager.cpp Update WebSocket server startup arguments.
src/​connection_manager_pairing.cpp Update the malformed-message silent-close call.
src/​client_dispatch.cpp Update silent-close calls and related comments.
docs/​playback-sync.md Describe fixed filter constants instead of removed configuration.

Review effort: Balanced (adaptive)

@kahrendt
kahrendt merged commit c2f2a69 into main Nov 21, 2026
17 checks passed
@kahrendt
kahrendt deleted the trim-dead-code branch November 21, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants