diff --git a/src/client.rs b/src/client.rs index dfe1c43..08ea686 100644 --- a/src/client.rs +++ b/src/client.rs @@ -83,6 +83,7 @@ pub async fn negotiate_files_up( let files = file_handles.iter().map(|fh| fh.to_file_info()).collect(); let msg = EncryptedMessage::FileNegotiationMessage(FileNegotiationPayload { files }); let server_msg = msg.to_encrypted_message(cipher)?; + println!("server_msg encrypted: {:?}", server_msg); stream.send(server_msg).await?; let reply_payload = match stream.next().await { Some(Ok(msg)) => match msg { diff --git a/src/conf.rs b/src/conf.rs index 07a6f99..b4db236 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1 +1 @@ -pub const BUFFER_SIZE: usize = 1024 * 1024; +pub const BUFFER_SIZE: usize = 1024 * 1024 * 10; diff --git a/src/crypto.rs b/src/crypto.rs index 482d37e..1b555db 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -4,7 +4,6 @@ use aes_gcm::aead::{Aead, NewAead}; use aes_gcm::{Aes256Gcm, Key, Nonce}; // Or `Aes128Gcm` use anyhow::{anyhow, Result}; use bytes::{Bytes, BytesMut}; -use futures::prelude::*; use rand::{thread_rng, Rng}; use spake2::{Ed25519Group, Identity, Password, Spake2}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; @@ -24,11 +23,7 @@ pub async fn handshake( handshake_msg.extend_from_slice(&outbound_msg); let handshake_msg = handshake_msg.freeze(); println!("client - handshake msg, {:?}", handshake_msg); - // println!( - // "len id: {:?}. len msg: {:?}", - // id.len(), - // Bytes::from(outbound_msg).len() - // ); + println!("id: {:?}. msg: {:?}", id.clone(), outbound_msg.clone()); socket.write_all(&handshake_msg).await?; let mut buffer = [0; 33]; let n = socket.read_exact(&mut buffer).await?; @@ -39,7 +34,7 @@ pub async fn handshake( Ok(key_bytes) => key_bytes, Err(e) => return Err(anyhow!(e.to_string())), }; - // println!("Handshake successful. Key is {:?}", key); + println!("Handshake successful. Key is {:?}", key); return Ok((socket, new_cipher(&key))); } diff --git a/src/server.rs b/src/server.rs index 0d7f8c0..102d0f4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,7 +1,7 @@ +use crate::conf::BUFFER_SIZE; use anyhow::{anyhow, Result}; use bytes::{Bytes, BytesMut}; use std::collections::HashMap; -use std::io; use std::net::SocketAddr; use std::sync::Arc; use tokio::io::{AsyncReadExt, AsyncWriteExt}; @@ -123,19 +123,22 @@ pub async fn handle_connection( }; println!("Client upgraded"); // The handshake cache should be empty for {id} at this point. - let mut client_buffer = BytesMut::with_capacity(1024); + let mut client_buffer = BytesMut::with_capacity(BUFFER_SIZE); loop { tokio::select! { Some(msg) = client.rx.recv() => { + // println!("piping bytes= {:?}", msg); client.socket.write_all(&msg[..]).await? } - result = client.socket.read(&mut client_buffer) => match result { + result = client.socket.read_buf(&mut client_buffer) => match result { Ok(0) => { - break + break; }, Ok(n) => { - println!("reading more"); - client.peer_tx.send(BytesMut::from(&client_buffer[0..n]).freeze())? + let b = BytesMut::from(&client_buffer[0..n]).freeze(); + // println!("reading more = {:?}", b); + client_buffer.clear(); + client.peer_tx.send(b)? }, Err(e) => { println!("Error {:?}", e);