From 81eeb4fa57eb54deb5818bdab5938ff3329cabea Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 18 Jun 2023 17:14:25 +1000 Subject: [PATCH] make some internal networking bits public --- crates/valence_network/src/connect.rs | 8 ++++---- crates/valence_network/src/lib.rs | 3 ++- crates/valence_network/src/packet_io.rs | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/valence_network/src/connect.rs b/crates/valence_network/src/connect.rs index 73c6f94..26205f2 100644 --- a/crates/valence_network/src/connect.rs +++ b/crates/valence_network/src/connect.rs @@ -95,10 +95,10 @@ async fn handle_connection(shared: SharedNetworkState, stream: TcpStream, remote } } -struct HandshakeData { - protocol_version: i32, - server_address: String, - next_state: HandshakeNextState, +pub struct HandshakeData { + pub protocol_version: i32, + pub server_address: String, + pub next_state: HandshakeNextState, } async fn handle_handshake( diff --git a/crates/valence_network/src/lib.rs b/crates/valence_network/src/lib.rs index 7378462..5d65b5c 100644 --- a/crates/valence_network/src/lib.rs +++ b/crates/valence_network/src/lib.rs @@ -19,8 +19,9 @@ mod byte_channel; mod connect; +pub use connect::HandshakeData; pub mod packet; -mod packet_io; +pub mod packet_io; use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/crates/valence_network/src/packet_io.rs b/crates/valence_network/src/packet_io.rs index 7cdad58..9c9dbd9 100644 --- a/crates/valence_network/src/packet_io.rs +++ b/crates/valence_network/src/packet_io.rs @@ -19,7 +19,7 @@ use valence_core::protocol::{Decode, Encode, Packet}; use crate::byte_channel::{byte_channel, ByteSender, TrySendError}; use crate::{CleanupOnDrop, NewClientInfo}; -pub(crate) struct PacketIo { +pub struct PacketIo { stream: TcpStream, enc: PacketEncoder, dec: PacketDecoder, @@ -30,7 +30,7 @@ pub(crate) struct PacketIo { const READ_BUF_SIZE: usize = 4096; impl PacketIo { - pub(crate) fn new( + pub fn new( stream: TcpStream, enc: PacketEncoder, dec: PacketDecoder, @@ -48,7 +48,7 @@ impl PacketIo { } } - pub(crate) async fn send_packet

(&mut self, pkt: &P) -> anyhow::Result<()> + pub async fn send_packet

(&mut self, pkt: &P) -> anyhow::Result<()> where P: Packet + Encode, { @@ -58,7 +58,7 @@ impl PacketIo { Ok(()) } - pub(crate) async fn recv_packet<'a, P>(&'a mut self) -> anyhow::Result

+ pub async fn recv_packet<'a, P>(&'a mut self) -> anyhow::Result

where P: Packet + Decode<'a>, { @@ -86,12 +86,12 @@ impl PacketIo { } #[allow(dead_code)] - pub(crate) fn set_compression(&mut self, threshold: Option) { + pub fn set_compression(&mut self, threshold: Option) { self.enc.set_compression(threshold); self.dec.set_compression(threshold); } - pub(crate) fn enable_encryption(&mut self, key: &[u8; 16]) { + pub fn enable_encryption(&mut self, key: &[u8; 16]) { self.enc.enable_encryption(key); self.dec.enable_encryption(key); }