diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-05-19 13:17:10 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-05-27 14:36:59 +0200 |
| commit | eaef79cc2bcb041c986513bdaa1e58f3db53f130 (patch) | |
| tree | 29096957e7527bb272b6be8306fbf755f9ec8013 | |
| parent | 23ba82a76b74c2ca11c7b67e40b0c200601ec987 (diff) | |
| download | mullvadvpn-eaef79cc2bcb041c986513bdaa1e58f3db53f130.tar.xz mullvadvpn-eaef79cc2bcb041c986513bdaa1e58f3db53f130.zip | |
Add DNSSettings
| -rw-r--r-- | ios/MullvadVPN/TunnelSettings.swift | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/ios/MullvadVPN/TunnelSettings.swift b/ios/MullvadVPN/TunnelSettings.swift index 750538dd95..a572424f29 100644 --- a/ios/MullvadVPN/TunnelSettings.swift +++ b/ios/MullvadVPN/TunnelSettings.swift @@ -11,15 +11,53 @@ import Network import NetworkExtension import WireGuardKit -/// A struct that holds a tun interface configuration +/// A struct that holds a tun interface configuration. struct InterfaceSettings: Codable { - var privateKey = PrivateKeyWithMetadata() - var addresses = [IPAddressRange]() + var privateKey: PrivateKeyWithMetadata + var addresses: [IPAddressRange] + var dnsSettings: DNSSettings + + private enum CodingKeys: String, CodingKey { + case privateKey, addresses, dnsSettings + } + + init(privateKey: PrivateKeyWithMetadata = PrivateKeyWithMetadata(), addresses: [IPAddressRange] = [], dnsSettings: DNSSettings = DNSSettings()) { + self.privateKey = privateKey + self.addresses = addresses + self.dnsSettings = dnsSettings + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + privateKey = try container.decode(PrivateKeyWithMetadata.self, forKey: .privateKey) + addresses = try container.decode([IPAddressRange].self, forKey: .addresses) + + // Provide default value, since `dnsSettings` key does not exist in <= 2021.2 + dnsSettings = try container.decodeIfPresent(DNSSettings.self, forKey: .dnsSettings) + ?? DNSSettings() + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(privateKey, forKey: .privateKey) + try container.encode(addresses, forKey: .addresses) + try container.encode(dnsSettings, forKey: .dnsSettings) + } } -/// A struct that holds the configuration passed via NETunnelProviderProtocol +/// A struct that holds the configuration passed via `NETunnelProviderProtocol`. struct TunnelSettings: Codable { var relayConstraints = RelayConstraints() var interface = InterfaceSettings() } +/// A struct that holds DNS settings. +struct DNSSettings: Codable { + /// Block advertising. + var blockAdvertising: Bool = false + + /// Block tracking. + var blockTracking: Bool = false +} |
