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:
Taksh 2026-08-17 08:23:44 +05:30
parent 1fc6fda28f
commit 5eb49e4dae

View File

@ -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()
}