Refactor duplicated receiver dispatch into one protocol-processing core #217

Closed
opened 2026-09-01 21:09:14 +02:00 by TapTap · 1 comment
Owner

Summary

The server maintains two near-duplicate receive state machines: receive_files() in src/server/server.c:55-166 and receive_thread() in src/shared/multiprocessing.c:169-276. Both decode the same statuses, incremental checks, chunk batches, manifests, and FINISHED handling, but have diverged in validation and error/cancellation behavior. valid_batch_path() is also duplicated at server.c:32-35 and multiprocessing.c:17-19. Future protocol changes must be made twice and can produce inconsistent single-threaded versus multithreaded behavior.

Scope

Extract shared status dispatch/receive helpers with explicit callbacks or a receiver context for enqueueing versus immediate writing. Keep transport/thread synchronization outside the protocol core and preserve existing error semantics.

Acceptance criteria

  • Single-threaded and multithreaded receiving use the same protocol dispatch implementation.
  • There is one shared implementation of batch-path validation.
  • Unit/integration coverage exercises both modes, including incremental, chunk, manifest/delete, abort, malformed input, and FINISHED/error paths.
  • Tests demonstrate equivalent protocol outcomes between the two receive modes.

Severity

medium

Category

quality


Automated maintainability audit; no source changes were made.

## Summary The server maintains two near-duplicate receive state machines: `receive_files()` in `src/server/server.c:55-166` and `receive_thread()` in `src/shared/multiprocessing.c:169-276`. Both decode the same statuses, incremental checks, chunk batches, manifests, and FINISHED handling, but have diverged in validation and error/cancellation behavior. `valid_batch_path()` is also duplicated at `server.c:32-35` and `multiprocessing.c:17-19`. Future protocol changes must be made twice and can produce inconsistent single-threaded versus multithreaded behavior. ## Scope Extract shared status dispatch/receive helpers with explicit callbacks or a receiver context for enqueueing versus immediate writing. Keep transport/thread synchronization outside the protocol core and preserve existing error semantics. ## Acceptance criteria - Single-threaded and multithreaded receiving use the same protocol dispatch implementation. - There is one shared implementation of batch-path validation. - Unit/integration coverage exercises both modes, including incremental, chunk, manifest/delete, abort, malformed input, and FINISHED/error paths. - Tests demonstrate equivalent protocol outcomes between the two receive modes. ## Severity medium ## Category quality --- _Automated maintainability audit; no source changes were made._
TapTap added the qualityneeds-triage labels 2026-09-01 21:09:14 +02:00
Author
Owner

Fixed. The two receiver state machines are unified: receiver_process_pending() in src/server/receiver.c is now the single protocol core used by both the single-threaded path (receiver_receive_files) and the multithreaded path (receive_thread in receiver_pipeline.c). valid_batch_path() is now the single utils_valid_batch_path() (src/shared/utils.c). Single- vs multi-threaded integration tests assert equivalent outcomes. Closing as completed.

Fixed. The two receiver state machines are unified: `receiver_process_pending()` in `src/server/receiver.c` is now the single protocol core used by both the single-threaded path (`receiver_receive_files`) and the multithreaded path (`receive_thread` in `receiver_pipeline.c`). `valid_batch_path()` is now the single `utils_valid_batch_path()` (`src/shared/utils.c`). Single- vs multi-threaded integration tests assert equivalent outcomes. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#217