Skip to content

Commit

Permalink
pool: set get_or_add_relay as private API
Browse files Browse the repository at this point in the history
Rename `RelayPool::get_or_add_relay` to `RelayPool::__get_or_add_relay`

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
  • Loading branch information
yukibtc committed Dec 8, 2024
1 parent 7edfd67 commit f43f0cc
Showing 3 changed files with 16 additions and 20 deletions.
14 changes: 5 additions & 9 deletions crates/nostr-relay-pool/src/pool/inner.rs
Original file line number Diff line number Diff line change
@@ -224,7 +224,7 @@ impl InnerRelayPool {
}

// Compose new relay
let relay = Relay::internal_custom(url, self.state.clone(), opts);
let relay: Relay = Relay::internal_custom(url, self.state.clone(), opts);

// Set notification sender
relay
@@ -245,17 +245,13 @@ impl InnerRelayPool {
Ok(true)
}

pub async fn get_or_add_relay<U>(
pub async fn get_or_add_relay(
&self,
url: U,
url: RelayUrl,
inherit_pool_subscriptions: bool,
opts: RelayOptions,
) -> Result<Option<Relay>, Error>
where
U: TryIntoUrl + Clone,
Error: From<<U as TryIntoUrl>::Err>,
{
match self.relay(url.clone()).await {
) -> Result<Option<Relay>, Error> {
match self.relay(&url).await {
Ok(relay) => Ok(Some(relay)),
Err(..) => {
self.add_relay(url, inherit_pool_subscriptions, opts)
18 changes: 8 additions & 10 deletions crates/nostr-relay-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
@@ -181,20 +181,18 @@ impl RelayPool {
self.inner.add_relay(url, true, opts).await
}

/// Try to get relay by `url` or add it to pool.
///
/// Return `Some(..)` only if the relay already exists.
// Private API
//
// Try to get relay by `url` or add it to pool.
// Return `Some(..)` only if the relay already exists.
#[inline]
pub async fn get_or_add_relay<U>(
#[doc(hidden)]
pub async fn __get_or_add_relay(
&self,
url: U,
url: RelayUrl,
inherit_pool_subscriptions: bool,
opts: RelayOptions,
) -> Result<Option<Relay>, Error>
where
U: TryIntoUrl + Clone,
Error: From<<U as TryIntoUrl>::Err>,
{
) -> Result<Option<Relay>, Error> {
self.inner
.get_or_add_relay(url, inherit_pool_subscriptions, opts)
.await
4 changes: 3 additions & 1 deletion crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -394,16 +394,18 @@ impl Client {
let opts: RelayOptions = opts.flags(flag);

// Add relay with opts or edit current one
// TODO: remove clone here
match self
.pool
.get_or_add_relay::<&RelayUrl>(&url, inherit_pool_subscriptions, opts)
.__get_or_add_relay(url.clone(), inherit_pool_subscriptions, opts)
.await?
{
Some(relay) => {
relay.flags().add(flag);
Ok(false)
}
None => {
// TODO: move autoconnect to `Relay`?
// Connect if `autoconnect` is enabled
if self.opts.autoconnect {
self.connect_relay::<RelayUrl>(url).await?;

0 comments on commit f43f0cc

Please sign in to comment.