If msg is large, grow the session scratch buffer

This commit is contained in:
Mike Dilger 2024-02-15 11:26:59 +13:00
parent f5f813dcab
commit 0deeb5e0a8

View File

@ -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?;