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::socket::Unsecure;
|
||||
use chrono::{Local, SecondsFormat};
|
||||
use log::info;
|
||||
use log::{error, info};
|
||||
use once_cell::sync::Lazy;
|
||||
use simplelog::{
|
||||
ColorChoice, CombinedLogger, Config, LevelFilter, TermLogger, TerminalMode, WriteLogger,
|
||||
|
|
@ -68,7 +68,7 @@ static SECURE_SERVER_PORT: Lazy<u16> = Lazy::new(|| {
|
|||
env::var("SECURE_SERVER_PORT")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(10002)
|
||||
.unwrap_or(10001)
|
||||
});
|
||||
|
||||
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{
|
||||
async fn login(&self, name: String) -> Result<(), ErrorCode> {
|
||||
|
|
@ -287,7 +282,16 @@ impl Auth for AuthClient{
|
|||
}
|
||||
|
||||
#[rmc_struct(AuthClientProtocol)]
|
||||
struct AuthClient {}
|
||||
struct AuthClient {
|
||||
|
||||
}
|
||||
|
||||
define_rmc_proto!(
|
||||
proto AuthClientProtocol{
|
||||
Auth
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
async fn start_servers() {
|
||||
|
||||
|
|
@ -298,18 +302,29 @@ async fn start_servers() {
|
|||
|
||||
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
|
||||
.expect("unable to start router");
|
||||
|
||||
let mut socket_secure = router_secure
|
||||
.add_socket(VirtualPort::new(1, 10), Unsecure("CD&ML"))
|
||||
.add_socket(VirtualPort::new(1, 10), Unsecure("6f599f81"))
|
||||
.await
|
||||
.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);
|
||||
|
||||
println!("data from {:?}", connection);
|
||||
|
||||
let endpoints = self.endpoints.read().await;
|
||||
|
||||
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 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");
|
||||
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::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::router::{Error, Router};
|
||||
use crate::prudp::sockaddr::PRUDPSockAddr;
|
||||
|
|
@ -670,7 +670,7 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
|||
.write_to(&mut vec)
|
||||
.expect("somehow failed to convert backet to bytes");
|
||||
|
||||
println!("{}", hex::encode(&vec));
|
||||
println!("sent out: {}", hex::encode(&vec));
|
||||
|
||||
self.socket
|
||||
.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) {
|
||||
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();
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
//println!("got syn: {:?}", response);
|
||||
|
||||
self.send_packet_unbuffered(address, response)
|
||||
.await;
|
||||
}
|
||||
|
|
@ -822,16 +828,45 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
|||
remote_signature,
|
||||
*own_signature,
|
||||
&packet.payload,
|
||||
*max_substream,
|
||||
1 + *max_substream,
|
||||
);
|
||||
|
||||
let mut response = packet.base_acknowledgement_packet();
|
||||
response.header.types_and_flags.set_flag(HAS_SIZE | ACK);
|
||||
let mut response = packet.base_response_packet();
|
||||
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.sequence_id = 1;
|
||||
|
||||
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);
|
||||
|
||||
//println!("connect out: {:?}", response);
|
||||
|
||||
self.create_connection(crypto, address, session_id).await;
|
||||
|
||||
self.send_packet_unbuffered(address, response).await;
|
||||
|
|
@ -926,6 +961,15 @@ impl<T: CryptoHandler> AnyInternalSocket for InternalSocket<T> {
|
|||
info!("got ack");
|
||||
if packet.header.types_and_flags.get_types() == SYN ||
|
||||
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;
|
||||
info!("redirecting ack to active connection establishment code");
|
||||
|
||||
|
|
@ -976,7 +1020,7 @@ impl<T: CryptoHandler> AnyInternalSocket for InternalSocket<T> {
|
|||
},
|
||||
options: vec![
|
||||
SupportedFunctions(0x104),
|
||||
MaximumSubstreamId(1),
|
||||
MaximumSubstreamId(0),
|
||||
ConnectionSignature(remote_signature)
|
||||
],
|
||||
..Default::default()
|
||||
|
|
@ -1011,7 +1055,7 @@ impl<T: CryptoHandler> AnyInternalSocket for InternalSocket<T> {
|
|||
},
|
||||
options: vec![
|
||||
SupportedFunctions(0x04),
|
||||
MaximumSubstreamId(1),
|
||||
MaximumSubstreamId(0),
|
||||
ConnectionSignature(remote_signature)
|
||||
],
|
||||
..Default::default()
|
||||
|
|
|
|||
|
|
@ -132,14 +132,14 @@ impl RemoteObject for () {
|
|||
|
||||
pub trait RmcCallable {
|
||||
//type Remote: RemoteObject;
|
||||
async fn rmc_call(
|
||||
fn rmc_call(
|
||||
&self,
|
||||
responder: &SendingConnection,
|
||||
protocol_id: u16,
|
||||
method_id: u32,
|
||||
call_id: u32,
|
||||
rest: Vec<u8>,
|
||||
);
|
||||
) -> impl std::future::Future<Output = ()> + Send;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
@ -215,8 +215,8 @@ impl<T: RemoteInstantiatable> 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();
|
||||
|
||||
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!("ending rmc gateway.");
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue