diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-14 13:47:11 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-14 13:47:11 +0000 |
| commit | a1d67c50c8ebc5395b069e30b60d66e0c7de5a5a (patch) | |
| tree | 0895e4cfab98e7c7bbf45ddbac2e7af2c51935e6 /src/client.rs | |
| parent | fed60687b2438b6bd19ee8f5c854ddc53cad0c9b (diff) | |
feat: send to default relays, blast repo event
improve the distribution of events by sending to default relays
in addition to user and repo relays. for better discoverability of
repo events, this is also blasted.
a temporary fix to blast everything was removed.
the less reliable purplepages.es relay is moved to
more_fallback_relays that currently isn't used
Diffstat (limited to 'src/client.rs')
| -rw-r--r-- | src/client.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs index 97cb856..9bc171a 100644 --- a/src/client.rs +++ b/src/client.rs | |||
| @@ -26,6 +26,7 @@ pub struct Client { | |||
| 26 | client: nostr_sdk::Client, | 26 | client: nostr_sdk::Client, |
| 27 | fallback_relays: Vec<String>, | 27 | fallback_relays: Vec<String>, |
| 28 | more_fallback_relays: Vec<String>, | 28 | more_fallback_relays: Vec<String>, |
| 29 | blaster_relays: Vec<String>, | ||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | #[cfg_attr(test, automock)] | 32 | #[cfg_attr(test, automock)] |
| @@ -37,6 +38,7 @@ pub trait Connect { | |||
| 37 | async fn disconnect(&self) -> Result<()>; | 38 | async fn disconnect(&self) -> Result<()>; |
| 38 | fn get_fallback_relays(&self) -> &Vec<String>; | 39 | fn get_fallback_relays(&self) -> &Vec<String>; |
| 39 | fn get_more_fallback_relays(&self) -> &Vec<String>; | 40 | fn get_more_fallback_relays(&self) -> &Vec<String>; |
| 41 | fn get_blaster_relays(&self) -> &Vec<String>; | ||
| 40 | async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>; | 42 | async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>; |
| 41 | async fn get_events( | 43 | async fn get_events( |
| 42 | &self, | 44 | &self, |
| @@ -55,7 +57,6 @@ impl Connect for Client { | |||
| 55 | ] | 57 | ] |
| 56 | } else { | 58 | } else { |
| 57 | vec![ | 59 | vec![ |
| 58 | "wss://purplepages.es".to_string(), | ||
| 59 | "wss://relay.damus.io".to_string(), | 60 | "wss://relay.damus.io".to_string(), |
| 60 | "wss://nostr-pub.wellorder.net".to_string(), | 61 | "wss://nostr-pub.wellorder.net".to_string(), |
| 61 | "wss://nos.lol".to_string(), | 62 | "wss://nos.lol".to_string(), |
| @@ -70,6 +71,7 @@ impl Connect for Client { | |||
| 70 | ] | 71 | ] |
| 71 | } else { | 72 | } else { |
| 72 | vec![ | 73 | vec![ |
| 74 | "wss://purplepages.es".to_string(), | ||
| 73 | "wss://nostr.wine/".to_string(), | 75 | "wss://nostr.wine/".to_string(), |
| 74 | "wss://eden.nostr.land/".to_string(), | 76 | "wss://eden.nostr.land/".to_string(), |
| 75 | "wss://relay.nostr.band/".to_string(), | 77 | "wss://relay.nostr.band/".to_string(), |
| @@ -77,10 +79,16 @@ impl Connect for Client { | |||
| 77 | ] | 79 | ] |
| 78 | }; | 80 | }; |
| 79 | 81 | ||
| 82 | let blaster_relays: Vec<String> = if std::env::var("NGITTEST").is_ok() { | ||
| 83 | vec!["ws://localhost:8057".to_string()] | ||
| 84 | } else { | ||
| 85 | vec!["wss://nostr.mutinywallet.com".to_string()] | ||
| 86 | }; | ||
| 80 | Client { | 87 | Client { |
| 81 | client: nostr_sdk::Client::new(&nostr::Keys::generate()), | 88 | client: nostr_sdk::Client::new(&nostr::Keys::generate()), |
| 82 | fallback_relays, | 89 | fallback_relays, |
| 83 | more_fallback_relays, | 90 | more_fallback_relays, |
| 91 | blaster_relays, | ||
| 84 | } | 92 | } |
| 85 | } | 93 | } |
| 86 | fn new(opts: Params) -> Self { | 94 | fn new(opts: Params) -> Self { |
| @@ -88,6 +96,7 @@ impl Connect for Client { | |||
| 88 | client: nostr_sdk::Client::new(&opts.keys.unwrap_or(nostr::Keys::generate())), | 96 | client: nostr_sdk::Client::new(&opts.keys.unwrap_or(nostr::Keys::generate())), |
| 89 | fallback_relays: opts.fallback_relays, | 97 | fallback_relays: opts.fallback_relays, |
| 90 | more_fallback_relays: opts.more_fallback_relays, | 98 | more_fallback_relays: opts.more_fallback_relays, |
| 99 | blaster_relays: opts.blaster_relays, | ||
| 91 | } | 100 | } |
| 92 | } | 101 | } |
| 93 | 102 | ||
| @@ -110,6 +119,10 @@ impl Connect for Client { | |||
| 110 | &self.more_fallback_relays | 119 | &self.more_fallback_relays |
| 111 | } | 120 | } |
| 112 | 121 | ||
| 122 | fn get_blaster_relays(&self) -> &Vec<String> { | ||
| 123 | &self.blaster_relays | ||
| 124 | } | ||
| 125 | |||
| 113 | async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> { | 126 | async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> { |
| 114 | self.client.add_relay(url).await?; | 127 | self.client.add_relay(url).await?; |
| 115 | self.client.connect_relay(url).await?; | 128 | self.client.connect_relay(url).await?; |
| @@ -243,6 +256,7 @@ pub struct Params { | |||
| 243 | pub keys: Option<nostr::Keys>, | 256 | pub keys: Option<nostr::Keys>, |
| 244 | pub fallback_relays: Vec<String>, | 257 | pub fallback_relays: Vec<String>, |
| 245 | pub more_fallback_relays: Vec<String>, | 258 | pub more_fallback_relays: Vec<String>, |
| 259 | pub blaster_relays: Vec<String>, | ||
| 246 | } | 260 | } |
| 247 | 261 | ||
| 248 | fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> { | 262 | fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> { |