From 5eb49e4dae176e4ea4c83933751315fe2556d1b3 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 17 Aug 2026 08:23:44 +0530 Subject: [PATCH] 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. --- .../main/java/com/bitchat/android/nostr/RelayDirectory.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/nostr/RelayDirectory.kt b/app/src/main/java/com/bitchat/android/nostr/RelayDirectory.kt index 980b95ef..13bafce2 100644 --- a/app/src/main/java/com/bitchat/android/nostr/RelayDirectory.kt +++ b/app/src/main/java/com/bitchat/android/nostr/RelayDirectory.kt @@ -88,10 +88,10 @@ object RelayDirectory { fun closestRelaysForGeohash(geohash: String, nRelays: Int): List { 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() }