Skip to content

Commit

Permalink
pool: remove RelayPoolNotification::Stop
Browse files Browse the repository at this point in the history
* Remove all `start` and `stop` methods
* Remove `RelayStatus::Stop`
* Fix shutdown notification sent to external channel on `Relay::terminate` method call

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jun 18, 2024
1 parent b8c93ab commit 0ff5770
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 239 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@
### Fixed

* nostr: fix NIP-47 `list_transactions` response deserialization ([Yuki Kishimoto] and [lnbc1QWFyb24])
* pool: fix shutdown notification sent to external channel on `Relay::terminate` method call ([Yuki Kishimoto])
* js: fix "RuntimeError: memory access out of bounds" WASM error ([Yuki Kishimoto])

### Removed

* pool: remove `RelayPoolNotification::Stop` ([Yuki Kishimoto])
* pool: remove `RelayStatus::Stop` ([Yuki Kishimoto])
* Remove all `start` and `stop` methods ([Yuki Kishimoto])

## [v0.32.0]

### Summary
Expand Down
8 changes: 0 additions & 8 deletions bindings/nostr-sdk-ffi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ impl Client {
.await
}

pub async fn start(&self) {
self.inner.start().await
}

pub async fn stop(&self) -> Result<()> {
Ok(self.inner.stop().await?)
}

pub async fn shutdown(&self) -> Result<()> {
Ok(self.inner.clone().shutdown().await?)
}
Expand Down
15 changes: 0 additions & 15 deletions bindings/nostr-sdk-ffi/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ impl RelayPool {
}
}

/// Start
///
/// Internally call `connect` without wait for connection.
#[inline]
pub async fn start(&self) {
self.inner.start().await
}

/// Stop
///
/// Call `connect` to re-start relays connections
pub async fn stop(&self) -> Result<()> {
Ok(self.inner.stop().await?)
}

/// Completely shutdown pool
pub async fn shutdown(&self) -> Result<()> {
Ok(self.inner.clone().shutdown().await?)
Expand Down
5 changes: 0 additions & 5 deletions bindings/nostr-sdk-ffi/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ impl Relay {
self.inner.connect(connection_timeout).await
}

/// Disconnect from relay and set status to 'Stopped'
pub async fn stop(&self) -> Result<()> {
Ok(self.inner.stop().await?)
}

/// Disconnect from relay and set status to 'Terminated'
pub async fn terminate(&self) -> Result<()> {
Ok(self.inner.terminate().await?)
Expand Down
3 changes: 0 additions & 3 deletions bindings/nostr-sdk-ffi/src/relay/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub enum RelayStatus {
Connected,
/// Relay disconnected, will retry to connect again
Disconnected,
/// Stop
Stopped,
/// Relay completely disconnected
Terminated,
}
Expand All @@ -30,7 +28,6 @@ impl From<nostr_sdk::RelayStatus> for RelayStatus {
nostr_sdk::RelayStatus::Connecting => Self::Connecting,
nostr_sdk::RelayStatus::Connected => Self::Connected,
nostr_sdk::RelayStatus::Disconnected => Self::Disconnected,
nostr_sdk::RelayStatus::Stopped => Self::Stopped,
nostr_sdk::RelayStatus::Terminated => Self::Terminated,
}
}
Expand Down
16 changes: 0 additions & 16 deletions bindings/nostr-sdk-js/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ impl JsRelayPool {
}
}

/// Start
///
/// Internally call `connect` without wait for connection.
#[wasm_bindgen]
pub async fn start(&self) {
self.inner.start().await
}

/// Stop
///
/// Call `connect` or `start` to re-start relays connections
#[wasm_bindgen]
pub async fn stop(&self) -> Result<()> {
self.inner.stop().await.map_err(into_err)
}

/// Completely shutdown pool
#[wasm_bindgen]
pub async fn shutdown(&self) -> Result<()> {
Expand Down
8 changes: 0 additions & 8 deletions bindings/nostr-sdk-js/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ pub enum JsRelayStatus {
Connected,
/// Relay disconnected, will retry to connect again
Disconnected,
/// Stop
Stopped,
/// Relay completely disconnected
Terminated,
}
Expand All @@ -68,7 +66,6 @@ impl From<RelayStatus> for JsRelayStatus {
RelayStatus::Connecting => Self::Connecting,
RelayStatus::Connected => Self::Connected,
RelayStatus::Disconnected => Self::Disconnected,
RelayStatus::Stopped => Self::Stopped,
RelayStatus::Terminated => Self::Terminated,
}
}
Expand Down Expand Up @@ -133,11 +130,6 @@ impl JsRelay {
self.inner.connect(connection_timeout.map(|d| *d)).await
}

/// Disconnect from relay and set status to 'Stopped'
pub async fn stop(&self) -> Result<()> {
self.inner.stop().await.map_err(into_err)
}

/// Disconnect from relay and set status to 'Terminated'
pub async fn terminate(&self) -> Result<()> {
self.inner.terminate().await.map_err(into_err)
Expand Down
11 changes: 0 additions & 11 deletions crates/nostr-relay-pool/src/pool/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ impl InternalRelayPool {
}
}

pub async fn stop(&self) -> Result<(), Error> {
let relays = self.relays().await;
for relay in relays.values() {
relay.stop().await?;
}
if let Err(e) = self.notification_sender.send(RelayPoolNotification::Stop) {
tracing::error!("Impossible to send STOP notification: {e}");
}
Ok(())
}

pub async fn shutdown(&self) -> Result<(), Error> {
// Disconnect all relays
self.disconnect().await?;
Expand Down
21 changes: 1 addition & 20 deletions crates/nostr-relay-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub enum RelayPoolNotification {
/// Relay Status
status: RelayStatus,
},
/// Stop
Stop,
/// Shutdown
Shutdown,
}
Expand Down Expand Up @@ -101,22 +99,6 @@ impl RelayPool {
}
}

/// Start
///
/// Internally call `connect` without wait for connection.
#[inline]
pub async fn start(&self) {
self.inner.connect(None).await
}

/// Stop
///
/// Call `connect` to re-start relays connections
#[inline]
pub async fn stop(&self) -> Result<(), Error> {
self.inner.stop().await
}

/// Completely shutdown pool
#[inline]
pub async fn shutdown(self) -> Result<(), Error> {
Expand Down Expand Up @@ -516,12 +498,11 @@ impl RelayPool {
{
let mut notifications = self.notifications();
while let Ok(notification) = notifications.recv().await {
let stop: bool = RelayPoolNotification::Stop == notification;
let shutdown: bool = RelayPoolNotification::Shutdown == notification;
let exit: bool = func(notification)
.await
.map_err(|e| Error::Handler(e.to_string()))?;
if exit || stop || shutdown {
if exit || shutdown {
break;
}
}
Expand Down
Loading

0 comments on commit 0ff5770

Please sign in to comment.