Skip to content

Commit

Permalink
sdk: add reconcilie method to RelayPool
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 9, 2023
1 parent 3d6ddba commit 8b94861
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion crates/nostr-sdk/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::time::Duration;

use async_utility::thread;
use nostr::url::Url;
use nostr::{ClientMessage, Event, EventId, Filter, RelayMessage};
use nostr::{ClientMessage, Event, EventId, Filter, RelayMessage, Timestamp};
use thiserror::Error;
use tokio::sync::mpsc::{self, Receiver, Sender};
use tokio::sync::{broadcast, Mutex, RwLock};
Expand Down Expand Up @@ -797,4 +797,31 @@ impl RelayPool {
relay.terminate().await?;
Ok(())
}

/// Negentropy reconciliation
pub async fn reconcilie(
&self,
filter: Filter,
my_items: Vec<(EventId, Timestamp)>,
timeout: Duration,
) -> Result<(), Error> {
let mut handles = Vec::new();
let relays = self.relays().await;
for (url, relay) in relays.into_iter() {
let filter = filter.clone();
let my_items = my_items.clone();
let handle = thread::spawn(async move {
if let Err(e) = relay.reconcilie(filter, my_items, timeout).await {
tracing::error!("Failed to get reconcilie with {url}: {e}");
}
});
handles.push(handle);
}

for handle in handles.into_iter().flatten() {
handle.join().await?;
}

Ok(())
}
}

0 comments on commit 8b94861

Please sign in to comment.