mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-10-25 07:40:36 +00:00
fix(nostr): do not pick relays around (0, 0) for an undecodable geohash
closestRelaysForGeohash wraps the decode in a try/catch and returns an empty list on failure, but decodeToCenter never throws: it hands back (0, 0), so an empty or malformed geohash quietly selects the relays nearest the Gulf of Guinea and connects to them. Use the nullable decoder, so the empty-list path the code already intended is the one that runs.
This commit is contained in:
parent
1fc6fda28f
commit
5eb49e4dae
@ -88,10 +88,10 @@ object RelayDirectory {
|
||||
fun closestRelaysForGeohash(geohash: String, nRelays: Int): List<String> {
|
||||
val snapshot = synchronized(relaysLock) { relays.toList() }
|
||||
if (snapshot.isEmpty()) return emptyList()
|
||||
val center = try {
|
||||
val c = com.bitchat.android.geohash.Geohash.decodeToCenter(geohash)
|
||||
c
|
||||
} catch (e: Exception) {
|
||||
// An empty or malformed geohash decodes to (0, 0), which would pick the
|
||||
// relays closest to the Gulf of Guinea rather than declining to choose.
|
||||
val center = com.bitchat.android.geohash.Geohash.decodeToCenterOrNull(geohash)
|
||||
if (center == null) {
|
||||
Log.e(TAG, "Failed to decode geohash")
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user