From 0deeb5e0a8719b39acb44c64ab426e30276ae601 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Thu, 15 Feb 2024 11:26:59 +1300 Subject: [PATCH] If msg is large, grow the session scratch buffer --- src/nostr.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/nostr.rs b/src/nostr.rs index 5ff31de..b6e060c 100644 --- a/src/nostr.rs +++ b/src/nostr.rs @@ -6,6 +6,13 @@ use hyper_tungstenite::tungstenite::Message; impl WebSocketService { pub async fn handle_nostr_message(&mut self, msg: String) -> Result<(), Error> { + // If the msg is large, grow the session buffer + // (it will be freed when they disconnect) + if msg.len() > 4096 { + let newlen = 4096 * ((msg.len() / 4096) + 1); + self.buffer.resize(newlen, 0); + } + log::warn!("Received unhandled text message: {}", msg); let reply = NostrReply::Notice("NIP-01 is not yet fully supported".to_owned()); self.websocket.send(Message::text(reply.as_json())).await?;