Skip to content

Commit

Permalink
Merge branch 'fix-swiftlint-warnings-in-xcode-ios-PacketTunnelProvide…
Browse files Browse the repository at this point in the history
…r-296'
  • Loading branch information
buggmagnet committed Sep 19, 2023
2 parents b84180c + b2a8720 commit a93b710
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions ios/PacketTunnel/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
override init() {
var loggerBuilder = LoggerBuilder()
let pid = ProcessInfo.processInfo.processIdentifier

loggerBuilder.metadata["pid"] = .string("\(pid)")
loggerBuilder.addFileOutput(fileURL: ApplicationConfiguration.logFileURL(for: .packetTunnel))

#if DEBUG
loggerBuilder.addOSLogOutput(subsystem: ApplicationTarget.packetTunnel.bundleIdentifier)
#endif

loggerBuilder.install()

providerLogger = Logger(label: "PacketTunnelProvider")
Expand Down Expand Up @@ -168,23 +171,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {

super.init()

adapter = WireGuardAdapter(
with: self,
shouldHandleReasserting: false,
logHandler: { [weak self] logLevel, message in
self?.dispatchQueue.async {
self?.tunnelLogger.log(level: logLevel.loggerLevel, "\(message)")
}
}
)
adapter = createWireGuardAdapter()

tunnelMonitor = TunnelMonitor(
eventQueue: dispatchQueue,
pinger: Pinger(replyQueue: dispatchQueue),
tunnelDeviceInfo: WgAdapterDeviceInfo(adapter: adapter),
defaultPathObserver: PacketTunnelPathObserver(packetTunnelProvider: self),
timings: TunnelMonitorTimings()
)
tunnelMonitor = createTunnelMonitor(wireGuardAdapter: adapter)
tunnelMonitor.onEvent = { [weak self] event in
self?.handleTunnelMonitorEvent(event)
}
Expand Down Expand Up @@ -288,10 +277,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
do {
message = try TunnelProviderMessage(messageData: messageData)
} catch {
self.providerLogger.error(
error: error,
message: "Failed to decode the app message."
)
self.providerLogger.error(error: error, message: "Failed to decode the app message.")

completionHandler?(nil)
return
Expand All @@ -303,9 +289,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
case let .reconnectTunnel(appSelectorResult):
self.providerLogger.debug("Reconnecting the tunnel...")

let nextRelay: NextRelay = (appSelectorResult ?? self.selectorResult)
.map { .set($0) } ?? .automatic

let nextRelay: NextRelay = (appSelectorResult ?? self.selectorResult).map { .set($0) } ?? .automatic
self.reconnectTunnel(to: nextRelay, shouldStopTunnelMonitor: true)

completionHandler?(nil)
Expand Down Expand Up @@ -420,6 +404,28 @@ class PacketTunnelProvider: NEPacketTunnelProvider {

// MARK: - Private

private func createWireGuardAdapter() -> WireGuardAdapter {
WireGuardAdapter(
with: self,
shouldHandleReasserting: false,
logHandler: { [weak self] logLevel, message in
self?.dispatchQueue.async {
self?.tunnelLogger.log(level: logLevel.loggerLevel, "\(message)")
}
}
)
}

private func createTunnelMonitor(wireGuardAdapter: WireGuardAdapter) -> TunnelMonitor {
TunnelMonitor(
eventQueue: dispatchQueue,
pinger: Pinger(replyQueue: dispatchQueue),
tunnelDeviceInfo: WgAdapterDeviceInfo(adapter: adapter),
defaultPathObserver: PacketTunnelPathObserver(packetTunnelProvider: self),
timings: TunnelMonitorTimings()
)
}

private func startTunnelReconnectionTimer(reconnectionDelay: Duration) {
dispatchPrecondition(condition: .onQueue(dispatchQueue))

Expand Down

0 comments on commit a93b710

Please sign in to comment.