Refactor server handler to use ClientMessage/ServerMessage enums and protocol builders
Rewrite the connection handler’s dispatch function to decode raw frame
payloads through protocol::decode_client_message, which returns a typed
ClientMessage enum. The match statement now patterns on the enum variant
directly rather than matching MessageType discriminants and manually
deserializing individual structs. This eliminates redundant deserialization
code and catches direction mismatches at the protocol boundary.
All server response construction now uses the protocol builder functions:
build_handshake_ack_success, build_handshake_ack_failed, build_archive_accept,
build_restore_accept, build_status_response, and build_error. The
send_server_msg helper takes a ServerMessage enum, calls message_type() for
the frame header discriminant, and serializes through encode_frame. This
replaces scattered struct literal construction and manual frame encoding
with a single call site.
The handler functions (handle_handshake, handle_archive_start,
handle_archive_finish, handle_restore_start, handle_status) are unchanged
in logic but now operate on the inner payload structs extracted by the
dispatch layer. Storage locking uses scoped blocks with read().unwrap() and
write().unwrap() guards that drop before the next operation. Unused imports
are cleaned up, including the removal of the deprecated
ring::constant_time import.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.