Skip to content

refactor(daemon): modularize socket frame reading and PAM action handling in SocketServer - #48

Merged
HMAKT99 merged 1 commit into
HMAKT99:mainfrom
aymanysr:refactor/socket-frame-reading
Oct 31, 2026
Merged

HMAKT99 merged 1 commit into
HMAKT99:mainfrom
aymanysr:refactor/socket-frame-reading

Conversation

@aymanysr

Copy link
Copy Markdown
Contributor

Summary

In SocketServer.handleConnection(fd:), low-level POSIX recv() 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:

  1. readFramedRequest(fd:): Handles socket timeout configuration, chunk reading, buffer bounding, and newline delimiter validation, returning (data: Data?, errorReason: String?).
  2. handleAuthenticate(fd:request:timeout:): Encapsulates protocol v2 challenge-response verification and failure signaling.
  3. 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.

@HMAKT99
HMAKT99 merged commit 9c04e04 into HMAKT99:main Oct 31, 2026
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.

2 participants