From bc3aa9467ae1e2d0ea1727093af9b0af14965e69 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Fri, 7 Oct 2022 20:12:36 -0500 Subject: Replace impl Read with Cursor<&[u8]> (#26) * Start getting rid of Cursor * try to make the tests pass and fail * make the tests pass * remove unused uses * fix clippy warnings * fix potential OOM exploits * fix OOM in az-nbt * fix nbt benchmark * fix a test * start replacing it with Cursor> * wip * fix all the issues * fix all tests * fix nbt benchmark * fix warnings --- azalea-protocol/src/connect.rs | 5 +++++ 1 file changed, 5 insertions(+) mode change 100755 => 100644 azalea-protocol/src/connect.rs (limited to 'azalea-protocol/src/connect.rs') diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs old mode 100755 new mode 100644 index 3fdcecd3..bd55e406 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -9,6 +9,7 @@ use crate::read::{read_packet, ReadPacketError}; use crate::write::write_packet; use crate::ServerIpAddress; use azalea_crypto::{Aes128CfbDec, Aes128CfbEnc}; +use bytes::BytesMut; use std::fmt::Debug; use std::marker::PhantomData; use thiserror::Error; @@ -17,6 +18,7 @@ use tokio::net::TcpStream; pub struct ReadConnection { pub read_stream: OwnedReadHalf, + buffer: BytesMut, pub compression_threshold: Option, pub dec_cipher: Option, _reading: PhantomData, @@ -41,6 +43,7 @@ where pub async fn read(&mut self) -> Result { read_packet::( &mut self.read_stream, + &mut self.buffer, self.compression_threshold, &mut self.dec_cipher, ) @@ -104,6 +107,7 @@ impl Connection { Ok(Connection { reader: ReadConnection { read_stream, + buffer: BytesMut::new(), compression_threshold: None, dec_cipher: None, _reading: PhantomData, @@ -165,6 +169,7 @@ where Connection { reader: ReadConnection { read_stream: connection.reader.read_stream, + buffer: connection.reader.buffer, compression_threshold: connection.reader.compression_threshold, dec_cipher: connection.reader.dec_cipher, _reading: PhantomData, -- cgit v1.2.3