Repository navigation
refactor(daemon): modularize socket frame reading and PAM action handling in SocketServer - #48
Merged
Conversation
…dling in SocketServer
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
In
SocketServer.handleConnection(fd:), low-level POSIXrecv()socket operations, newline framing checks, and JSON decoding were previously interleaved with action routing and PAM proof verification inside a single function.This change separates connection handling into focused helper methods:
readFramedRequest(fd:): Handles socket timeout configuration, chunk reading, buffer bounding, and newline delimiter validation, returning(data: Data?, errorReason: String?).handleAuthenticate(fd:request:timeout:): Encapsulates protocol v2 challenge-response verification and failure signaling.handleDiagnostic(fd:request:timeout:): Encapsulates diagnostic authentication and evidence restriction enforcement.All existing failure reasons (
invalid_frame,incomplete_request,parse_error,unknown_action,evidence_v2_required,invalid_or_missing_proof,diagnostic_evidence_forbidden), response JSON formats, and OSLog messages are preserved without behavioral divergence.Testing
swift test --package-path daemon: 115 tests pass (18 XCTest + 97 Swift Testing).swift test --package-path daemon --sanitize=thread: 115 tests pass with 0 data races.