From f3545e6f98f80f53a40a497f4e1453500c86af2e Mon Sep 17 00:00:00 2001 From: Macbook Date: Sun, 1 Dec 2024 16:51:11 +0700 Subject: [PATCH 01/14] fixbug handshake-time --- .../ios/PacketTunnelProvider+WireGuard.swift | 12 +++++++++++- client/platforms/ios/ios_controller.mm | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/client/platforms/ios/PacketTunnelProvider+WireGuard.swift b/client/platforms/ios/PacketTunnelProvider+WireGuard.swift index 18200c7fc..6e073df97 100644 --- a/client/platforms/ios/PacketTunnelProvider+WireGuard.swift +++ b/client/platforms/ios/PacketTunnelProvider+WireGuard.swift @@ -111,10 +111,20 @@ extension PacketTunnelProvider { settingsDictionary[pair[0]] = pair[1] } } + + let lastHandshakeString = settingsDictionary["last_handshake_time_sec"] + let lastHandshake: Int64 + + if let lastHandshakeValue = lastHandshakeString, let handshakeValue = Int64(lastHandshakeValue) { + lastHandshake = handshakeValue + } else { + lastHandshake = -2 // Trả về lỗi nếu không có giá trị last_handshake_time_sec + } let response: [String: Any] = [ "rx_bytes": settingsDictionary["rx_bytes"] ?? "0", - "tx_bytes": settingsDictionary["tx_bytes"] ?? "0" + "tx_bytes": settingsDictionary["tx_bytes"] ?? "0", + "last_handshake_time_sec": lastHandshake ] completionHandler(try? JSONSerialization.data(withJSONObject: response, options: [])) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 85fb50b79..2fd2467ae 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -249,6 +249,17 @@ sendVpnExtensionMessage(message, [&](NSDictionary* response){ uint64_t txBytes = [response[@"tx_bytes"] intValue]; uint64_t rxBytes = [response[@"rx_bytes"] intValue]; + uint64_t last_handshake_time_sec = 0; + if (response[@"last_handshake_time_sec"] && ![response[@"last_handshake_time_sec"] isKindOfClass:[NSNull class]]) { + last_handshake_time_sec = [response[@"last_handshake_time_sec"] intValue]; + } else { + qDebug() << "Key last_handshake_time_sec is missing or null"; + } + + if (last_handshake_time_sec < 0) { + disconnectVpn(); + qDebug() << "Invalid handshake time, disconnecting VPN."; + } emit bytesChanged(rxBytes - m_rxBytes, txBytes - m_txBytes); m_rxBytes = rxBytes; m_txBytes = txBytes; From a3b1f9b8aed8eccce95d958976dd638766e4b220 Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Mon, 2 Dec 2024 13:37:49 +0700 Subject: [PATCH 02/14] remove comment --- client/platforms/ios/PacketTunnelProvider+WireGuard.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/platforms/ios/PacketTunnelProvider+WireGuard.swift b/client/platforms/ios/PacketTunnelProvider+WireGuard.swift index 6e073df97..7a5c125b1 100644 --- a/client/platforms/ios/PacketTunnelProvider+WireGuard.swift +++ b/client/platforms/ios/PacketTunnelProvider+WireGuard.swift @@ -118,7 +118,7 @@ extension PacketTunnelProvider { if let lastHandshakeValue = lastHandshakeString, let handshakeValue = Int64(lastHandshakeValue) { lastHandshake = handshakeValue } else { - lastHandshake = -2 // Trả về lỗi nếu không có giá trị last_handshake_time_sec + lastHandshake = -2 } let response: [String: Any] = [ From 6d31ec363c8f102315193c35ae2caddf293c97ad Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Thu, 5 Dec 2024 22:40:25 +0700 Subject: [PATCH 03/14] Update ios_controller.h --- client/platforms/ios/ios_controller.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/platforms/ios/ios_controller.h b/client/platforms/ios/ios_controller.h index 855807691..1bfe3e1bc 100644 --- a/client/platforms/ios/ios_controller.h +++ b/client/platforms/ios/ios_controller.h @@ -63,6 +63,8 @@ class IosController : public QObject void finished(); + void stopForHandshake(); + void waitForHandshake(); protected slots: private: From 0822bf8a452929c532a8ca0f9de8fa922015293b Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Thu, 5 Dec 2024 22:47:17 +0700 Subject: [PATCH 04/14] Update ios_controller.mm --- client/platforms/ios/ios_controller.mm | 63 +++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 2fd2467ae..45cdd5bff 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -7,7 +7,7 @@ #include #include #include - +#include #include "../protocols/vpnprotocol.h" #import "ios_controller_wrapper.h" @@ -58,6 +58,7 @@ namespace { IosController* s_instance = nullptr; +QTimer *m_handshakeTimer = nullptr; } IosController::IosController() : QObject() @@ -367,6 +368,7 @@ } else { qDebug() << "Disconnect error is unavailable on iOS < 16.0"; } + stopForHandshake(); } emit connectionStateChanged(iosStatusToState(session.status)); @@ -405,6 +407,7 @@ QJsonDocument openVPNConfigDoc(openVPNConfig); QString openVPNConfigStr(openVPNConfigDoc.toJson(QJsonDocument::Compact)); + stopForHandshake(); return startOpenVPN(openVPNConfigStr); } @@ -464,6 +467,7 @@ QJsonDocument openVPNConfigDoc(openVPNConfig); QString openVPNConfigStr(openVPNConfigDoc.toJson(QJsonDocument::Compact)); + stopForHandshake(); return startOpenVPN(openVPNConfigStr); } @@ -527,6 +531,7 @@ QJsonDocument wgConfigDoc(wgConfig); QString wgConfigDocStr(wgConfigDoc.toJson(QJsonDocument::Compact)); + waitForHandshake(); return startWireGuard(wgConfigDocStr); } @@ -545,6 +550,7 @@ QJsonDocument finalConfigDoc(finalConfig); QString finalConfigStr(finalConfigDoc.toJson(QJsonDocument::Compact)); + stopForHandshake(); return startXray(finalConfigStr); } @@ -563,6 +569,7 @@ QJsonDocument finalConfigDoc(finalConfig); QString finalConfigStr(finalConfigDoc.toJson(QJsonDocument::Compact)); + stopForHandshake(); return startXray(finalConfigStr); } @@ -624,6 +631,7 @@ QJsonDocument wgConfigDoc(wgConfig); QString wgConfigDocStr(wgConfigDoc.toJson(QJsonDocument::Compact)); + waitForHandshake(); return startWireGuard(wgConfigDocStr); } @@ -874,3 +882,56 @@ }]; [task resume]; } + +void IosController::stopForHandshake() { + if (m_handshakeTimer) { + // Stop the timer if it's active + m_handshakeTimer->stop(); + delete m_handshakeTimer; + m_handshakeTimer = nullptr; + + qDebug() << "Handshake monitoring stopped."; + } else { + qDebug() << "No active handshake monitoring to stop."; + } +} + +void IosController::waitForHandshake() { + qDebug() << "Waiting for last_handshake_time_sec to be greater than 0..."; + + // Lambda to handle the response + auto checkHandshake = [this](NSDictionary *response) { + uint64_t last_handshake_time_sec = 0; + if (response && response[@"last_handshake_time_sec"] && ![response[@"last_handshake_time_sec"] isKindOfClass:[NSNull class]]) { + last_handshake_time_sec = [response[@"last_handshake_time_sec"] unsignedLongLongValue]; + } + + qDebug() << "last_handshake_time_sec:" << last_handshake_time_sec; + + if (last_handshake_time_sec > 0) { + // Handshake successful, update state + qDebug() << "Handshake detected, updating state to CONNECTED."; + emit connectionStateChanged(Vpn::ConnectionState::Connected); + } else { + if (last_handshake_time_sec == 0) { + // Retry after a delay + emit connectionStateChanged(Vpn::ConnectionState::Connecting); + QTimer::singleShot(1000, this, [this]() { waitForHandshake(); }); + }else{ + emit connectionStateChanged(Vpn::ConnectionState::Disconnected); + stopForHandshake(); // Stop monitoring on error + } + } + }; + + // Prepare the message to check status + NSString *actionKey = [NSString stringWithUTF8String:MessageKey::action]; + NSString *actionValue = [NSString stringWithUTF8String:Action::getStatus]; + NSString *tunnelIdKey = [NSString stringWithUTF8String:MessageKey::tunnelId]; + NSString *tunnelIdValue = !m_tunnelId.isEmpty() ? m_tunnelId.toNSString() : @""; + + NSDictionary *message = @{actionKey: actionValue, tunnelIdKey: tunnelIdValue}; + + // Send the message to the VPN extension + sendVpnExtensionMessage(message, checkHandshake); +} From b899b2a68fef677b1de90bfa54acc58602bcc95b Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Sat, 7 Dec 2024 13:06:33 +0700 Subject: [PATCH 05/14] Update ios_controller.mm --- client/platforms/ios/ios_controller.mm | 84 ++++++++++++++++---------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 45cdd5bff..44528d1d6 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -885,9 +885,9 @@ void IosController::stopForHandshake() { if (m_handshakeTimer) { - // Stop the timer if it's active - m_handshakeTimer->stop(); - delete m_handshakeTimer; + if (m_handshakeTimer->isActive()) { + m_handshakeTimer->stop(); + } m_handshakeTimer = nullptr; qDebug() << "Handshake monitoring stopped."; @@ -899,39 +899,57 @@ void IosController::waitForHandshake() { qDebug() << "Waiting for last_handshake_time_sec to be greater than 0..."; - // Lambda to handle the response - auto checkHandshake = [this](NSDictionary *response) { - uint64_t last_handshake_time_sec = 0; - if (response && response[@"last_handshake_time_sec"] && ![response[@"last_handshake_time_sec"] isKindOfClass:[NSNull class]]) { - last_handshake_time_sec = [response[@"last_handshake_time_sec"] unsignedLongLongValue]; - } + // Initialize the timer if it's null + if (!m_handshakeTimer) { + m_handshakeTimer = new QTimer(this); + + // Connect the timer's timeout signal to perform handshake checking + connect(m_handshakeTimer, &QTimer::timeout, this, [this]() { + // Prepare the message to check status + NSString *actionKey = [NSString stringWithUTF8String:MessageKey::action]; + NSString *actionValue = [NSString stringWithUTF8String:Action::getStatus]; + NSString *tunnelIdKey = [NSString stringWithUTF8String:MessageKey::tunnelId]; + NSString *tunnelIdValue = !m_tunnelId.isEmpty() ? m_tunnelId.toNSString() : @""; + + NSDictionary *message = @{actionKey: actionValue, tunnelIdKey: tunnelIdValue}; + + // Lambda to handle the response + auto checkHandshake = [this](NSDictionary *response) { + uint64_t last_handshake_time_sec = 0; + if (response && response[@"last_handshake_time_sec"] && + ![response[@"last_handshake_time_sec"] isKindOfClass:[NSNull class]]) { + last_handshake_time_sec = [response[@"last_handshake_time_sec"] unsignedLongLongValue]; + } - qDebug() << "last_handshake_time_sec:" << last_handshake_time_sec; + qDebug() << "last_handshake_time_sec:" << last_handshake_time_sec; - if (last_handshake_time_sec > 0) { - // Handshake successful, update state - qDebug() << "Handshake detected, updating state to CONNECTED."; - emit connectionStateChanged(Vpn::ConnectionState::Connected); - } else { - if (last_handshake_time_sec == 0) { - // Retry after a delay - emit connectionStateChanged(Vpn::ConnectionState::Connecting); - QTimer::singleShot(1000, this, [this]() { waitForHandshake(); }); - }else{ - emit connectionStateChanged(Vpn::ConnectionState::Disconnected); - stopForHandshake(); // Stop monitoring on error - } - } - }; + if (last_handshake_time_sec > 0) { + // Handshake successful, update state + qDebug() << "Handshake detected, updating state to CONNECTED."; + emit connectionStateChanged(Vpn::ConnectionState::Connected); + } else { + if (last_handshake_time_sec == 0) { + // Keep retrying + emit connectionStateChanged(Vpn::ConnectionState::Connecting); + } else { + // Handle handshake failure and stop monitoring + emit connectionStateChanged(Vpn::ConnectionState::Disconnected); + stopForHandshake(); + return; + } + } + }; - // Prepare the message to check status - NSString *actionKey = [NSString stringWithUTF8String:MessageKey::action]; - NSString *actionValue = [NSString stringWithUTF8String:Action::getStatus]; - NSString *tunnelIdKey = [NSString stringWithUTF8String:MessageKey::tunnelId]; - NSString *tunnelIdValue = !m_tunnelId.isEmpty() ? m_tunnelId.toNSString() : @""; + // Send the message to the VPN extension + sendVpnExtensionMessage(message, checkHandshake); + }); - NSDictionary *message = @{actionKey: actionValue, tunnelIdKey: tunnelIdValue}; + qDebug() << "Handshake timer initialized."; + } - // Send the message to the VPN extension - sendVpnExtensionMessage(message, checkHandshake); + // Start the timer only if it's not already active + if (m_handshakeTimer && !m_handshakeTimer->isActive()) { + m_handshakeTimer->start(1000); // Retry every 1 second + qDebug() << "Handshake timer Retry every 1 second"; + } } From 498cd28a1eb9c57a673b98f7c5ddc2b09c75aa39 Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Sat, 7 Dec 2024 13:07:05 +0700 Subject: [PATCH 06/14] Update ios_controller.h --- client/platforms/ios/ios_controller.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/platforms/ios/ios_controller.h b/client/platforms/ios/ios_controller.h index 1bfe3e1bc..543b8e41e 100644 --- a/client/platforms/ios/ios_controller.h +++ b/client/platforms/ios/ios_controller.h @@ -55,6 +55,9 @@ class IosController : public QObject QString openFile(); void requestInetAccess(); + + void stopForHandshake(); + void waitForHandshake(); signals: void connectionStateChanged(Vpn::ConnectionState state); void bytesChanged(quint64 receivedBytes, quint64 sentBytes); @@ -62,9 +65,6 @@ class IosController : public QObject void importBackupFromOutside(const QString); void finished(); - - void stopForHandshake(); - void waitForHandshake(); protected slots: private: From fa3fcb664c9a3cf804da3dd3412b4852b13d0146 Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Sat, 7 Dec 2024 15:39:50 +0700 Subject: [PATCH 07/14] remove catch Handshake in IosController::checkStatus() function --- client/platforms/ios/ios_controller.mm | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 44528d1d6..1b2ab6c58 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -238,7 +238,6 @@ } } - void IosController::checkStatus() { NSString *actionKey = [NSString stringWithUTF8String:MessageKey::action]; @@ -250,17 +249,7 @@ sendVpnExtensionMessage(message, [&](NSDictionary* response){ uint64_t txBytes = [response[@"tx_bytes"] intValue]; uint64_t rxBytes = [response[@"rx_bytes"] intValue]; - uint64_t last_handshake_time_sec = 0; - if (response[@"last_handshake_time_sec"] && ![response[@"last_handshake_time_sec"] isKindOfClass:[NSNull class]]) { - last_handshake_time_sec = [response[@"last_handshake_time_sec"] intValue]; - } else { - qDebug() << "Key last_handshake_time_sec is missing or null"; - } - if (last_handshake_time_sec < 0) { - disconnectVpn(); - qDebug() << "Invalid handshake time, disconnecting VPN."; - } emit bytesChanged(rxBytes - m_rxBytes, txBytes - m_txBytes); m_rxBytes = rxBytes; m_txBytes = txBytes; From bc5d9d918214c01367b79e2e9f8cc7cdb74ea505 Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Sat, 7 Dec 2024 15:44:23 +0700 Subject: [PATCH 08/14] Update ios_controller.mm --- client/platforms/ios/ios_controller.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 1b2ab6c58..1f09eb1a5 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -249,7 +249,6 @@ sendVpnExtensionMessage(message, [&](NSDictionary* response){ uint64_t txBytes = [response[@"tx_bytes"] intValue]; uint64_t rxBytes = [response[@"rx_bytes"] intValue]; - emit bytesChanged(rxBytes - m_rxBytes, txBytes - m_txBytes); m_rxBytes = rxBytes; m_txBytes = txBytes; From 954d256ff3099ad3bd9e20a8ebad1635210d5102 Mon Sep 17 00:00:00 2001 From: AnhTVc Date: Sun, 8 Dec 2024 10:50:09 +0700 Subject: [PATCH 09/14] Update ios_controller.mm --- client/platforms/ios/ios_controller.mm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 1f09eb1a5..ba659eb30 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -395,7 +395,6 @@ QJsonDocument openVPNConfigDoc(openVPNConfig); QString openVPNConfigStr(openVPNConfigDoc.toJson(QJsonDocument::Compact)); - stopForHandshake(); return startOpenVPN(openVPNConfigStr); } @@ -455,7 +454,6 @@ QJsonDocument openVPNConfigDoc(openVPNConfig); QString openVPNConfigStr(openVPNConfigDoc.toJson(QJsonDocument::Compact)); - stopForHandshake(); return startOpenVPN(openVPNConfigStr); } @@ -538,7 +536,6 @@ QJsonDocument finalConfigDoc(finalConfig); QString finalConfigStr(finalConfigDoc.toJson(QJsonDocument::Compact)); - stopForHandshake(); return startXray(finalConfigStr); } @@ -557,7 +554,6 @@ QJsonDocument finalConfigDoc(finalConfig); QString finalConfigStr(finalConfigDoc.toJson(QJsonDocument::Compact)); - stopForHandshake(); return startXray(finalConfigStr); } From a1304017ce63fbef9114e1a7b2edc1a7133fa9c7 Mon Sep 17 00:00:00 2001 From: Macbook Date: Sun, 8 Dec 2024 15:47:24 +0700 Subject: [PATCH 10/14] update delete later --- client/platforms/ios/ios_controller.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index ba659eb30..4fbaac2f9 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -872,6 +872,7 @@ if (m_handshakeTimer->isActive()) { m_handshakeTimer->stop(); } + m_handshakeTimer->deleteLater(); m_handshakeTimer = nullptr; qDebug() << "Handshake monitoring stopped."; @@ -911,6 +912,8 @@ // Handshake successful, update state qDebug() << "Handshake detected, updating state to CONNECTED."; emit connectionStateChanged(Vpn::ConnectionState::Connected); + stopForHandshake(); + return; } else { if (last_handshake_time_sec == 0) { // Keep retrying From 307576e4bc1e2b51df440404a52cca3e8e0eff4c Mon Sep 17 00:00:00 2001 From: Macbook Date: Mon, 9 Dec 2024 22:14:39 +0700 Subject: [PATCH 11/14] bypass handle status connected vpn with WG --- client/platforms/ios/ios_controller.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 4fbaac2f9..9b5b33bc2 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -59,6 +59,7 @@ namespace { IosController* s_instance = nullptr; QTimer *m_handshakeTimer = nullptr; +bool is_WireGuard = false; } IosController::IosController() : QObject() @@ -206,21 +207,27 @@ if (proto == amnezia::Proto::OpenVpn) { + is_WireGuard = false; return setupOpenVPN(); } if (proto == amnezia::Proto::Cloak) { + is_WireGuard = false; return setupCloak(); } if (proto == amnezia::Proto::WireGuard) { + is_WireGuard = true; return setupWireGuard(); } if (proto == amnezia::Proto::Awg) { + is_WireGuard = true; return setupAwg(); } if (proto == amnezia::Proto::Xray) { + is_WireGuard = false; return setupXray(); } if (proto == amnezia::Proto::SSXray) { + is_WireGuard = false; return setupSSXray(); } @@ -261,7 +268,11 @@ if (session /* && session == TunnelManager.session */ ) { qDebug() << "IosController::vpnStatusDidChange" << iosStatusToState(session.status) << session; - + if (is_WireGuard && session.status == NEVPNStatusConnected) + { + // use last_handshake_time for check status connected for WireGuard + return; + } if (session.status == NEVPNStatusDisconnected) { if (@available(iOS 16.0, *)) { [session fetchLastDisconnectErrorWithCompletionHandler:^(NSError * _Nullable error) { @@ -874,6 +885,7 @@ } m_handshakeTimer->deleteLater(); m_handshakeTimer = nullptr; + is_WireGuard = false; qDebug() << "Handshake monitoring stopped."; } else { From c862d70d82e55e6fbd4e882b4ac3a16911a9fd0f Mon Sep 17 00:00:00 2001 From: Macbook Date: Fri, 20 Dec 2024 10:38:48 +0700 Subject: [PATCH 12/14] move func check handshake to start vpn function --- client/platforms/ios/ios_controller.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 9b5b33bc2..daa74be5c 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -528,7 +528,6 @@ QJsonDocument wgConfigDoc(wgConfig); QString wgConfigDocStr(wgConfigDoc.toJson(QJsonDocument::Compact)); - waitForHandshake(); return startWireGuard(wgConfigDocStr); } @@ -626,7 +625,6 @@ QJsonDocument wgConfigDoc(wgConfig); QString wgConfigDocStr(wgConfigDoc.toJson(QJsonDocument::Compact)); - waitForHandshake(); return startWireGuard(wgConfigDocStr); } @@ -655,6 +653,7 @@ m_currentTunnel.protocolConfiguration = tunnelProtocol; + waitForHandshake(); startTunnel(); } From 6331658a76ef62ec83a31449c67903cccf879051 Mon Sep 17 00:00:00 2001 From: Macbook Date: Sun, 22 Dec 2024 22:27:31 +0700 Subject: [PATCH 13/14] remove is_WireGuard --- client/platforms/ios/ios_controller.mm | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index daa74be5c..10056d62b 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -59,7 +59,6 @@ namespace { IosController* s_instance = nullptr; QTimer *m_handshakeTimer = nullptr; -bool is_WireGuard = false; } IosController::IosController() : QObject() @@ -207,27 +206,21 @@ if (proto == amnezia::Proto::OpenVpn) { - is_WireGuard = false; return setupOpenVPN(); } if (proto == amnezia::Proto::Cloak) { - is_WireGuard = false; return setupCloak(); } if (proto == amnezia::Proto::WireGuard) { - is_WireGuard = true; return setupWireGuard(); } if (proto == amnezia::Proto::Awg) { - is_WireGuard = true; return setupAwg(); } if (proto == amnezia::Proto::Xray) { - is_WireGuard = false; return setupXray(); } if (proto == amnezia::Proto::SSXray) { - is_WireGuard = false; return setupSSXray(); } @@ -265,10 +258,10 @@ void IosController::vpnStatusDidChange(void *pNotification) { NETunnelProviderSession *session = (NETunnelProviderSession *)pNotification; - + NETunnelProviderProtocol *tunnelProtocol = (NETunnelProviderProtocol *)m_currentTunnel.protocolConfiguration; if (session /* && session == TunnelManager.session */ ) { qDebug() << "IosController::vpnStatusDidChange" << iosStatusToState(session.status) << session; - if (is_WireGuard && session.status == NEVPNStatusConnected) + if (tunnelProtocol.providerConfiguration[@"wireguard"] != nil && session.status == NEVPNStatusConnected) { // use last_handshake_time for check status connected for WireGuard return; @@ -680,6 +673,8 @@ protocolName = @"WireGuard"; } else if (tunnelProtocol.providerConfiguration[@"ovpn"] != nil) { protocolName = @"OpenVPN"; + } else if (tunnelProtocol.providerConfiguration[@"xray"] != nil) { + protocolName = @"XRay"; } m_rxBytes = 0; @@ -884,7 +879,6 @@ } m_handshakeTimer->deleteLater(); m_handshakeTimer = nullptr; - is_WireGuard = false; qDebug() << "Handshake monitoring stopped."; } else { From c9003f537dc8966d178c61740c1669e768e9cb7b Mon Sep 17 00:00:00 2001 From: Macbook Date: Tue, 24 Dec 2024 23:05:27 +0700 Subject: [PATCH 14/14] fixbug QTTimeer --- client/platforms/ios/ios_controller.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/platforms/ios/ios_controller.mm b/client/platforms/ios/ios_controller.mm index 10056d62b..e81f5ac77 100644 --- a/client/platforms/ios/ios_controller.mm +++ b/client/platforms/ios/ios_controller.mm @@ -874,6 +874,12 @@ void IosController::stopForHandshake() { if (m_handshakeTimer) { + if (QThread::currentThread() != m_handshakeTimer->thread()) { + QMetaObject::invokeMethod(m_handshakeTimer, "stop", Qt::QueuedConnection); + QMetaObject::invokeMethod(m_handshakeTimer, "deleteLater", Qt::QueuedConnection); + m_handshakeTimer = nullptr; + return; + } if (m_handshakeTimer->isActive()) { m_handshakeTimer->stop(); }