-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correcting typo (TransportLater actually sounds nice!) #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,8 @@ pub enum TransportLayerError { | |
IOError(#[from] Arc<IOError>), | ||
#[error("Raknet UDP Error: {0}")] | ||
RaknetUDPError(#[from] RaknetError), | ||
#[error("UDP Error: {0}")] | ||
UDPError(#[from] UdpError), | ||
} | ||
|
||
#[derive(Error, Debug, Clone)] | ||
|
@@ -84,3 +86,11 @@ pub enum RaknetError { | |
#[error("Format Error: {0}")] | ||
FormatError(String), | ||
} | ||
|
||
#[derive(Error, Debug, Clone)] | ||
pub enum UdpError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove udp stuff please |
||
#[error("Error while Receive: {0}")] | ||
RecvError(#[from] RecvError), | ||
#[error("Format Error: {0}")] | ||
FormatError(String), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use std::sync::Arc; | |
|
||
use bedrockrs_core::int::LE; | ||
|
||
use crate::error::{RaknetError, TransportLayerError}; | ||
use crate::error::{RaknetError, TransportLayerError, UdpError}; | ||
use crate::info::RAKNET_GAME_PACKET_ID; | ||
|
||
/// | ||
|
@@ -12,8 +12,8 @@ pub enum TransportLayerConnection { | |
// TODO RaknetTCP(...), | ||
NetherNet(/* TODO */), | ||
// TODO Quic(s2n_quic::connection::Connection), | ||
// TODO Tcp(net::TcpStream), | ||
// TODO Udp(net::UdpSocket) | ||
// Tcp(std::net::TcpStream), | ||
Udp(tokio::net::UdpSocket) //MCBE over UDP :sobb:?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove udp stuff please |
||
} | ||
|
||
impl TransportLayerConnection { | ||
|
@@ -34,6 +34,22 @@ impl TransportLayerConnection { | |
.await | ||
.map_err(|e| TransportLayerError::RaknetUDPError(RaknetError::SendError(e))) | ||
} | ||
TransportLayerConnection::Udp(conn) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove udp stuff please |
||
//BIO | ||
let mut final_stream = vec![]; | ||
|
||
LE::<u8>::write(&LE::new(RAKNET_GAME_PACKET_ID), &mut final_stream) | ||
.map_err(|e| TransportLayerError::IOError(Arc::new(e)))?; | ||
|
||
final_stream | ||
.write_all(stream.get_ref()) | ||
.map_err(|e| TransportLayerError::IOError(Arc::new(e)))?; | ||
|
||
conn.send(final_stream.as_slice()) | ||
.await | ||
.map(|_| ()) | ||
.map_err(|e| TransportLayerError::IOError(Arc::new(e))) //udp send error is std::io::Error | ||
} | ||
_ => { | ||
todo!() | ||
} | ||
|
@@ -70,6 +86,39 @@ impl TransportLayerConnection { | |
.map_err(|e| TransportLayerError::IOError(Arc::new(e)))?) | ||
} | ||
|
||
TransportLayerConnection::Udp(conn) => { | ||
// TODO: Configure the socket for non-blocking (NIO) mode to improve efficiency and responsiveness. | ||
// Non-blocking I/O allows the program to perform other tasks while waiting for I/O operations to complete, | ||
// thereby avoiding potential bottlenecks and enhancing overall performance in high-concurrency scenarios. | ||
let mut recv_buffer: Vec<u8> = vec![0; 4096]; | ||
let _amt = conn | ||
.recv(&mut recv_buffer) | ||
.await | ||
.map(|_| ()) | ||
.map_err(|e| TransportLayerError::IOError(Arc::new(e)))?; | ||
|
||
let mut recv_buffer = Cursor::new(recv_buffer.as_slice()); | ||
|
||
match LE::<u8>::read(&mut recv_buffer) | ||
.map_err(|e| TransportLayerError::IOError(Arc::new(e)))? | ||
.into_inner() | ||
{ | ||
RAKNET_GAME_PACKET_ID => {} | ||
other => { | ||
return Err(TransportLayerError::UDPError( | ||
UdpError::FormatError(format!( | ||
"Expected RakNet Game Packet ID ({:?}), got: {:?}", | ||
RAKNET_GAME_PACKET_ID, other | ||
)), | ||
)); | ||
} | ||
}; | ||
|
||
Ok(stream | ||
.write_all(recv_buffer.into_inner()) | ||
.map_err(|e| TransportLayerError::IOError(Arc::new(e)))?) | ||
} | ||
|
||
_ => { | ||
todo!() | ||
} | ||
|
@@ -81,6 +130,9 @@ impl TransportLayerConnection { | |
TransportLayerConnection::RaknetUDP(conn) => { | ||
conn.close().await; | ||
} | ||
TransportLayerConnection::Udp(socket) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove udp stuff please |
||
std::mem::drop(socket); //for closing the socket explicitly(...do we need it?) | ||
} | ||
_ => { | ||
todo!() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove udp stuff please