From a1d67c50c8ebc5395b069e30b60d66e0c7de5a5a Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 14 Feb 2024 13:47:11 +0000 Subject: 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 --- src/client.rs | 16 +++++++++++++++- src/sub_commands/init.rs | 12 +----------- src/sub_commands/send.rs | 25 +++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 14 deletions(-) (limited to 'src') 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 { client: nostr_sdk::Client, fallback_relays: Vec, more_fallback_relays: Vec, + blaster_relays: Vec, } #[cfg_attr(test, automock)] @@ -37,6 +38,7 @@ pub trait Connect { async fn disconnect(&self) -> Result<()>; fn get_fallback_relays(&self) -> &Vec; fn get_more_fallback_relays(&self) -> &Vec; + fn get_blaster_relays(&self) -> &Vec; async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result; async fn get_events( &self, @@ -55,7 +57,6 @@ impl Connect for Client { ] } else { vec![ - "wss://purplepages.es".to_string(), "wss://relay.damus.io".to_string(), "wss://nostr-pub.wellorder.net".to_string(), "wss://nos.lol".to_string(), @@ -70,6 +71,7 @@ impl Connect for Client { ] } else { vec![ + "wss://purplepages.es".to_string(), "wss://nostr.wine/".to_string(), "wss://eden.nostr.land/".to_string(), "wss://relay.nostr.band/".to_string(), @@ -77,10 +79,16 @@ impl Connect for Client { ] }; + let blaster_relays: Vec = if std::env::var("NGITTEST").is_ok() { + vec!["ws://localhost:8057".to_string()] + } else { + vec!["wss://nostr.mutinywallet.com".to_string()] + }; Client { client: nostr_sdk::Client::new(&nostr::Keys::generate()), fallback_relays, more_fallback_relays, + blaster_relays, } } fn new(opts: Params) -> Self { @@ -88,6 +96,7 @@ impl Connect for Client { client: nostr_sdk::Client::new(&opts.keys.unwrap_or(nostr::Keys::generate())), fallback_relays: opts.fallback_relays, more_fallback_relays: opts.more_fallback_relays, + blaster_relays: opts.blaster_relays, } } @@ -110,6 +119,10 @@ impl Connect for Client { &self.more_fallback_relays } + fn get_blaster_relays(&self) -> &Vec { + &self.blaster_relays + } + async fn send_event_to(&self, url: &str, event: Event) -> Result { self.client.add_relay(url).await?; self.client.connect_relay(url).await?; @@ -243,6 +256,7 @@ pub struct Params { pub keys: Option, pub fallback_relays: Vec, pub more_fallback_relays: Vec, + pub blaster_relays: Vec, } fn get_dedup_events(relay_results: Vec>>) -> Vec { diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index a95021d..9fdcca5 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -81,7 +81,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let mut maintainers = vec![keys.public_key()]; - let mut repo_relays: Vec = if !args.relays.is_empty() { + let repo_relays: Vec = if !args.relays.is_empty() { args.relays.clone() } else if let Ok(config) = &repo_config_result { config.relays.clone() @@ -92,16 +92,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { user_ref.relays.write() }; - // TODO: add blaster for just repo event and don't add it to repo relays - // TODO: fix the tests to support blaster - if std::env::var("NGITTEST").is_err() - && !repo_relays - .iter() - .any(|s| s.contains("nostr.mutinywallet.com")) - { - repo_relays.push("wss://nostr.mutinywallet.com".to_string()); - } - if let Ok(config) = &repo_config_result { maintainers = extract_pks(config.maintainers.clone())?; } diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 2c1dec8..b8cb271 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -183,7 +183,23 @@ pub async fn send_events( repo_read_relays: Vec, animate: bool, ) -> Result<()> { - let (_, _, _, all) = unique_and_duplicate_all(&my_write_relays, &repo_read_relays); + let (_, _, _, mut all) = unique_and_duplicate_all(&my_write_relays, &repo_read_relays); + + let mut fallback = client.get_fallback_relays().clone(); + + // blast repo events + if events.iter().any(|e| e.kind().as_u64().eq(&REPO_REF_KIND)) { + for r in client.get_blaster_relays() { + fallback.push(r.to_string()); + } + } + + // then remaining fallback list + for r in &fallback { + if !all.iter().any(|r2| r2.eq(&r)) { + all.push(r); + } + } let m = MultiProgress::new(); let pb_style = ProgressStyle::with_template(if animate { @@ -215,7 +231,7 @@ pub async fn send_events( join_all(all.iter().map(|&relay| async { let details = format!( - "{}{} {}", + "{}{}{} {}", if my_write_relays.iter().any(|r| relay.eq(r)) { " [my-relay]" } else { @@ -226,6 +242,11 @@ pub async fn send_events( } else { "" }, + if fallback.iter().any(|r| relay.eq(r)) { + " [default]" + } else { + "" + }, *relay, ); let pb = m.add( -- cgit v1.2.3