Start wire-up of logging and tunnel system.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -7,16 +7,31 @@
|
||||
//
|
||||
|
||||
import NetworkExtension
|
||||
import os.log
|
||||
|
||||
class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
let wireGuardWrapper = WireGuardGoWrapper()
|
||||
|
||||
private let tunnelQueue = DispatchQueue(label: PacketTunnelProvider.description())
|
||||
|
||||
//TODO create a way to transfer config into extension
|
||||
|
||||
override func startTunnel(options: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void) {
|
||||
os_log("Starting tunnel", log: Log.general, type: .info)
|
||||
// Add code here to start the process of connecting the tunnel.
|
||||
|
||||
//TODO get a settings string in here.
|
||||
tunnelQueue.sync {
|
||||
wireGuardWrapper.turnOn(withInterfaceName: "TODO", settingsString: "TODO")
|
||||
}
|
||||
}
|
||||
|
||||
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
||||
os_log("Stopping tunnel", log: Log.general, type: .info)
|
||||
// Add code here to start the process of stopping the tunnel.
|
||||
tunnelQueue.sync {
|
||||
wireGuardWrapper.turnOff()
|
||||
}
|
||||
completionHandler()
|
||||
}
|
||||
|
||||
@@ -27,12 +42,21 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
override func sleep(completionHandler: @escaping () -> Void) {
|
||||
// Add code here to get ready to sleep.
|
||||
completionHandler()
|
||||
private func loopReadPackets(_ handler: @escaping ([Data]?, Error?) -> Void) {
|
||||
packetFlow.readPackets { [weak self] (_, _) in
|
||||
// TODO write packets into the tunnel
|
||||
self?.loopReadPackets(handler)
|
||||
}
|
||||
}
|
||||
|
||||
override func wake() {
|
||||
// Add code here to wake up.
|
||||
func writePacket(_ packet: Data, completionHandler: ((Error?) -> Void)?) {
|
||||
packetFlow.writePackets([packet], withProtocols: [AF_INET] as [NSNumber])
|
||||
completionHandler?(nil)
|
||||
}
|
||||
|
||||
func writePackets(_ packets: [Data], completionHandler: ((Error?) -> Void)?) {
|
||||
let protocols = [Int32](repeating: AF_INET, count: packets.count) as [NSNumber]
|
||||
packetFlow.writePackets(packets, withProtocols: protocols)
|
||||
completionHandler?(nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user