diff --git a/Signal/src/Loki/Utilities/IP2Country.swift b/Signal/src/Loki/Utilities/IP2Country.swift index 853e2cdc1..64c4f6399 100644 --- a/Signal/src/Loki/Utilities/IP2Country.swift +++ b/Signal/src/Loki/Utilities/IP2Country.swift @@ -19,15 +19,15 @@ final class IP2Country { } // MARK: Implementation - static func getCountry(_ ip: String) -> String { + func getCountry(_ ip: String) -> String { var truncatedIP = ip func getCountryInternal() -> String { - if let country = countryNamesCache[ip] { return country } - if let ipv4TableIndex = ipv4Table.namedColumns["network"]!.firstIndex(where: { $0.starts(with: truncatedIP) }) { - let countryID = ipv4Table.namedColumns["registered_country_geoname_id"]![ipv4TableIndex] - if let countryNamesTableIndex = countryNamesTable.namedColumns["geoname_id"]!.firstIndex(of: countryID) { - let country = countryNamesTable.namedColumns["country_name"]![countryNamesTableIndex] - countryNamesCache[ip] = country + if let country = IP2Country.countryNamesCache[ip] { return country } + if let ipv4TableIndex = IP2Country.ipv4Table.namedColumns["network"]!.firstIndex(where: { $0.starts(with: truncatedIP) }) { + let countryID = IP2Country.ipv4Table.namedColumns["registered_country_geoname_id"]![ipv4TableIndex] + if let countryNamesTableIndex = IP2Country.countryNamesTable.namedColumns["geoname_id"]!.firstIndex(of: countryID) { + let country = IP2Country.countryNamesTable.namedColumns["country_name"]![countryNamesTableIndex] + IP2Country.countryNamesCache[ip] = country return country } } @@ -53,7 +53,7 @@ final class IP2Country { guard OnionRequestAPI.paths.count >= OnionRequestAPI.pathCount else { return } let pathToDisplay = OnionRequestAPI.paths.first! pathToDisplay.forEach { snode in - let _ = IP2Country.getCountry(snode.ip) // Preload if needed + let _ = self.getCountry(snode.ip) // Preload if needed } print("[Loki] Finished preloading onion request path countries.") } diff --git a/Signal/src/Loki/View Controllers/PathVC.swift b/Signal/src/Loki/View Controllers/PathVC.swift index 601c8a9d0..ae5e20a96 100644 --- a/Signal/src/Loki/View Controllers/PathVC.swift +++ b/Signal/src/Loki/View Controllers/PathVC.swift @@ -155,7 +155,7 @@ final class PathVC : BaseVC { } private func getPathRow(snode: LokiAPITarget, location: LineView.Location, dotAnimationStartDelay: Double, dotAnimationRepeatInterval: Double, isGuardSnode: Bool) -> UIStackView { - let country = IP2Country.getCountry(snode.ip) + let country = IP2Country.shared.getCountry(snode.ip) let title = isGuardSnode ? NSLocalizedString("Guard Node", comment: "") : NSLocalizedString("Service Node", comment: "") return getPathRow(title: title, subtitle: country, location: location, dotAnimationStartDelay: dotAnimationStartDelay, dotAnimationRepeatInterval: dotAnimationRepeatInterval) }