diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-10-07 20:12:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 20:12:36 -0500 |
| commit | bc3aa9467ae1e2d0ea1727093af9b0af14965e69 (patch) | |
| tree | 8db3b735daed484507129eb0683db88ddec14210 /azalea-protocol/src/connect.rs | |
| parent | 695efef66fdf1e08f0cb6d8783c085875100fa2d (diff) | |
| download | azalea-drasl-bc3aa9467ae1e2d0ea1727093af9b0af14965e69.tar.xz | |
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<Vec<u8>>
* wip
* fix all the issues
* fix all tests
* fix nbt benchmark
* fix warnings
Diffstat (limited to 'azalea-protocol/src/connect.rs')
| -rw-r--r--[-rwxr-xr-x] | azalea-protocol/src/connect.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index 3fdcecd3..bd55e406 100755..100644 --- 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<R: ProtocolPacket> { pub read_stream: OwnedReadHalf, + buffer: BytesMut, pub compression_threshold: Option<u32>, pub dec_cipher: Option<Aes128CfbDec>, _reading: PhantomData<R>, @@ -41,6 +43,7 @@ where pub async fn read(&mut self) -> Result<R, ReadPacketError> { read_packet::<R, _>( &mut self.read_stream, + &mut self.buffer, self.compression_threshold, &mut self.dec_cipher, ) @@ -104,6 +107,7 @@ impl Connection<ClientboundHandshakePacket, ServerboundHandshakePacket> { 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, |
