From 51fc1a71f2acdd9811ede7c854fd7c796aa8d519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Sun, 5 Jul 2020 11:27:53 +0200 Subject: [PATCH 1/2] small fix --- network/src/prios.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/src/prios.rs b/network/src/prios.rs index 2ab4f57f1f..b3a06c4d0b 100644 --- a/network/src/prios.rs +++ b/network/src/prios.rs @@ -208,7 +208,7 @@ impl PrioManager { frames: &mut E, ) -> bool { let to_send = std::cmp::min( - msg.buffer.data.len() as u64 - msg.cursor, + msg.buffer.data[msg.cursor as usize..].len() as u64, Self::FRAME_DATA_SIZE, ); if to_send > 0 { From f544ea59a2673402baf327c607e2e1e1731e2821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Sun, 5 Jul 2020 20:14:47 +0200 Subject: [PATCH 2/2] compress everything --- Cargo.lock | 1 + network/Cargo.toml | 1 + network/src/participant.rs | 6 ++++++ network/src/protocols.rs | 10 ++++++---- network/src/types.rs | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 226c507cf9..5fe17155d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4652,6 +4652,7 @@ dependencies = [ "crossbeam-channel 0.4.2", "futures 0.3.5", "lazy_static", + "lz4-compress", "prometheus", "rand 0.7.3", "serde", diff --git a/network/Cargo.toml b/network/Cargo.toml index 9282a14eba..eac162448b 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] +lz4-compress = "0.1.1" #serialisation bincode = "1.2" serde = { version = "1.0" } diff --git a/network/src/participant.rs b/network/src/participant.rs index b2534253ef..28647b234d 100644 --- a/network/src/participant.rs +++ b/network/src/participant.rs @@ -637,4 +637,10 @@ impl BParticipant { a2b_close_stream_s.clone(), ) } + + /* + async fn close_participant(&self) { + + } + */ } diff --git a/network/src/protocols.rs b/network/src/protocols.rs index 3f20c78cfa..3d918008c0 100644 --- a/network/src/protocols.rs +++ b/network/src/protocols.rs @@ -182,9 +182,10 @@ impl TcpProtocol { bytes[15], ]); let length = u16::from_le_bytes([bytes[16], bytes[17]]); - let mut data = vec![0; length as usize]; + let mut cdata = vec![0; length as usize]; throughput_cache.inc_by(length as i64); - Self::read_except_or_close(cid, &stream, &mut data, w2c_cid_frame_s).await; + Self::read_except_or_close(cid, &stream, &mut cdata, w2c_cid_frame_s).await; + let data = lz4_compress::decompress(&cdata).unwrap(); Frame::Data { mid, start, data } }, FRAME_RAW => { @@ -347,6 +348,7 @@ impl TcpProtocol { }, Frame::Data { mid, start, data } => { throughput_cache.inc_by(data.len() as i64); + let cdata = lz4_compress::compress(&data); Self::write_or_close(&mut stream, &FRAME_DATA.to_be_bytes(), &mut c2w_frame_r) .await || Self::write_or_close(&mut stream, &mid.to_le_bytes(), &mut c2w_frame_r) @@ -355,11 +357,11 @@ impl TcpProtocol { .await || Self::write_or_close( &mut stream, - &(data.len() as u16).to_le_bytes(), + &(cdata.len() as u16).to_le_bytes(), &mut c2w_frame_r, ) .await - || Self::write_or_close(&mut stream, &data, &mut c2w_frame_r).await + || Self::write_or_close(&mut stream, &cdata, &mut c2w_frame_r).await }, Frame::Raw(data) => { Self::write_or_close(&mut stream, &FRAME_RAW.to_be_bytes(), &mut c2w_frame_r) diff --git a/network/src/types.rs b/network/src/types.rs index aeb409ac0c..46205f25ce 100644 --- a/network/src/types.rs +++ b/network/src/types.rs @@ -34,7 +34,7 @@ pub const PROMISES_COMPRESSED: Promises = 8; pub const PROMISES_ENCRYPTED: Promises = 16; pub(crate) const VELOREN_MAGIC_NUMBER: [u8; 7] = [86, 69, 76, 79, 82, 69, 78]; //VELOREN -pub const VELOREN_NETWORK_VERSION: [u32; 3] = [0, 2, 0]; +pub const VELOREN_NETWORK_VERSION: [u32; 3] = [0, 3, 0]; pub(crate) const STREAM_ID_OFFSET1: Sid = Sid::new(0); pub(crate) const STREAM_ID_OFFSET2: Sid = Sid::new(u64::MAX / 2);