Add connection test timeout support

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2023-09-15 13:21:37 +08:00
parent dad7f7e281
commit 7ae020a349
+25 -3
View File
@@ -120,6 +120,7 @@ class ConnectAction(Action):
'https://www.youtube.com/',
]
self.testTime = 0
self.testFinished = True
self.XrayCore = XrayCore()
self.Hysteria1 = Hysteria1()
@@ -1169,6 +1170,8 @@ class ConnectAction(Action):
showRoutingChangedMessage, currentRouting, isBuiltinRouting
)
else:
self.testFinished = True
if self.disconnectReason:
self.disconnectAction(self.disconnectReason)
else:
@@ -1178,11 +1181,12 @@ class ConnectAction(Action):
else:
logger.info(f'{self.coreName}: connection test success. Connected')
APP().Connect = Switch.ON_
self.testFinished = True
# Connected status
self.setConnectedStatus()
APP().Connect = Switch.ON_
if showRoutingChangedMessage:
# Routing changed
if isBuiltinRouting:
@@ -1257,6 +1261,21 @@ class ConnectAction(Action):
self.connectingAction()
def waitForConnectionTest(self, startCounter=0, timeout=30000, step=1):
while self.coreRunning and not self.testFinished and startCounter < timeout:
QTest.qWait(step)
startCounter += step
if self.coreRunning and not self.testFinished:
# Timeout
logger.error('connection test timeout. Abort')
assert isinstance(self.networkReply, QNetworkReply)
self.coreRunning = False
self.networkReply.abort()
def connectingAction(
self,
showProgressBar=True,
@@ -1305,11 +1324,14 @@ class ConnectAction(Action):
self.errorConfiguration()
else:
self.moveConnectingProgressBar()
# Reset try time
# Reset test time
self.testTime = 0
# Reset test finished
self.testFinished = False
self.startConnectionTest(
showRoutingChangedMessage, currentRouting, isBuiltinRouting
)
self.waitForConnectionTest()
def disconnectAction(self, reason=''):
Proxy.off()