Parse routing policies for TunnelKitProvider

This commit is contained in:
Davide De Rosa 2019-04-25 14:09:27 +02:00
parent f9f642b64e
commit 7382616e8b
1 changed files with 19 additions and 0 deletions

View File

@ -176,6 +176,14 @@ extension TunnelKitProvider {
sessionConfigurationBuilder.httpsProxy = proxy
}
sessionConfigurationBuilder.proxyBypassDomains = providerConfiguration[S.proxyBypassDomains] as? [String]
if let routingPoliciesStrings = providerConfiguration[S.routingPolicies] as? [String], !routingPoliciesStrings.isEmpty {
sessionConfigurationBuilder.routingPolicies = try routingPoliciesStrings.map {
guard let policy = SessionProxy.RoutingPolicy(rawValue: $0) else {
throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.routingPolicies)] has a badly formed element")
}
return policy
}
}
sessionConfiguration = sessionConfigurationBuilder.build()
shouldDebug = providerConfiguration[S.debug] as? Bool ?? ConfigurationBuilder.defaults.shouldDebug
@ -259,6 +267,8 @@ extension TunnelKitProvider {
static let proxyBypassDomains = "ProxyBypassDomains"
static let routingPolicies = "RoutingPolicies"
// MARK: Debugging
static let debug = "Debug"
@ -471,6 +481,9 @@ extension TunnelKitProvider {
if let proxyBypassDomains = sessionConfiguration.proxyBypassDomains {
dict[S.proxyBypassDomains] = proxyBypassDomains
}
if let routingPolicies = sessionConfiguration.routingPolicies {
dict[S.routingPolicies] = routingPolicies.map { $0.rawValue }
}
//
if let resolvedAddresses = resolvedAddresses {
dict[S.resolvedAddresses] = resolvedAddresses
@ -559,6 +572,12 @@ extension TunnelKitProvider {
if sessionConfiguration.randomizeEndpoint ?? false {
log.info("\tRandomize endpoint: true")
}
// FIXME: refine logging of other routing policies
if let routingPolicies = sessionConfiguration.routingPolicies {
log.info("\tDefault gateway: \(routingPolicies.map { $0.rawValue })")
} else {
log.info("\tDefault gateway: no")
}
if let dnsServers = sessionConfiguration.dnsServers {
log.info("\tDNS servers: \(dnsServers.maskedDescription)")
}