Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/nostr-relay-pool/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

-->

## Unreleased

### Breaking changes

- Change `Relay::send_msg` and `Relay::batch_msg` signatures (https://github.com/rust-nostr/nostr/pull/1124)
- Change `RelayPool::send_msg_to` and `RelayPool::batch_msg_to` signatures (https://github.com/rust-nostr/nostr/pull/1124)

## v0.44.0 - 2025/11/06

### Breaking changes
Expand Down
23 changes: 18 additions & 5 deletions crates/nostr-relay-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use self::options::RelayPoolOptions;
pub use self::output::Output;
use crate::monitor::Monitor;
use crate::relay::flags::FlagCheck;
use crate::relay::options::{RelayOptions, ReqExitPolicy, SyncOptions};
use crate::relay::options::{RelayOptions, ReqExitPolicy, SendMessageOptions, SyncOptions};
use crate::relay::Relay;
use crate::shared::SharedState;
use crate::stream::{BoxedStream, ReceiverStream};
Expand Down Expand Up @@ -653,13 +653,14 @@ impl RelayPool {
&self,
urls: I,
msg: ClientMessage<'_>,
opts: SendMessageOptions,
) -> Result<Output<()>, Error>
where
I: IntoIterator<Item = U>,
U: TryIntoUrl,
Error: From<<U as TryIntoUrl>::Err>,
{
self.batch_msg_to(urls, vec![msg]).await
self.batch_msg_to(urls, &[msg], opts).await
}

/// Send multiple client messages at once to specific relays
Expand All @@ -668,7 +669,8 @@ impl RelayPool {
pub async fn batch_msg_to<I, U>(
&self,
urls: I,
msgs: Vec<ClientMessage<'_>>,
msgs: &[ClientMessage<'_>],
opts: SendMessageOptions,
) -> Result<Output<()>, Error>
where
I: IntoIterator<Item = U>,
Expand Down Expand Up @@ -705,12 +707,23 @@ impl RelayPool {
}
}

let mut urls: Vec<RelayUrl> = Vec::with_capacity(set.len());
let mut futures = Vec::with_capacity(set.len());
let mut output: Output<()> = Output::default();

// Batch messages and construct outputs
// Compose futures
for url in set.into_iter() {
let relay: &Relay = self.internal_relay(&relays, &url)?;
match relay.batch_msg(msgs.clone()) {
urls.push(url);
futures.push(relay.batch_msg(msgs, opts));
}

// Join futures
let list = future::join_all(futures).await;

// Iter results and construct output
for (url, result) in urls.into_iter().zip(list.into_iter()) {
match result {
Ok(..) => {
// Success, insert relay url in 'success' set result
output.success.insert(url);
Expand Down
1 change: 1 addition & 0 deletions crates/nostr-relay-pool/src/relay/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use core::time::Duration;

pub(super) const WAIT_FOR_OK_TIMEOUT: Duration = Duration::from_secs(10);
pub(super) const WAIT_FOR_AUTHENTICATION_TIMEOUT: Duration = Duration::from_secs(7);
pub(super) const WAIT_FOR_MSG_SEND_CONFIRMATION_TIMEOUT: Duration = Duration::from_secs(10);
pub(super) const DEFAULT_CONNECTION_TIMEOUT: Duration = Duration::from_secs(60);

/// Relay default notification channel size
Expand Down
3 changes: 3 additions & 0 deletions crates/nostr-relay-pool/src/relay/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum Error {
Negentropy(negentropy::Error),
/// Database error
Database(DatabaseError),
/// Can't receive send confirmation
CantReceiveSendConfirmation,
/// Generic timeout
Timeout,
/// Not replied to ping
Expand Down Expand Up @@ -139,6 +141,7 @@ impl fmt::Display for Error {
Self::Hex(e) => e.fmt(f),
Self::Negentropy(e) => e.fmt(f),
Self::Database(e) => e.fmt(f),
Self::CantReceiveSendConfirmation => f.write_str("can't receive send confirmation"),
Self::Timeout => f.write_str("timeout"),
Self::NotRepliedToPing => f.write_str("not replied to ping"),
Self::CantParsePong => f.write_str("can't parse pong"),
Expand Down
Loading
Loading