make some internal networking bits public

This commit is contained in:
Alex Janka 2023-06-18 17:14:25 +10:00
parent d36998dc9c
commit 81eeb4fa57
3 changed files with 12 additions and 11 deletions

View file

@ -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(

View file

@ -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};

View file

@ -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<P>(&mut self, pkt: &P) -> anyhow::Result<()>
pub async fn send_packet<P>(&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<P>
pub async fn recv_packet<'a, P>(&'a mut self) -> anyhow::Result<P>
where
P: Packet + Decode<'a>,
{
@ -86,12 +86,12 @@ impl PacketIo {
}
#[allow(dead_code)]
pub(crate) fn set_compression(&mut self, threshold: Option<u32>) {
pub fn set_compression(&mut self, threshold: Option<u32>) {
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);
}