normalize relay URL

This commit is contained in:
callebtc
2025-08-23 22:54:32 +02:00
parent df94c930d7
commit 67176490a1
3 changed files with 18 additions and 4 deletions
@@ -902,12 +902,15 @@ class NostrGeohashService(
since = System.currentTimeMillis() - 86400000L // Last 24 hours
)
nostrRelayManager.subscribe(
nostrRelayManager.subscribeForGeohash(
geohash = channel.channel.geohash,
filter = dmFilter,
id = dmSubId,
handler = { giftWrap ->
handleGeohashDmEvent(giftWrap, channel.channel.geohash, dmIdentity)
}
},
includeDefaults = true,
nRelays = 5
)
Log.i(TAG, "✅ Subscribed to geohash DMs for identity: ${dmIdentity.publicKeyHex.take(16)}...")
@@ -648,7 +648,12 @@ class NostrRelayManager private constructor() {
val wasProcessed = eventDeduplicator.processEvent(response.event) { event ->
// Only log non-gift-wrap events to reduce noise
if (event.kind != NostrKind.GIFT_WRAP) {
Log.v(TAG, "📥 Processing new Nostr event (kind: ${event.kind}) from relay: $relayUrl")
val originGeo = activeSubscriptions[response.subscriptionId]?.originGeohash
if (originGeo != null) {
Log.v(TAG, "📥 Processing event (kind=${event.kind}) from relay=$relayUrl geo=$originGeo sub=${response.subscriptionId}")
} else {
Log.v(TAG, "📥 Processing event (kind=${event.kind}) from relay=$relayUrl sub=${response.subscriptionId}")
}
}
// Call handler for new events only
@@ -43,7 +43,7 @@ object RelayDirectory {
if (trimmed.lowercase().startsWith("relay url")) continue
val parts = trimmed.split(",")
if (parts.size < 3) continue
val url = parts[0].trim()
val url = normalizeRelayUrl(parts[0].trim())
val lat = parts[1].trim().toDoubleOrNull()
val lon = parts[2].trim().toDoubleOrNull()
if (url.isEmpty() || lat == null || lon == null) continue
@@ -89,6 +89,12 @@ object RelayDirectory {
val c = 2 * atan2(sqrt(a), sqrt(1 - a))
return R * c
}
private fun normalizeRelayUrl(raw: String): String {
val trimmed = raw.trim()
if (trimmed.isEmpty()) return trimmed
return if ("://" in trimmed) trimmed else "wss://$trimmed"
}
}