Add implementation for stop command

This adds implementation for stopping the tunnel
via the `Stop` command.
This commit is contained in:
Jett Chen 2024-02-11 03:17:14 +08:00
parent 29d2bfae3f
commit c4c342dc8b
5 changed files with 81 additions and 38 deletions

View file

@ -44,6 +44,17 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
}
override func stopTunnel(with reason: NEProviderStopReason) async {
do {
let client = try Client()
let command = BurrowRequest(id: 0, command: "Stop")
let data = try await client.request(command, type: Response<BurrowResult<String>>.self)
self.logger.log("Stopped client.")
} catch {
self.logger.error("Failed to stop tunnel: \(error)")
}
}
private func generateTunSettings(from: ServerConfigData) -> NETunnelNetworkSettings? {
let cfig = from.ServerConfig
let nst = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "1.1.1.1")