<commit_before>//
//  This file is part of Blokada.
//
//  Blokada is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Blokada is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Blokada.  If not, see <https://www.gnu.org/licenses/>.
//
//  Copyright © 2020 Blocka AB. All rights reserved.
//
//  @author <NAME>
//

import Foundation

struct Dns: Codable {
    let ips: [String]
    let port: Int
    let name: String
    let path: String
    let label: String
}


extension Dns: Hashable {
    func hash(into hasher: inout Hasher) {
        hasher.combine(label)
    }
}

extension Dns: Equatable {
    static func == (lhs: Dns, rhs: Dns) -> Bool {
        lhs.label == rhs.label
    }
}

extension Dns {

    func persist() {
        if let dnsString = self.toJson() {
            UserDefaults.standard.set(dnsString, forKey: "dns")
        } else {
            Logger.w("Dns", "Could not convert dns to json")
        }
    }

    static func load() -> Dns {
        let result = UserDefaults.standard.string(forKey: "dns")
        guard let stringData = result else {
            return Dns.defaultDns()
        }

        let jsonData = stringData.data(using: .utf8)
        guard let json = jsonData else {
            Logger.e("Dns", "Failed getting dns json")
            return Dns.defaultDns()
        }

        do {
            return try decoder.decode(Dns.self, from: json)
        } catch {
            Logger.e("Dns", "Failed decoding dns json".cause(error))
            return Dns.defaultDns()
        }
    }

