Improve connection status determination logic
This commit is contained in:
parent
b887b8d2ff
commit
68bb55e7d4
1 changed files with 21 additions and 5 deletions
|
|
@ -402,15 +402,31 @@ class ConnectionController:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __test_connection(port_number: Optional[int] = None, timeout: float = 10.0):
|
def __test_connection(port_number: Optional[int] = None, timeout: float = 10.0):
|
||||||
|
|
||||||
timeout = float(timeout)
|
|
||||||
proxies = None
|
proxies = None
|
||||||
|
request_urls = [Constants.PING_URL]
|
||||||
|
timeout = float(timeout)
|
||||||
|
|
||||||
if port_number is not None:
|
if port_number is not None:
|
||||||
proxies = ConnectionController.get_proxies(port_number)
|
proxies = ConnectionController.get_proxies(port_number)
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
requests.get(Constants.PING_URL, timeout=timeout, proxies=proxies)
|
|
||||||
|
requests.get(request_url, timeout=timeout, proxies=proxies)
|
||||||
|
return None
|
||||||
|
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
|
pass
|
||||||
|
|
||||||
raise ConnectionError('The connection could not be established.')
|
raise ConnectionError('The connection could not be established.')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue