Skip to content

[Audit] Refactor ConnectionManager for Simplicity and Robustness #109

Description

@iret77

Summary

A high-level code audit of ConnectionManager.swift found the code to be of high quality and well-architected. However, three minor areas for improvement were identified to increase simplicity and robustness.

Findings

  1. Refactor retryTimer Logic:

    • Current: The timer fires every second to tick down a countdown, sending a .retryTimerTick event to the state machine on each tick.
    • Suggestion: Simplify this to a single-shot Timer that fires once after the required delay and sends a single .retryNow event. This would reduce complexity and the number of events processed.
  2. Fix gatewayBaseURL Default Behavior:

    • Current: The computed property defaults to 127.0.0.1 if config.gatewayHost is an empty string.
    • Problem: This can lead to unexpected behavior if a user clears the host field, as the app might silently attempt to connect to localhost.
    • Suggestion: Return nil if the host is empty and the SSH tunnel is not active.
  3. Improve stateMachine Encapsulation:

    • Current: The stateMachine property is declared as public let.
    • Problem: This allows any part of the app to potentially call stateMachine.handle() directly, bypassing the orchestration, logging, and side-effect execution logic in ConnectionManager.
    • Suggestion: Change the declaration to public private(set), preventing external modification while still allowing read-only access for observation if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:lowLow prioritytech-debtTechnical debt and code hygienetriagedIssue has been triaged

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions