Skip to content

Commit

Permalink
pool: handle close WebSocket message
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jan 24, 2025
1 parent d8d3cbb commit 2064313
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
* pool: avoid repeatedly locking the relay channel receiver ([Yuki Kishimoto])
* pool: refactor `RelayPool::stream_events_targeted` ([Yuki Kishimoto])
* pool: refactor relay removal logic and add unit tests ([Yuki Kishimoto])
* pool: handle `close` WebSocket message ([Yuki Kishimoto])
* lmdb: use `EventBorrow` instead of `DatabaseEvent` ([Yuki Kishimoto])
* ndb: refactor note-to-event conversion ([Yuki Kishimoto])
* relay-builder: refactor shutdown mechanism to use `Notify` over `broadcast` ([Yuki Kishimoto])
Expand Down
13 changes: 10 additions & 3 deletions crates/nostr-relay-pool/src/relay/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ impl InnerRelay {

while let Some(msg) = ws_rx.next().await {
match msg? {
WsMessage::Text(json) => self.handle_relay_message(&json).await,
WsMessage::Binary(_) => {
tracing::warn!(url = %self.url, "Binary messages aren't supported.");
}
#[cfg(not(target_arch = "wasm32"))]
WsMessage::Pong(bytes) => {
if self.flags.has_ping() {
Expand Down Expand Up @@ -742,9 +746,12 @@ impl InnerRelay {
}
}
}
WsMessage::Text(json) => self.handle_relay_message(&json).await,
WsMessage::Binary(_) => {
tracing::warn!(url = %self.url, "Binary messages aren't supported.");
#[cfg(not(target_arch = "wasm32"))]
WsMessage::Close(None) => break,
#[cfg(not(target_arch = "wasm32"))]
WsMessage::Close(Some(frame)) => {
tracing::info!(code = %frame.code, reason = %frame.reason, "Connection closed by peer.");
break;
}
#[cfg(not(target_arch = "wasm32"))]
_ => {}
Expand Down

0 comments on commit 2064313

Please sign in to comment.