upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/client.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2023-11-01 00:00:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2023-11-01 00:00:00 +0000
commit47a5075b6385a8c0d28bae04c5862d93d0a6ffa6 (patch)
tree9050262be95c06e39c6ae72806dee34865950003 /src/client.rs
parent6c72ccca0371c01c0a50ab162238160fe95e076c (diff)
refactor(client) simply connect flow
connect immediately before requesting or sending events no longer waiting for all relays to connect before interacting with any of them
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/client.rs b/src/client.rs
index 929f19a..84bfb11 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -27,7 +27,7 @@ pub struct Client {
27pub trait Connect { 27pub trait Connect {
28 fn default() -> Self; 28 fn default() -> Self;
29 fn new(opts: Params) -> Self; 29 fn new(opts: Params) -> Self;
30 async fn connect(&self) -> Result<()>; 30 async fn set_keys(&mut self, keys: &nostr::Keys);
31 async fn disconnect(&self) -> Result<()>; 31 async fn disconnect(&self) -> Result<()>;
32 fn get_fallback_relays(&self) -> &Vec<String>; 32 fn get_fallback_relays(&self) -> &Vec<String>;
33 async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>; 33 async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>;
@@ -55,12 +55,9 @@ impl Connect for Client {
55 fallback_relays: opts.fallback_relays, 55 fallback_relays: opts.fallback_relays,
56 } 56 }
57 } 57 }
58 async fn connect(&self) -> Result<()> { 58
59 for relay in &self.fallback_relays { 59 async fn set_keys(&mut self, keys: &nostr::Keys) {
60 self.client.add_relay(relay.as_str(), None).await?; 60 self.client.set_keys(keys).await;
61 }
62 self.client.connect().await;
63 Ok(())
64 } 61 }
65 62
66 async fn disconnect(&self) -> Result<()> { 63 async fn disconnect(&self) -> Result<()> {
@@ -73,6 +70,8 @@ impl Connect for Client {
73 } 70 }
74 71
75 async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> { 72 async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> {
73 self.client.add_relay(url, None).await?;
74 self.client.connect_relay(url).await?;
76 Ok(self.client.send_event_to(url, event).await?) 75 Ok(self.client.send_event_to(url, event).await?)
77 } 76 }
78 77