Merge branch 'expose-default-configuration'

This commit is contained in:
Davide De Rosa 2018-10-26 17:30:41 +02:00
commit 81a47832c1
1 changed files with 32 additions and 8 deletions

View File

@ -110,6 +110,30 @@ extension TunnelKitProvider {
/// The way to create a `TunnelKitProvider.Configuration` object for the tunnel profile. /// The way to create a `TunnelKitProvider.Configuration` object for the tunnel profile.
public struct ConfigurationBuilder { public struct ConfigurationBuilder {
/// :nodoc:
public static let defaults = Configuration(
prefersResolvedAddresses: false,
resolvedAddresses: nil,
endpointProtocols: [EndpointProtocol(.udp, 1194)],
mtu: 1250,
sessionConfiguration: SessionProxy.Configuration(
cipher: .aes128cbc,
digest: .sha1,
ca: CryptoContainer(pem: ""),
clientCertificate: nil,
clientKey: nil,
compressionFraming: .disabled,
tlsWrap: nil,
keepAliveInterval: nil,
renegotiatesAfter: nil,
usesPIAPatches: nil
),
shouldDebug: false,
debugLogKey: nil,
debugLogFormat: nil,
lastErrorKey: nil
)
/// Prefers resolved addresses over DNS resolution. `resolvedAddresses` must be set and non-empty. Default is `false`. /// Prefers resolved addresses over DNS resolution. `resolvedAddresses` must be set and non-empty. Default is `false`.
/// ///
/// - Seealso: `fallbackServerAddresses` /// - Seealso: `fallbackServerAddresses`
@ -151,19 +175,19 @@ extension TunnelKitProvider {
- Parameter ca: The CA certificate. - Parameter ca: The CA certificate.
*/ */
public init(sessionConfiguration: SessionProxy.Configuration) { public init(sessionConfiguration: SessionProxy.Configuration) {
prefersResolvedAddresses = false prefersResolvedAddresses = ConfigurationBuilder.defaults.prefersResolvedAddresses
resolvedAddresses = nil resolvedAddresses = nil
endpointProtocols = [EndpointProtocol(.udp, 1194)] endpointProtocols = ConfigurationBuilder.defaults.endpointProtocols
mtu = 1500 mtu = ConfigurationBuilder.defaults.mtu
self.sessionConfiguration = sessionConfiguration self.sessionConfiguration = sessionConfiguration
shouldDebug = false shouldDebug = ConfigurationBuilder.defaults.shouldDebug
debugLogFormat = nil debugLogFormat = ConfigurationBuilder.defaults.debugLogFormat
} }
fileprivate init(providerConfiguration: [String: Any]) throws { fileprivate init(providerConfiguration: [String: Any]) throws {
let S = Configuration.Keys.self let S = Configuration.Keys.self
prefersResolvedAddresses = providerConfiguration[S.prefersResolvedAddresses] as? Bool ?? false prefersResolvedAddresses = providerConfiguration[S.prefersResolvedAddresses] as? Bool ?? ConfigurationBuilder.defaults.prefersResolvedAddresses
resolvedAddresses = providerConfiguration[S.resolvedAddresses] as? [String] resolvedAddresses = providerConfiguration[S.resolvedAddresses] as? [String]
guard let endpointProtocolsStrings = providerConfiguration[S.endpointProtocols] as? [String], !endpointProtocolsStrings.isEmpty else { guard let endpointProtocolsStrings = providerConfiguration[S.endpointProtocols] as? [String], !endpointProtocolsStrings.isEmpty else {
throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.endpointProtocols)] is nil or empty") throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.endpointProtocols)] is nil or empty")
@ -174,7 +198,7 @@ extension TunnelKitProvider {
} }
return ep return ep
} }
mtu = providerConfiguration[S.mtu] as? Int ?? 1250 mtu = providerConfiguration[S.mtu] as? Int ?? ConfigurationBuilder.defaults.mtu
// //
@ -212,7 +236,7 @@ extension TunnelKitProvider {
if let compressionFramingValue = providerConfiguration[S.compressionFraming] as? Int, let compressionFraming = SessionProxy.CompressionFraming(rawValue: compressionFramingValue) { if let compressionFramingValue = providerConfiguration[S.compressionFraming] as? Int, let compressionFraming = SessionProxy.CompressionFraming(rawValue: compressionFramingValue) {
sessionConfigurationBuilder.compressionFraming = compressionFraming sessionConfigurationBuilder.compressionFraming = compressionFraming
} else { } else {
sessionConfigurationBuilder.compressionFraming = .disabled sessionConfigurationBuilder.compressionFraming = ConfigurationBuilder.defaults.sessionConfiguration.compressionFraming
} }
if let tlsWrapData = providerConfiguration[S.tlsWrap] as? Data { if let tlsWrapData = providerConfiguration[S.tlsWrap] as? Data {
do { do {