Improve connection status determination logic
This commit is contained in:
parent
b887b8d2ff
commit
68bb55e7d4
1 changed files with 21 additions and 5 deletions
|
|
@ -402,16 +402,32 @@ class ConnectionController:
|
|||
@staticmethod
|
||||
def __test_connection(port_number: Optional[int] = None, timeout: float = 10.0):
|
||||
|
||||
timeout = float(timeout)
|
||||
proxies = None
|
||||
request_urls = [Constants.PING_URL]
|
||||
timeout = float(timeout)
|
||||
|
||||
if port_number is not None:
|
||||
proxies = ConnectionController.get_proxies(port_number)
|
||||
|
||||
try:
|
||||
requests.get(Constants.PING_URL, timeout=timeout, proxies=proxies)
|
||||
except requests.exceptions.RequestException:
|
||||
raise ConnectionError('The connection could not be established.')
|
||||
if os.environ.get('PING_URL') is None:
|
||||
|
||||
request_urls.extend([
|
||||
'https://hc1.simplifiedprivacy.net',
|
||||
'https://hc2.simplifiedprivacy.org',
|
||||
'https://hc3.hydraveil.net'
|
||||
])
|
||||
|
||||
for request_url in request_urls:
|
||||
|
||||
try:
|
||||
|
||||
requests.get(request_url, timeout=timeout, proxies=proxies)
|
||||
return None
|
||||
|
||||
except requests.exceptions.RequestException:
|
||||
pass
|
||||
|
||||
raise ConnectionError('The connection could not be established.')
|
||||
|
||||
@staticmethod
|
||||
def __should_renegotiate(profile: Union[SessionProfile, SystemProfile]):
|
||||
|
|
|
|||
Loading…
Reference in a new issue