mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 09:56:45 +02:00
Fixes auth infinite loop with nostr.wine
This commit is contained in:
@@ -75,6 +75,7 @@ class Relay(
|
|||||||
private var afterEOSEPerSubscription = mutableMapOf<String, Boolean>()
|
private var afterEOSEPerSubscription = mutableMapOf<String, Boolean>()
|
||||||
|
|
||||||
private val authResponse = mutableMapOf<HexKey, Boolean>()
|
private val authResponse = mutableMapOf<HexKey, Boolean>()
|
||||||
|
private val authChallengesSent = mutableSetOf<String>()
|
||||||
private val outboxCache = mutableMapOf<HexKey, EventInterface>()
|
private val outboxCache = mutableMapOf<HexKey, EventInterface>()
|
||||||
|
|
||||||
fun register(listener: Listener) {
|
fun register(listener: Listener) {
|
||||||
@@ -372,6 +373,9 @@ class Relay(
|
|||||||
|
|
||||||
fun resetEOSEStatuses() {
|
fun resetEOSEStatuses() {
|
||||||
afterEOSEPerSubscription = LinkedHashMap(afterEOSEPerSubscription.size)
|
afterEOSEPerSubscription = LinkedHashMap(afterEOSEPerSubscription.size)
|
||||||
|
|
||||||
|
authResponse.clear()
|
||||||
|
authChallengesSent.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendFilter(
|
fun sendFilter(
|
||||||
@@ -492,8 +496,19 @@ class Relay(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sendAuth(signedEvent: RelayAuthEvent) {
|
private fun sendAuth(signedEvent: RelayAuthEvent) {
|
||||||
authResponse.put(signedEvent.id, false)
|
val challenge = signedEvent.challenge() ?: ""
|
||||||
writeToSocket("""["AUTH",${signedEvent.toJson()}]""")
|
|
||||||
|
// only send replies to new challenges to avoid infinite loop:
|
||||||
|
// 1. Auth is sent
|
||||||
|
// 2. auth is rejected
|
||||||
|
// 3. auth is requested
|
||||||
|
// 4. auth is sent
|
||||||
|
// ...
|
||||||
|
if (!authChallengesSent.contains(challenge)) {
|
||||||
|
authResponse.put(signedEvent.id, false)
|
||||||
|
authChallengesSent.add(challenge)
|
||||||
|
writeToSocket("""["AUTH",${signedEvent.toJson()}]""")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendEvent(signedEvent: EventInterface) {
|
private fun sendEvent(signedEvent: EventInterface) {
|
||||||
|
Reference in New Issue
Block a user