From 6e1488530fa7316dde5f16fa76e817b250f56070 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Thu, 5 Oct 2023 10:30:28 +0200 Subject: [PATCH] sdk: skip disconnected relay in `handle_events_of` method --- crates/nostr-sdk/src/relay/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/nostr-sdk/src/relay/mod.rs b/crates/nostr-sdk/src/relay/mod.rs index 64e335e9d..c4842b1c4 100644 --- a/crates/nostr-sdk/src/relay/mod.rs +++ b/crates/nostr-sdk/src/relay/mod.rs @@ -62,6 +62,9 @@ pub enum Error { /// Message not sent #[error("message not sent")] MessageNotSent, + /// Relay not connected + #[error("relay not connected")] + NotConnected, /// Event not published #[error("event not published: {0}")] EventNotPublished(String), @@ -1463,6 +1466,13 @@ impl Relay { where F: Future, { + if !self.is_connected().await + && self.stats.attempts() > 1 + && self.stats.uptime() < MIN_UPTIME + { + return Err(Error::NotConnected); + } + let mut counter = 0; let mut received_eose: bool = false;