Skip to content

Commit

Permalink
sdk: add NegentropyOptions::single_reconciliation_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Nov 16, 2023
1 parent 46fcdff commit 2d01303
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/nostr-sdk/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,14 +1558,14 @@ impl Relay {
if opts.syncrounous {
self.get_events_of(
vec![filter],
Duration::from_secs(30),
opts.single_reconciliation_timeout,
FilterOptions::ExitOnEOSE,
)
.await?;
} else {
self.req_events_of(
vec![filter],
Duration::from_secs(30),
opts.single_reconciliation_timeout,
FilterOptions::ExitOnEOSE,
);
}
Expand Down
22 changes: 19 additions & 3 deletions crates/nostr-sdk/src/relay/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,12 @@ impl RelayPoolOptions {
/// Negentropy reconciliation options
#[derive(Debug, Clone, Copy)]
pub struct NegentropyOptions {
/// Timeout for reconciliation (default: 30 secs)
/// Total timeout for reconciliation (default: 60 secs)
pub timeout: Duration,
/// Timeout for **single** reconciliation (default: 30 secs)
///
/// Should be less than total timeout
pub single_reconciliation_timeout: Duration,
/// Syncronous (default: true)
///
/// If `true`, request events and wait that relay send them.
Expand All @@ -263,7 +267,8 @@ pub struct NegentropyOptions {
impl Default for NegentropyOptions {
fn default() -> Self {
Self {
timeout: Duration::from_secs(30),
timeout: Duration::from_secs(60),
single_reconciliation_timeout: Duration::from_secs(30),
syncrounous: true,
bidirectional: false,
}
Expand All @@ -276,12 +281,23 @@ impl NegentropyOptions {
Self::default()
}

/// Timeout for sending event (default: 30 secs)
/// Timeout for sending event (default: 60 secs)
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}

/// Timeout for **single** reconciliation (default: 30 secs)
///
/// Should be less than total timeout
pub fn single_reconciliation_timeout(
mut self,
single_reconciliation_timeout: Duration,
) -> Self {
self.single_reconciliation_timeout = single_reconciliation_timeout;
self
}

/// Syncronous (default: true)
///
/// If `true`, request events and wait that relay send them.
Expand Down

0 comments on commit 2d01303

Please sign in to comment.