Expose server configuration via provider message

This commit is contained in:
Davide De Rosa 2019-10-23 09:42:32 +02:00
parent 74ec321946
commit 7608ae2e3c
3 changed files with 15 additions and 0 deletions

View File

@ -51,6 +51,11 @@ extension OpenVPNTunnelProvider {
/// Data is 16 bytes: low 8 = received, high 8 = sent. /// Data is 16 bytes: low 8 = received, high 8 = sent.
public static let dataCount = Message(0xfe) public static let dataCount = Message(0xfe)
/// Requests the configuration pulled from the server (if connected and available).
///
/// Data is JSON (Decodable).
public static let serverConfiguration = Message(0xfd)
/// The underlying raw message `Data` to forward to the tunnel via IPC. /// The underlying raw message `Data` to forward to the tunnel via IPC.
public let data: Data public let data: Data

View File

@ -277,6 +277,12 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
response?.append(UInt64(dataCount.1)) // outbound response?.append(UInt64(dataCount.1)) // outbound
} }
case .serverConfiguration:
if let cfg = session?.serverConfiguration() {
let encoder = JSONEncoder()
response = try? encoder.encode(cfg)
}
default: default:
break break
} }

View File

@ -308,6 +308,10 @@ public class OpenVPNSession: Session {
return controlChannel.currentDataCount() return controlChannel.currentDataCount()
} }
public func serverConfiguration() -> OpenVPN.Configuration? {
return pushReply?.options
}
public func shutdown(error: Error?) { public func shutdown(error: Error?) {
guard !isStopping else { guard !isStopping else {
log.warning("Ignore stop request, already stopping!") log.warning("Ignore stop request, already stopping!")