diff --git a/crates/nostr-sdk/src/relay/mod.rs b/crates/nostr-sdk/src/relay/mod.rs index 77938568f..2a10ab80c 100644 --- a/crates/nostr-sdk/src/relay/mod.rs +++ b/crates/nostr-sdk/src/relay/mod.rs @@ -146,6 +146,15 @@ impl fmt::Display for RelayStatus { } } +/// Relay Connection Type +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum RelayConnectionType { + /// Manual: realy added manually + Manual, + /// Gossip: relay added by gossip + Gossip, +} + /// Relay event #[derive(Debug)] pub enum RelayEvent { @@ -252,6 +261,7 @@ pub struct Relay { #[cfg(not(target_arch = "wasm32"))] proxy: Option, status: Arc>, + connection_type: RelayConnectionType, #[cfg(feature = "nip11")] document: Arc>, opts: RelayOptions, @@ -278,6 +288,7 @@ impl Relay { #[cfg(not(target_arch = "wasm32"))] pub fn new( url: Url, + connection_type: RelayConnectionType, pool_sender: Sender, notification_sender: broadcast::Sender, proxy: Option, @@ -290,6 +301,7 @@ impl Relay { url, proxy, status: Arc::new(RwLock::new(RelayStatus::Initialized)), + connection_type, #[cfg(feature = "nip11")] document: Arc::new(RwLock::new(RelayInformationDocument::new())), opts, @@ -310,6 +322,7 @@ impl Relay { #[cfg(target_arch = "wasm32")] pub fn new( url: Url, + connection_type: RelayConnectionType, pool_sender: Sender, notification_sender: broadcast::Sender, opts: RelayOptions, @@ -320,6 +333,7 @@ impl Relay { Self { url, status: Arc::new(RwLock::new(RelayStatus::Initialized)), + connection_type, #[cfg(feature = "nip11")] document: Arc::new(RwLock::new(RelayInformationDocument::new())), opts, @@ -353,6 +367,11 @@ impl Relay { *status } + /// Relay Connection Type + pub fn connection_type(&self) -> RelayConnectionType { + self.connection_type + } + /// Get [`RelayStatus`] #[cfg(feature = "blocking")] pub fn status_blocking(&self) -> RelayStatus { diff --git a/crates/nostr-sdk/src/relay/pool.rs b/crates/nostr-sdk/src/relay/pool.rs index ff520578d..abf3969a7 100644 --- a/crates/nostr-sdk/src/relay/pool.rs +++ b/crates/nostr-sdk/src/relay/pool.rs @@ -22,8 +22,8 @@ use tokio::sync::{broadcast, Mutex, RwLock}; use super::options::RelayPoolOptions; use super::{ - Error as RelayError, FilterOptions, InternalSubscriptionId, Limits, Relay, RelayOptions, - RelaySendOptions, RelayStatus, + Error as RelayError, FilterOptions, InternalSubscriptionId, Limits, Relay, RelayConnectionType, + RelayOptions, RelaySendOptions, RelayStatus, }; use crate::util::TryIntoUrl; @@ -448,6 +448,7 @@ impl RelayPool { if !relays.contains_key(&url) { let relay = Relay::new( url, + RelayConnectionType::Manual, self.pool_task_sender.clone(), self.notification_sender.clone(), proxy, @@ -473,6 +474,7 @@ impl RelayPool { if !relays.contains_key(&url) { let relay = Relay::new( url, + RelayConnectionType::Manual, self.pool_task_sender.clone(), self.notification_sender.clone(), opts,