Update connection status determination logic
This commit is contained in:
parent
6dfd5993a2
commit
616a864c9d
2 changed files with 9 additions and 15 deletions
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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.')
|
||||
|
|
|
|||
Loading…
Reference in a new issue