commit 6692abf5557486b57cb3d1d14cc5a03aef107aa8
parent 4fd62d94029b12e9f7610b4100c10a347a4067c5
Author: kernelkind <kernelkind@gmail.com>
Date: Sun, 1 Feb 2026 20:43:00 -0500
refactor(websocket): move `WebsocketRelay` -> websocket.rs
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
3 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/crates/enostr/src/relay/mod.rs b/crates/enostr/src/relay/mod.rs
@@ -4,7 +4,7 @@ pub mod pool;
pub mod subs_debug;
mod websocket;
-pub use websocket::WebsocketConn;
+pub use websocket::{WebsocketConn, WebsocketRelay};
#[derive(Debug, Copy, Clone)]
pub enum RelayStatus {
diff --git a/crates/enostr/src/relay/pool.rs b/crates/enostr/src/relay/pool.rs
@@ -1,5 +1,5 @@
use crate::relay::multicast::{setup_multicast_relay, MulticastRelay};
-use crate::relay::{RelayStatus, WebsocketConn};
+use crate::relay::{RelayStatus, WebsocketConn, WebsocketRelay};
use crate::{ClientMessage, Error, Result};
use nostrdb::Filter;
@@ -38,13 +38,6 @@ pub enum PoolRelay {
Multicast(MulticastRelay),
}
-pub struct WebsocketRelay {
- pub relay: WebsocketConn,
- pub last_ping: Instant,
- pub last_connect_attempt: Instant,
- pub retry_connect_after: Duration,
-}
-
impl PoolRelay {
pub fn url(&self) -> &str {
match self {
@@ -106,21 +99,6 @@ impl PoolRelay {
}
}
-impl WebsocketRelay {
- pub fn new(relay: WebsocketConn) -> Self {
- Self {
- relay,
- last_ping: Instant::now(),
- last_connect_attempt: Instant::now(),
- retry_connect_after: Self::initial_reconnect_duration(),
- }
- }
-
- pub fn initial_reconnect_duration() -> Duration {
- Duration::from_secs(5)
- }
-}
-
pub struct RelayPool {
pub relays: Vec<PoolRelay>,
pub ping_rate: Duration,
diff --git a/crates/enostr/src/relay/websocket.rs b/crates/enostr/src/relay/websocket.rs
@@ -3,6 +3,7 @@ use crate::{relay::RelayStatus, ClientMessage, Result};
use std::{
fmt,
hash::{Hash, Hasher},
+ time::{Duration, Instant},
};
use ewebsock::{Options, WsMessage, WsReceiver, WsSender};
@@ -83,3 +84,25 @@ impl WebsocketConn {
self.sender.send(msg);
}
}
+
+pub struct WebsocketRelay {
+ pub relay: WebsocketConn,
+ pub last_ping: Instant,
+ pub last_connect_attempt: Instant,
+ pub retry_connect_after: Duration,
+}
+
+impl WebsocketRelay {
+ pub fn new(relay: WebsocketConn) -> Self {
+ Self {
+ relay,
+ last_ping: Instant::now(),
+ last_connect_attempt: Instant::now(),
+ retry_connect_after: Self::initial_reconnect_duration(),
+ }
+ }
+
+ pub fn initial_reconnect_duration() -> Duration {
+ Duration::from_secs(5)
+ }
+}