From 6b81cec83aeba9eb61d930c3cb014b27975f62c5 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Fri, 18 Jun 2021 20:02:48 +0200 Subject: [PATCH] Decrease max message size to 16MB --- Cargo.lock | 4 ++-- src/constants.rs | 3 ++- src/frontend/index.js | 6 +++--- src/session_manager.rs | 8 ++++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92837e6..6ca633e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,9 +403,9 @@ dependencies = [ [[package]] name = "async-psec" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aa693cf79f81392aeffa439d2aae418d8d04816e86c0032a3e80e8b5df0b743" +checksum = "589ceb2d0c6d841e27084dac8599b84436b9024dc047f71963c7460c31f1e8f5" dependencies = [ "aes-gcm", "async-trait", diff --git a/src/constants.rs b/src/constants.rs index d79ffe3..4a00f4a 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -4,4 +4,5 @@ pub const APPLICATION_FOLDER: &str = "AIRA"; pub const DB_NAME: &str = "AIRA.db"; pub const HTTP_COOKIE_NAME: &str = "aira_auth"; pub const MSG_LOADING_COUNT: usize = 20; -pub const FILE_CHUNK_SIZE: usize = 1023996; \ No newline at end of file +pub const FILE_CHUNK_SIZE: usize = 1_023_996; +pub const MAX_RECV_SIZE: usize = 16_383_996; \ No newline at end of file diff --git a/src/frontend/index.js b/src/frontend/index.js index 37a4354..07c4b71 100644 --- a/src/frontend/index.js +++ b/src/frontend/index.js @@ -174,7 +174,7 @@ document.getElementById("attach_file").onchange = function(event) { let files = event.target.files; let useLargeFileTransfer = false; for (let i=0; i 32760000) { + if (files[i].size > 16380000) { useLargeFileTransfer = true; break; } @@ -215,7 +215,7 @@ document.getElementById("attach_file").onchange = function(event) { formData.append("", files[i]); fetch("/send_file", {method: "POST", body: formData}).then(response => { if (response.ok) { - response.text().then(uuid => onFileSent(currentSessionId, new Date.now(), uuid, files[i].name)); + response.text().then(uuid => onFileSent(currentSessionId, new Date(), uuid, files[i].name)); } else { console.log(response); } @@ -1193,4 +1193,4 @@ function displayHistory(scrollToBottom = true) { socket.send("load_msgs "+currentSessionId); } } -} \ No newline at end of file +} diff --git a/src/session_manager.rs b/src/session_manager.rs index 1d30103..3fb3c6f 100644 --- a/src/session_manager.rs +++ b/src/session_manager.rs @@ -100,7 +100,10 @@ impl SessionManager { } } if !msg_saved { - self.saved_msgs.write().unwrap().get_mut(&session_id).unwrap().push(message); + //can be None if session disconnected + if let Some(saved_msgs) = self.saved_msgs.write().unwrap().get_mut(&session_id) { + saved_msgs.push(message) + } } } @@ -412,7 +415,7 @@ impl SessionManager { } } Err(e) => { - if e != PsecError::BrokenPipe && e != PsecError::ConnectionReset && e != PsecError::BufferTooLarge { + if e != PsecError::BrokenPipe && e != PsecError::ConnectionReset { print_error!(e); } break; @@ -468,6 +471,7 @@ impl SessionManager { fn handle_new_session(session_manager: Arc, mut session: Session, outgoing: bool) { tokio::spawn(async move { let mut peer_public_key = [0; PUBLIC_KEY_LENGTH]; + session.set_max_recv_size(constants::MAX_RECV_SIZE, false); let session = { let identity = { session_manager.identity.read().unwrap().clone()