    static var hardcoded = [
        //Dns(ips: ["172.16.17.32", "192.168.127.12", "fc00:e968:6179::de52:7100:0ff", "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b:0ff"], port: 443, name: "dns.adguard.com", path: "dns-query", label: "Adguard"),
        //Dns(ips: ["172.16.31.10", "172.16.31.10", "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "fc00:e968:6179::de52:7100"], port: 443, name: "doh.cleanbrowsing.org", path: "doh/security-filter", label: "CleanBrowsing: Security filter"),
        //Dns(ips: ["172.16.31.10", "172.16.31.10", "fc00:e968:6179::de52:7100", "fdf8:f53e:61e4::18"], port: 443, name: "doh.cleanbrowsing.org", path: "doh/adult-filter", label: "CleanBrowsing: Adult filter"),
        Dns(ips: ["fdf8:f53e:61e4::18", "fc00:db20:35b:7399::5"], port: 443, name: "dns.blokada.org", path: "dns-query", label: "Blokada (IPv6) Beta"),
        Dns(ips: ["1.1.1.1", "1.0.0.1", "fdf8:f53e:61e4::18", "fc00:e968:6179::de52:7100"], port: 443, name: "cloudflare-dns.com", path: "dns-query", label: "Cloudflare"),
        // Turns out those two are not DoH
        //Dns(ips: ["172.16.17.32", "192.168.3.11", "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b", "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b"], port: 443, name: "cloudflare-dns.com", path: "dns-query", label: "Cloudflare: malware blocking"),
        //Dns(ips: ["172.16.17.32", "172.16.17.32", "fc00:db20:35b:7399::5", "fdf8:f53e:61e4::18"], port: 443, name: "cloudflare-dns.com", path: "dns-query", label: "Cloudflare: malware & adult blocking"),
        Dns(ips: ["172.16.58.3", "172.16.31.10", "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "fdf8:f53e:61e4::18"], port: 443, name: "dns.digitale-gesellschaft.ch", path: "dns-query", label: "Digitale Gesellschaft (Switzerland)"),
        Dns(ips: ["8.8.8.8", "8.8.4.4", "fc00:e968:6179::de52:7100", "fc00:e968:6179::de52:7100"], port: 443, name: "dns.google", path: "resolve", label: "Google"),
        Dns(ips: ["172.16.58.3", "fdf8:f53e:61e4::18"], port: 443, name: "ns03.dns.tin-fan.com", path: "dns-query", label: "OpenNIC: USA"),
        Dns(ips: ["172.16.17.32", "fdf8:f53e:61e4::18"], port: 443, name: "ns01.dns.tin-fan.com", path: "dns-query", label: "OpenNIC: Europe")
    ] + (Env.isProduction ? [] : [
        // Debug only entries
        Dns(ips: ["0.0.0.0"], port: 443, name: "localhost", path: "dns-query", label: "Broken DNS (for testing only)")
        ])

    static func defaultDns() -> Dns {
        return hardcoded.first { $0.label == "Cloudflare" }!
    }

}<commit_msg>ios: remove blokada dns for now<commit_after>//
//  This file is part of Blokada.
//
//  Blokada is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Blokada is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Blokada.  If not, see <https://www.gnu.org/licenses/>.
//
//  Copyright © 2020 Blocka AB. All rights reserved.
//
//  @author <NAME>
//

import Foundation

struct Dns: Codable {
    let ips: [String]
    let port: Int
    let name: String
    let path: String
    let label: String
}


extension Dns: Hashable {
    func hash(into hasher: inout Hasher) {
        hasher.combine(label)
    }
}

extension Dns: Equatable {
    static func == (lhs: Dns, rhs: Dns) -> Bool {
        lhs.label == rhs.label
    }
}

extension Dns {

    func persist() {
        if let dnsString = self.toJson() {
            UserDefaults.standard.set(dnsString, forKey: "dns")
        } else {
            Logger.w("Dns", "Could not convert dns to json")
        }
    }

    static func load() -> Dns {
        let result = UserDefaults.standard.string(forKey: "dns")
        guard let stringData = result else {
            return Dns.defaultDns()
        }

        let jsonData = stringData.data(using: .utf8)
        guard let json = jsonData else {
            Logger.e("Dns", "Failed getting dns json")
            return Dns.defaultDns()
        }

        do {
            return try decoder.decode(Dns.self, from: json)
        } catch {
            Logger.e("Dns", "Failed decoding dns json".cause(error))
            return Dns.defaultDns()
        }
    }

    static var hardcoded = [
        //Dns(ips: ["172.16.17.32", "192.168.127.12", "fc00:e968:6179::de52:7100:0ff", "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b:0ff"], port: 443, name: "dns.adguard.com", path: "dns-query", label: "Adguard"),
        //Dns(ips: ["172.16.31.10", "172.16.31.10", "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "fc00:e968:6179::de52:7100"], port: 443, name: "doh.cleanbrowsing.org", path: "doh/security-filter", label: "CleanBrowsing: Security filter"),
        //Dns(ips: ["172.16.31.10", "172.16.31.10", "fc00:e968:6179::de52:7100", "fdf8:f53e:61e4::18"], port: 443, name: "doh.cleanbrowsing.org", path: "doh/adult-filter", label: "CleanBrowsing: Adult filter"),
        Dns(ips: ["1.1.1.1", "1.0.0.1", "fdf8:f53e:61e4::18", "fc00:e968:6179::de52:7100"], port: 443, name: "cloudflare-dns.com", path: "dns-query", label: "Cloudflare"),
        // Turns out those two are not DoH
        //Dns(ips: ["172.16.17.32", "192.168.3.11", "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b", "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b"], port: 443, name: "cloudflare-dns.com", path: "dns-query", label: "Cloudflare: malware blocking"),
        //Dns(ips: ["172.16.17.32", "172.16.17.32", "fc00:db20:35b:7399::5", "fdf8:f53e:61e4::18"], port: 443, name: "cloudflare-dns.com", path: "dns-query", label: "Cloudflare: malware & adult blocking"),
        Dns(ips: ["172.16.58.3", "172.16.31.10", "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "fdf8:f53e:61e4::18"], port: 443, name: "dns.digitale-gesellschaft.ch", path: "dns-query", label: "Digitale Gesellschaft (Switzerland)"),
        Dns(ips: ["8.8.8.8", "8.8.4.4", "fc00:e968:6179::de52:7100", "fc00:e968:6179::de52:7100"], port: 443, name: "dns.google", path: "resolve", label: "Google"),
        Dns(ips: ["172.16.58.3", "fdf8:f53e:61e4::18"], port: 443, name: "ns03.dns.tin-fan.com", path: "dns-query", label: "OpenNIC: USA"),
        Dns(ips: ["172.16.17.32", "fdf8:f53e:61e4::18"], port: 443, name: "ns01.dns.tin-fan.com", path: "dns-query", label: "OpenNIC: Europe")
    ] + (Env.isProduction ? [] : [
        // Debug only entries
        Dns(ips: ["0.0.0.0"], port: 443, name: "localhost", path: "dns-query", label: "Broken DNS (for testing only)")
        ])

    static func defaultDns() -> Dns {
        return hardcoded.first { $0.label == "Cloudflare" }!
    }

}
{'fraction_non_alphanumeric': 0.17829632985953783, 'fraction_numerical': 0.1013819664703217, 'mean_word_length': 3.0425824175824174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 38, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '212767', 'n_tokens_mistral': 3888, 'n_tokens_neox': 3388, 'n_words': 804}