pull/203/head
nielsandriesse 5 years ago
parent 5d01befd1a
commit dc3365b11d

@ -19,15 +19,15 @@ final class IP2Country {
} }
// MARK: Implementation // MARK: Implementation
static func getCountry(_ ip: String) -> String { func getCountry(_ ip: String) -> String {
var truncatedIP = ip var truncatedIP = ip
func getCountryInternal() -> String { func getCountryInternal() -> String {
if let country = countryNamesCache[ip] { return country } if let country = IP2Country.countryNamesCache[ip] { return country }
if let ipv4TableIndex = ipv4Table.namedColumns["network"]!.firstIndex(where: { $0.starts(with: truncatedIP) }) { if let ipv4TableIndex = IP2Country.ipv4Table.namedColumns["network"]!.firstIndex(where: { $0.starts(with: truncatedIP) }) {
let countryID = ipv4Table.namedColumns["registered_country_geoname_id"]![ipv4TableIndex] let countryID = IP2Country.ipv4Table.namedColumns["registered_country_geoname_id"]![ipv4TableIndex]
if let countryNamesTableIndex = countryNamesTable.namedColumns["geoname_id"]!.firstIndex(of: countryID) { if let countryNamesTableIndex = IP2Country.countryNamesTable.namedColumns["geoname_id"]!.firstIndex(of: countryID) {
let country = countryNamesTable.namedColumns["country_name"]![countryNamesTableIndex] let country = IP2Country.countryNamesTable.namedColumns["country_name"]![countryNamesTableIndex]
countryNamesCache[ip] = country IP2Country.countryNamesCache[ip] = country
return country return country
} }
} }
@ -53,7 +53,7 @@ final class IP2Country {
guard OnionRequestAPI.paths.count >= OnionRequestAPI.pathCount else { return } guard OnionRequestAPI.paths.count >= OnionRequestAPI.pathCount else { return }
let pathToDisplay = OnionRequestAPI.paths.first! let pathToDisplay = OnionRequestAPI.paths.first!
pathToDisplay.forEach { snode in 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.") print("[Loki] Finished preloading onion request path countries.")
} }

@ -155,7 +155,7 @@ final class PathVC : BaseVC {
} }
private func getPathRow(snode: LokiAPITarget, location: LineView.Location, dotAnimationStartDelay: Double, dotAnimationRepeatInterval: Double, isGuardSnode: Bool) -> UIStackView { 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: "") let title = isGuardSnode ? NSLocalizedString("Guard Node", comment: "") : NSLocalizedString("Service Node", comment: "")
return getPathRow(title: title, subtitle: country, location: location, dotAnimationStartDelay: dotAnimationStartDelay, dotAnimationRepeatInterval: dotAnimationRepeatInterval) return getPathRow(title: title, subtitle: country, location: location, dotAnimationStartDelay: dotAnimationStartDelay, dotAnimationRepeatInterval: dotAnimationRepeatInterval)
} }

Loading…
Cancel
Save