mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
make some internal networking bits public
This commit is contained in:
parent
d36998dc9c
commit
81eeb4fa57
|
@ -95,10 +95,10 @@ async fn handle_connection(shared: SharedNetworkState, stream: TcpStream, remote
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HandshakeData {
|
pub struct HandshakeData {
|
||||||
protocol_version: i32,
|
pub protocol_version: i32,
|
||||||
server_address: String,
|
pub server_address: String,
|
||||||
next_state: HandshakeNextState,
|
pub next_state: HandshakeNextState,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_handshake(
|
async fn handle_handshake(
|
||||||
|
|
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
mod byte_channel;
|
mod byte_channel;
|
||||||
mod connect;
|
mod connect;
|
||||||
|
pub use connect::HandshakeData;
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
mod packet_io;
|
pub mod packet_io;
|
||||||
|
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
|
@ -19,7 +19,7 @@ use valence_core::protocol::{Decode, Encode, Packet};
|
||||||
use crate::byte_channel::{byte_channel, ByteSender, TrySendError};
|
use crate::byte_channel::{byte_channel, ByteSender, TrySendError};
|
||||||
use crate::{CleanupOnDrop, NewClientInfo};
|
use crate::{CleanupOnDrop, NewClientInfo};
|
||||||
|
|
||||||
pub(crate) struct PacketIo {
|
pub struct PacketIo {
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
enc: PacketEncoder,
|
enc: PacketEncoder,
|
||||||
dec: PacketDecoder,
|
dec: PacketDecoder,
|
||||||
|
@ -30,7 +30,7 @@ pub(crate) struct PacketIo {
|
||||||
const READ_BUF_SIZE: usize = 4096;
|
const READ_BUF_SIZE: usize = 4096;
|
||||||
|
|
||||||
impl PacketIo {
|
impl PacketIo {
|
||||||
pub(crate) fn new(
|
pub fn new(
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
enc: PacketEncoder,
|
enc: PacketEncoder,
|
||||||
dec: PacketDecoder,
|
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
|
where
|
||||||
P: Packet + Encode,
|
P: Packet + Encode,
|
||||||
{
|
{
|
||||||
|
@ -58,7 +58,7 @@ impl PacketIo {
|
||||||
Ok(())
|
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
|
where
|
||||||
P: Packet + Decode<'a>,
|
P: Packet + Decode<'a>,
|
||||||
{
|
{
|
||||||
|
@ -86,12 +86,12 @@ impl PacketIo {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[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.enc.set_compression(threshold);
|
||||||
self.dec.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.enc.enable_encryption(key);
|
||||||
self.dec.enable_encryption(key);
|
self.dec.enable_encryption(key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue