Skip to content

Commit

Permalink
sdk: allow to specify relay pool notification channel size in Options
Browse files Browse the repository at this point in the history
Closes #623

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 14, 2024
1 parent daf9f95 commit 112ff48
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* nostr: add NIP73 support ([Yuki Kishimoto])
* nostr: add `NostrSigner::backend` ([Yuki Kishimoto])
* pool: add relay reconnection and disconnection unit tests ([Yuki Kishimoto])
* sdk: allow to specify relay pool notification channel size in `Options` ([Yuki Kishimoto])
* connect: add `NostrConnect::non_secure_set_user_public_key` ([Yuki Kishimoto])
* book: add some examples ([RydalWater])

Expand Down
5 changes: 5 additions & 0 deletions crates/nostr-relay-pool/src/pool/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

//! Constants
pub(super) const MAX_CONNECTING_CHUNK: usize = 100;

/// Relay Pool default notification channel size
pub const DEFAULT_NOTIFICATION_CHANNEL_SIZE: usize = 4096;
2 changes: 1 addition & 1 deletion crates/nostr-relay-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use nostr_database::{DynNostrDatabase, Events, IntoNostrDatabase, MemoryDatabase
use tokio::sync::broadcast;
pub use tokio_stream::wrappers::ReceiverStream;

mod constants;
pub mod constants;
mod error;
mod inner;
pub mod options;
Expand Down
5 changes: 3 additions & 2 deletions crates/nostr-relay-pool/src/pool/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! Pool options
use super::constants::DEFAULT_NOTIFICATION_CHANNEL_SIZE;
use crate::relay::RelayFilteringMode;

/// Relay Pool Options
Expand All @@ -18,7 +19,7 @@ impl Default for RelayPoolOptions {
fn default() -> Self {
Self {
max_relays: None,
notification_channel_size: 4096,
notification_channel_size: DEFAULT_NOTIFICATION_CHANNEL_SIZE,
filtering_mode: RelayFilteringMode::default(),
}
}
Expand All @@ -38,7 +39,7 @@ impl RelayPoolOptions {
self
}

/// Notification channel size (default: 4096)
/// Notification channel size (default: [`DEFAULT_NOTIFICATION_CHANNEL_SIZE`])
#[inline]
pub fn notification_channel_size(mut self, size: usize) -> Self {
self.notification_channel_size = size;
Expand Down
2 changes: 2 additions & 0 deletions crates/nostr-relay-pool/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub use async_utility::futures_util::StreamExt; // Needed for `RelayPool::stream
pub use nostr::prelude::*;
pub use nostr_database::*;

pub use crate::pool::constants::*;
pub use crate::pool::options::*;
// Internal modules
pub use crate::pool::{self, *};
pub use crate::relay::{self, *};
Expand Down
7 changes: 7 additions & 0 deletions crates/nostr-sdk/src/client/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ impl Options {
self.pool = self.pool.filtering_mode(mode);
self
}

/// Notification channel size (default: [`DEFAULT_NOTIFICATION_CHANNEL_SIZE`])
#[inline]
pub fn notification_channel_size(mut self, size: usize) -> Self {
self.pool = self.pool.notification_channel_size(size);
self
}
}

/// Connection target
Expand Down

0 comments on commit 112ff48

Please sign in to comment.