From 616a864c9d5b233cf85846738d2317af84c2add9 Mon Sep 17 00:00:00 2001 From: codeking Date: Sun, 18 Jan 2026 05:09:23 +0100 Subject: [PATCH] Update connection status determination logic --- core/Constants.py | 3 +++ core/controllers/ConnectionController.py | 21 ++++++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/core/Constants.py b/core/Constants.py index 2d20b14..36a0ef6 100644 --- a/core/Constants.py +++ b/core/Constants.py @@ -9,6 +9,9 @@ class Constants: SP_API_BASE_URL: Final[str] = os.environ.get('SP_API_BASE_URL', 'https://api.hydraveil.net/api/v1') PING_URL: Final[str] = os.environ.get('PING_URL', 'https://api.hydraveil.net/api/v1/health') + CONNECTION_RETRY_INTERVAL: Final[int] = int(os.environ.get('CONNECTION_RETRY_INTERVAL', '5')) + MAX_CONNECTION_ATTEMPTS: Final[int] = int(os.environ.get('MAX_CONNECTION_ATTEMPTS', '2')) + HV_CLIENT_PATH: Final[str] = os.environ.get('HV_CLIENT_PATH') HV_CLIENT_VERSION_NUMBER: Final[str] = os.environ.get('HV_CLIENT_VERSION_NUMBER') diff --git a/core/controllers/ConnectionController.py b/core/controllers/ConnectionController.py index 60345f2..8f825ca 100644 --- a/core/controllers/ConnectionController.py +++ b/core/controllers/ConnectionController.py @@ -122,7 +122,6 @@ class ConnectionController: session_directory = tempfile.mkdtemp(prefix='hv-') session_state = SessionStateController.get_or_new(profile.id) - maximum_number_of_attempts = None port_number = None proxy_port_number = None @@ -137,7 +136,6 @@ class ConnectionController: if profile.connection.code == 'tor': - maximum_number_of_attempts = 5 port_number = ConnectionController.get_random_available_port_number() ConnectionController.establish_tor_session_connection(session_directory, port_number) session_state.network_port_numbers.append(port_number) @@ -153,8 +151,6 @@ class ConnectionController: if profile.connection.masked: - maximum_number_of_attempts = 5 - while proxy_port_number is None or proxy_port_number == port_number: proxy_port_number = ConnectionController.get_random_available_port_number() @@ -162,7 +158,7 @@ class ConnectionController: session_state.network_port_numbers.append(proxy_port_number) if not profile.connection.is_unprotected(): - ConnectionController.await_connection(proxy_port_number or port_number, maximum_number_of_attempts, connection_observer=connection_observer) + ConnectionController.await_connection(proxy_port_number or port_number, connection_observer=connection_observer) SessionStateController.update_or_create(session_state) @@ -315,23 +311,18 @@ class ConnectionController: return port_number @staticmethod - def await_connection(port_number: Optional[int] = None, maximum_number_of_attempts: Optional[int] = None, connection_observer: Optional[ConnectionObserver] = None): + def await_connection(port_number: Optional[int] = None, connection_observer: Optional[ConnectionObserver] = None): if port_number is None: ConnectionController.await_network_interface() - if maximum_number_of_attempts is None: - maximum_number_of_attempts = 2 - - retry_interval = 5.0 - - for retry_count in range(maximum_number_of_attempts): + for retry_count in range(Constants.MAX_CONNECTION_ATTEMPTS): if connection_observer is not None: connection_observer.notify('connecting', dict( - retry_interval=retry_interval, - maximum_number_of_attempts=maximum_number_of_attempts, + retry_interval=Constants.CONNECTION_RETRY_INTERVAL, + maximum_number_of_attempts=Constants.MAX_CONNECTION_ATTEMPTS, attempt_count=retry_count + 1 )) @@ -342,7 +333,7 @@ class ConnectionController: except ConnectionError: - time.sleep(retry_interval) + time.sleep(Constants.CONNECTION_RETRY_INTERVAL) retry_count += 1 raise ConnectionError('The connection could not be established.')