WireGuardKit: Remove handleLogLine from WireGuardAdapter

Signed-off-by: Andrej Mihajlov <and@mullvad.net>
This commit is contained in:
Andrej Mihajlov 2020-12-02 13:53:16 +01:00
parent 697d449dc8
commit 2e356d3d8f
1 changed files with 9 additions and 22 deletions

View File

@ -239,7 +239,7 @@ public class WireGuardAdapter {
let swiftString = String(cString: message).trimmingCharacters(in: .newlines) let swiftString = String(cString: message).trimmingCharacters(in: .newlines)
let tunnelLogLevel = WireGuardLogLevel(rawValue: logLevel) ?? .debug let tunnelLogLevel = WireGuardLogLevel(rawValue: logLevel) ?? .debug
unretainedSelf.handleLogLine(level: tunnelLogLevel, message: swiftString) unretainedSelf.logHandler(tunnelLogLevel, swiftString)
} }
} }
@ -316,34 +316,21 @@ public class WireGuardAdapter {
return resolvedEndpoints return resolvedEndpoints
} }
/// Private helper to pass the logs coming from WireGuard to
/// - Parameters:
/// - level: log level
/// - message: message
private func handleLogLine(level: WireGuardLogLevel, message: String) {
workQueue.async {
self.logHandler?(level, message)
}
}
/// Helper method used by network path monitor. /// Helper method used by network path monitor.
/// - Parameter path: new network path /// - Parameter path: new network path
private func didReceivePathUpdate(path: Network.NWPath) { private func didReceivePathUpdate(path: Network.NWPath) {
guard let handle = self.wireguardHandle else { return }
if let handle = self.wireguardHandle { self.logHandler(.debug, "Network change detected with \(path.status) route and interface order \(path.availableInterfaces)")
self.handleLogLine(level: .debug, message: "Network change detected with \(path.status) route and interface order \(path.availableInterfaces)")
#if os(iOS) #if os(iOS)
if let settingsGenerator = self.settingsGenerator { if let settingsGenerator = self.settingsGenerator {
wgSetConfig(handle, settingsGenerator.endpointUapiConfiguration()) wgSetConfig(handle, settingsGenerator.endpointUapiConfiguration())
} }
// TODO: dynamically turn on or off WireGuard backend when entering airplane mode
#endif #endif
wgBumpSockets(handle) wgBumpSockets(handle)
} }
}
} }
/// A enum describing WireGuard log levels defined in `api-ios.go`. /// A enum describing WireGuard log levels defined in `api-ios.go`.