Skip to content

Commit

Permalink
pool: use READ and WRITE relays for reconciliation
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Sep 10, 2024
1 parent d8ad15b commit 2a9fa47
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/nostr-relay-pool/src/pool/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,16 @@ impl InternalRelayPool {
.collect()
}

/// Method to get **all** relays urls
async fn all_relay_urls(&self) -> Vec<Url> {
/// Get relays with `READ` or `WRITE` relays
async fn relay_urls(&self) -> Vec<Url> {
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<Url> {
Expand Down Expand Up @@ -971,7 +977,7 @@ impl InternalRelayPool {
filter: Filter,
opts: NegentropyOptions,
) -> Result<Output<Reconciliation>, Error> {
let urls: Vec<Url> = self.all_relay_urls().await;
let urls: Vec<Url> = self.relay_urls().await;
self.reconcile_with(urls, filter, opts).await
}

Expand Down Expand Up @@ -999,7 +1005,7 @@ impl InternalRelayPool {
items: Vec<(EventId, Timestamp)>,
opts: NegentropyOptions,
) -> Result<Output<Reconciliation>, Error> {
let urls: Vec<Url> = self.all_relay_urls().await;
let urls: Vec<Url> = self.relay_urls().await;
self.reconcile_advanced(urls, filter, items, opts).await
}

Expand Down

0 comments on commit 2a9fa47

Please sign in to comment.