Optimise and test IP2Country (#1684)

* Move ipv4Int to top level

* Remove redundant fun calls in ipv4ToCountry

* Add null safety to loadFile

* Close streams on failure

* Simplify cacheCountryForIP

* Add IP2CountryTest

* Generate binary

* Simplify ipv4Int

* Fix companion object visibility

* Use array instead of Treemap

* Synchronize OnionApi#paths

* Move csv

* Deduplicate locations csv

* Move ipToCode to gradle

* Use std lib binarySearch

---------

Co-authored-by: bemusementpark <bemusementpark>
This commit is contained in:
Andrew
2024-10-23 13:18:29 +10:30
committed by GitHub
parent 4917548faf
commit 3e17ab2b06
6 changed files with 150 additions and 84 deletions

View File

@@ -44,7 +44,8 @@ object OnionRequestAPI {
var guardSnodes = setOf<Snode>()
var _paths: AtomicReference<List<Path>?> = AtomicReference(null)
var paths: List<Path> // Not a set to ensure we consistently show the same path to the user
var paths: List<Path> // Not a Set to ensure we consistently show the same path to the user
@Synchronized
get() {
val paths = _paths.get()
@@ -57,6 +58,7 @@ object OnionRequestAPI {
_paths.set(result)
return result
}
@Synchronized
set(newValue) {
if (newValue.isEmpty()) {
database.clearOnionRequestPaths()