feat: fix prudp stuff(almost there)
This commit is contained in:
parent
ac21581957
commit
803a98aa0b
5 changed files with 88 additions and 27 deletions
39
src/main.rs
39
src/main.rs
|
|
@ -16,7 +16,7 @@ use crate::prudp::router::Router;
|
||||||
use crate::prudp::sockaddr::PRUDPSockAddr;
|
use crate::prudp::sockaddr::PRUDPSockAddr;
|
||||||
use crate::prudp::socket::Unsecure;
|
use crate::prudp::socket::Unsecure;
|
||||||
use chrono::{Local, SecondsFormat};
|
use chrono::{Local, SecondsFormat};
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use simplelog::{
|
use simplelog::{
|
||||||
ColorChoice, CombinedLogger, Config, LevelFilter, TermLogger, TerminalMode, WriteLogger,
|
ColorChoice, CombinedLogger, Config, LevelFilter, TermLogger, TerminalMode, WriteLogger,
|
||||||
|
|
@ -68,7 +68,7 @@ static SECURE_SERVER_PORT: Lazy<u16> = Lazy::new(|| {
|
||||||
env::var("SECURE_SERVER_PORT")
|
env::var("SECURE_SERVER_PORT")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|s| s.parse().ok())
|
.and_then(|s| s.parse().ok())
|
||||||
.unwrap_or(10002)
|
.unwrap_or(10001)
|
||||||
});
|
});
|
||||||
|
|
||||||
static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
|
static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
|
||||||
|
|
@ -258,11 +258,6 @@ async fn start_secure_server() -> SecureServer{
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
define_rmc_proto!(
|
|
||||||
proto AuthClientProtocol{
|
|
||||||
Auth
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
impl Auth for AuthClient{
|
impl Auth for AuthClient{
|
||||||
async fn login(&self, name: String) -> Result<(), ErrorCode> {
|
async fn login(&self, name: String) -> Result<(), ErrorCode> {
|
||||||
|
|
@ -287,7 +282,16 @@ impl Auth for AuthClient{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rmc_struct(AuthClientProtocol)]
|
#[rmc_struct(AuthClientProtocol)]
|
||||||
struct AuthClient {}
|
struct AuthClient {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
define_rmc_proto!(
|
||||||
|
proto AuthClientProtocol{
|
||||||
|
Auth
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
async fn start_servers() {
|
async fn start_servers() {
|
||||||
|
|
||||||
|
|
@ -298,18 +302,29 @@ async fn start_servers() {
|
||||||
|
|
||||||
let auth_sockaddr = PRUDPSockAddr::new(auth_ip, auth_port);
|
let auth_sockaddr = PRUDPSockAddr::new(auth_ip, auth_port);
|
||||||
|
|
||||||
let (router_secure, _) = Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *SECURE_SERVER_PORT))
|
let (router_secure, _) = Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *AUTH_SERVER_PORT))
|
||||||
.await
|
.await
|
||||||
.expect("unable to start router");
|
.expect("unable to start router");
|
||||||
|
|
||||||
let mut socket_secure = router_secure
|
let mut socket_secure = router_secure
|
||||||
.add_socket(VirtualPort::new(1, 10), Unsecure("CD&ML"))
|
.add_socket(VirtualPort::new(1, 10), Unsecure("6f599f81"))
|
||||||
.await
|
.await
|
||||||
.expect("unable to add socket");
|
.expect("unable to add socket");
|
||||||
|
|
||||||
let conn = socket_secure.connect(auth_sockaddr).await.unwrap();
|
// let conn = socket_secure.connect(auth_sockaddr).await.unwrap();
|
||||||
|
|
||||||
let obj = new_rmc_gateway_connection(conn, OnlyRemote::<RemoteAuthClientProtocol>::new);
|
|
||||||
|
loop {
|
||||||
|
let Some(conn) = socket_secure.accept().await else {
|
||||||
|
error!("server crashed");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
info!("new connected user!");
|
||||||
|
|
||||||
|
let _ = new_rmc_gateway_connection(conn, |_| AuthClient {}); //OnlyRemote::<RemoteAuthClientProtocol>::new
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,8 @@ impl Router {
|
||||||
|
|
||||||
let connection = packet.source_sockaddr(addr);
|
let connection = packet.source_sockaddr(addr);
|
||||||
|
|
||||||
|
println!("data from {:?}", connection);
|
||||||
|
|
||||||
let endpoints = self.endpoints.read().await;
|
let endpoints = self.endpoints.read().await;
|
||||||
|
|
||||||
let Some(endpoint) = endpoints[packet.header.destination_port.get_port_number() as usize].as_ref() else {
|
let Some(endpoint) = endpoints[packet.header.destination_port.get_port_number() as usize].as_ref() else {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ impl PRUDPSockAddr{
|
||||||
let mut hmac = Md5Hmac::new_from_slice(&[0; 16]).expect("fuck");
|
let mut hmac = Md5Hmac::new_from_slice(&[0; 16]).expect("fuck");
|
||||||
|
|
||||||
let mut data = self.regular_socket_addr.ip().octets().to_vec();
|
let mut data = self.regular_socket_addr.ip().octets().to_vec();
|
||||||
data.extend_from_slice(&self.regular_socket_addr.port().to_be_bytes());
|
//data.extend_from_slice(&self.regular_socket_addr.port().to_be_bytes());
|
||||||
|
|
||||||
hmac.write_all(&data).expect("figuring this out was complete ass");
|
hmac.write_all(&data).expect("figuring this out was complete ass");
|
||||||
let result: [u8; 16] = hmac.finalize().into_bytes()[0..16].try_into().expect("fuck");
|
let result: [u8; 16] = hmac.finalize().into_bytes()[0..16].try_into().expect("fuck");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::prudp::packet::flags::{ACK, HAS_SIZE, MULTI_ACK, NEED_ACK, RELIABLE};
|
use crate::prudp::packet::flags::{ACK, HAS_SIZE, MULTI_ACK, NEED_ACK, RELIABLE};
|
||||||
use crate::prudp::packet::types::{CONNECT, DATA, DISCONNECT, PING, SYN};
|
use crate::prudp::packet::types::{CONNECT, DATA, DISCONNECT, PING, SYN};
|
||||||
use crate::prudp::packet::PacketOption::{ConnectionSignature, FragmentId, MaximumSubstreamId, SupportedFunctions};
|
use crate::prudp::packet::PacketOption::{ConnectionSignature, FragmentId, InitialSequenceId, MaximumSubstreamId, SupportedFunctions};
|
||||||
use crate::prudp::packet::{PRUDPHeader, PRUDPPacket, PacketOption, TypesFlags, VirtualPort};
|
use crate::prudp::packet::{PRUDPHeader, PRUDPPacket, PacketOption, TypesFlags, VirtualPort};
|
||||||
use crate::prudp::router::{Error, Router};
|
use crate::prudp::router::{Error, Router};
|
||||||
use crate::prudp::sockaddr::PRUDPSockAddr;
|
use crate::prudp::sockaddr::PRUDPSockAddr;
|
||||||
|
|
@ -670,7 +670,7 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
||||||
.write_to(&mut vec)
|
.write_to(&mut vec)
|
||||||
.expect("somehow failed to convert backet to bytes");
|
.expect("somehow failed to convert backet to bytes");
|
||||||
|
|
||||||
println!("{}", hex::encode(&vec));
|
println!("sent out: {}", hex::encode(&vec));
|
||||||
|
|
||||||
self.socket
|
self.socket
|
||||||
.send_to(&vec, dest.regular_socket_addr)
|
.send_to(&vec, dest.regular_socket_addr)
|
||||||
|
|
@ -681,7 +681,11 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
||||||
async fn handle_syn(&self, address: PRUDPSockAddr, packet: PRUDPPacket) {
|
async fn handle_syn(&self, address: PRUDPSockAddr, packet: PRUDPPacket) {
|
||||||
info!("got syn");
|
info!("got syn");
|
||||||
|
|
||||||
let mut response = packet.base_acknowledgement_packet();
|
let mut response = packet.base_response_packet();
|
||||||
|
|
||||||
|
response.header.types_and_flags.set_types(SYN);
|
||||||
|
response.header.types_and_flags.set_flag(ACK);
|
||||||
|
response.header.types_and_flags.set_flag(HAS_SIZE);
|
||||||
|
|
||||||
let signature = address.calculate_connection_signature();
|
let signature = address.calculate_connection_signature();
|
||||||
|
|
||||||
|
|
@ -700,10 +704,12 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.header.types_and_flags.set_flag(HAS_SIZE | ACK);
|
response.set_sizes();
|
||||||
|
|
||||||
self.crypto_handler.sign_pre_handshake(&mut response);
|
self.crypto_handler.sign_pre_handshake(&mut response);
|
||||||
|
|
||||||
|
//println!("got syn: {:?}", response);
|
||||||
|
|
||||||
self.send_packet_unbuffered(address, response)
|
self.send_packet_unbuffered(address, response)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
@ -822,16 +828,45 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
||||||
remote_signature,
|
remote_signature,
|
||||||
*own_signature,
|
*own_signature,
|
||||||
&packet.payload,
|
&packet.payload,
|
||||||
*max_substream,
|
1 + *max_substream,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut response = packet.base_acknowledgement_packet();
|
let mut response = packet.base_response_packet();
|
||||||
response.header.types_and_flags.set_flag(HAS_SIZE | ACK);
|
response.header.types_and_flags.set_types(CONNECT);
|
||||||
|
response.header.types_and_flags.set_flag(ACK);
|
||||||
|
response.header.types_and_flags.set_flag(HAS_SIZE);
|
||||||
|
|
||||||
response.header.session_id = session_id;
|
response.header.session_id = session_id;
|
||||||
|
response.header.sequence_id = 1;
|
||||||
|
|
||||||
response.payload = return_data;
|
response.payload = return_data;
|
||||||
|
|
||||||
|
|
||||||
|
//let remote_signature = address.calculate_connection_signature();
|
||||||
|
|
||||||
|
response
|
||||||
|
.options
|
||||||
|
.push(ConnectionSignature(Default::default()));
|
||||||
|
|
||||||
|
for option in &packet.options {
|
||||||
|
match option {
|
||||||
|
MaximumSubstreamId(max_substream) => response
|
||||||
|
.options
|
||||||
|
.push(MaximumSubstreamId(*max_substream)),
|
||||||
|
SupportedFunctions(funcs) => {
|
||||||
|
response.options.push(SupportedFunctions(*funcs))
|
||||||
|
}
|
||||||
|
_ => { /* ? */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
response.set_sizes();
|
||||||
|
|
||||||
crypto.sign_connect(&mut response);
|
crypto.sign_connect(&mut response);
|
||||||
|
|
||||||
|
//println!("connect out: {:?}", response);
|
||||||
|
|
||||||
self.create_connection(crypto, address, session_id).await;
|
self.create_connection(crypto, address, session_id).await;
|
||||||
|
|
||||||
self.send_packet_unbuffered(address, response).await;
|
self.send_packet_unbuffered(address, response).await;
|
||||||
|
|
@ -926,6 +961,15 @@ impl<T: CryptoHandler> AnyInternalSocket for InternalSocket<T> {
|
||||||
info!("got ack");
|
info!("got ack");
|
||||||
if packet.header.types_and_flags.get_types() == SYN ||
|
if packet.header.types_and_flags.get_types() == SYN ||
|
||||||
packet.header.types_and_flags.get_types() == CONNECT{
|
packet.header.types_and_flags.get_types() == CONNECT{
|
||||||
|
|
||||||
|
if packet.header.types_and_flags.get_types() == SYN{
|
||||||
|
println!("Syn: {:?}", packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
if packet.header.types_and_flags.get_types() == CONNECT{
|
||||||
|
println!("Connect: {:?}", packet);
|
||||||
|
}
|
||||||
|
|
||||||
let sender = self.connection_establishment_data_sender.lock().await;
|
let sender = self.connection_establishment_data_sender.lock().await;
|
||||||
info!("redirecting ack to active connection establishment code");
|
info!("redirecting ack to active connection establishment code");
|
||||||
|
|
||||||
|
|
@ -976,7 +1020,7 @@ impl<T: CryptoHandler> AnyInternalSocket for InternalSocket<T> {
|
||||||
},
|
},
|
||||||
options: vec![
|
options: vec![
|
||||||
SupportedFunctions(0x104),
|
SupportedFunctions(0x104),
|
||||||
MaximumSubstreamId(1),
|
MaximumSubstreamId(0),
|
||||||
ConnectionSignature(remote_signature)
|
ConnectionSignature(remote_signature)
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
@ -1011,7 +1055,7 @@ impl<T: CryptoHandler> AnyInternalSocket for InternalSocket<T> {
|
||||||
},
|
},
|
||||||
options: vec![
|
options: vec![
|
||||||
SupportedFunctions(0x04),
|
SupportedFunctions(0x04),
|
||||||
MaximumSubstreamId(1),
|
MaximumSubstreamId(0),
|
||||||
ConnectionSignature(remote_signature)
|
ConnectionSignature(remote_signature)
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -132,14 +132,14 @@ impl RemoteObject for () {
|
||||||
|
|
||||||
pub trait RmcCallable {
|
pub trait RmcCallable {
|
||||||
//type Remote: RemoteObject;
|
//type Remote: RemoteObject;
|
||||||
async fn rmc_call(
|
fn rmc_call(
|
||||||
&self,
|
&self,
|
||||||
responder: &SendingConnection,
|
responder: &SendingConnection,
|
||||||
protocol_id: u16,
|
protocol_id: u16,
|
||||||
method_id: u32,
|
method_id: u32,
|
||||||
call_id: u32,
|
call_id: u32,
|
||||||
rest: Vec<u8>,
|
rest: Vec<u8>,
|
||||||
);
|
) -> impl std::future::Future<Output = ()> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
@ -215,8 +215,8 @@ impl<T: RemoteInstantiatable> OnlyRemote<T>{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RemoteInstantiatable> RmcCallable for OnlyRemote<T>{
|
impl<T: RemoteInstantiatable> RmcCallable for OnlyRemote<T>{
|
||||||
async fn rmc_call(&self, responder: &SendingConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>) {
|
fn rmc_call(&self, responder: &SendingConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>) -> impl std::future::Future<Output = ()> + Send {
|
||||||
|
async{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ async fn handle_incoming<T: RmcCallable + Send + Sync + 'static>(
|
||||||
let sending_conn = connection.duplicate_sender();
|
let sending_conn = connection.duplicate_sender();
|
||||||
|
|
||||||
while let Some(v) = connection.recv().await{
|
while let Some(v) = connection.recv().await{
|
||||||
let Some(proto_id) = v.get(5) else {
|
let Some(proto_id) = v.get(4) else {
|
||||||
error!("received too small rmc message.");
|
error!("received too small rmc message.");
|
||||||
error!("ending rmc gateway.");
|
error!("ending rmc gateway.");
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue