From fb174b8fe42b9cce1ed5cb2f67eb396f33822318 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Mon, 9 Sep 2024 18:55:26 -0400 Subject: [PATCH] pool: use `READ` and `WRITE` relays for reconciliation Signed-off-by: Yuki Kishimoto --- crates/nostr-relay-pool/src/pool/internal.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/nostr-relay-pool/src/pool/internal.rs b/crates/nostr-relay-pool/src/pool/internal.rs index 6014bc873..c75fdcd41 100644 --- a/crates/nostr-relay-pool/src/pool/internal.rs +++ b/crates/nostr-relay-pool/src/pool/internal.rs @@ -135,10 +135,16 @@ impl InternalRelayPool { .collect() } - /// Method to get **all** relays urls - async fn all_relay_urls(&self) -> Vec { + /// Get relays with `READ` or `WRITE` relays + async fn relay_urls(&self) -> Vec { let relays = self.relays.read().await; - relays.keys().cloned().collect() + self.internal_relays_with_flag( + &relays, + RelayServiceFlags::READ | RelayServiceFlags::WRITE, + FlagCheck::Any, + ) + .map(|(k, ..)| k.clone()) + .collect() } async fn read_relay_urls(&self) -> Vec { @@ -971,7 +977,7 @@ impl InternalRelayPool { filter: Filter, opts: NegentropyOptions, ) -> Result, Error> { - let urls: Vec = self.all_relay_urls().await; + let urls: Vec = self.relay_urls().await; self.reconcile_with(urls, filter, opts).await } @@ -999,7 +1005,7 @@ impl InternalRelayPool { items: Vec<(EventId, Timestamp)>, opts: NegentropyOptions, ) -> Result, Error> { - let urls: Vec = self.all_relay_urls().await; + let urls: Vec = self.relay_urls().await; self.reconcile_advanced(urls, filter, items, opts).await }