From 4f774ae3c54168662a31580d26b2cff8c68e793b Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 14 Jan 2025 16:58:16 -0500 Subject: [PATCH] Simple refactoring to avoid empty challenges. --- .../quartz/nip01Core/relays/SimpleClientRelay.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/SimpleClientRelay.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/SimpleClientRelay.kt index 50d395390..12c2477dd 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/SimpleClientRelay.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/SimpleClientRelay.kt @@ -247,7 +247,7 @@ class SimpleClientRelay( // if this is the OK of an auth event, renew all subscriptions and resend all outgoing events. if (authResponseWatcher.containsKey(msg.eventId)) { - val wasAlreadyAuthenticated = authResponseWatcher.get(msg.eventId) + val wasAlreadyAuthenticated = authResponseWatcher[msg.eventId] authResponseWatcher.put(msg.eventId, msg.success) if (wasAlreadyAuthenticated != true && msg.success) { sendEverything() @@ -375,15 +375,10 @@ class SimpleClientRelay( } fun sendAuth(signedEvent: RelayAuthEvent) { - val challenge = signedEvent.challenge() ?: "" + val challenge = signedEvent.challenge() // 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)) { + if (challenge != null && challenge !in authChallengesSent) { authResponseWatcher[signedEvent.id] = false authChallengesSent.add(challenge) writeToSocket(AuthCmd.toJson(signedEvent))