Skip to content

Commit

Permalink
sdk: add with_database constructor to RelayPool
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 16, 2023
1 parent 73b7d9e commit ce94fcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/nostr-sdk/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ pub struct Relay {
document: Arc<RwLock<RelayInformationDocument>>,
opts: RelayOptions,
stats: RelayConnectionStats,
#[allow(dead_code)]
database: Arc<DynNostrDatabase>,
scheduled_for_stop: Arc<AtomicBool>,
scheduled_for_termination: Arc<AtomicBool>,
Expand Down
13 changes: 9 additions & 4 deletions crates/nostr-sdk/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ impl RelayPoolTask {
}

// Set event as seen by relay
if let Err(e) =
this.database.event_id_seen(event.id, Some(relay_url)).await
if let Err(e) = this
.database
.event_id_seen(event.id, Some(relay_url))
.await
{
tracing::error!(
"Impossible to set event {} as seen by relay: {e}",
Expand Down Expand Up @@ -329,11 +331,14 @@ impl Drop for RelayPool {
impl RelayPool {
/// Create new `RelayPool`
pub fn new(opts: RelayPoolOptions) -> Self {
Self::with_database(opts, Arc::new(MemoryDatabase::new()))
}

/// New with database
pub fn with_database(opts: RelayPoolOptions, database: Arc<DynNostrDatabase>) -> Self {
let (notification_sender, _) = broadcast::channel(opts.notification_channel_size);
let (pool_task_sender, pool_task_receiver) = mpsc::channel(opts.task_channel_size);

let database = Arc::new(MemoryDatabase::new());

let relay_pool_task = RelayPoolTask::new(
database.clone(),
pool_task_receiver,
Expand Down

0 comments on commit ce94fcf

Please sign in to comment.