fix warnings
Some checks failed
Build and Test / friends (push) Successful in 3m13s
Build and Test / splatoon (push) Failing after 4m27s

This commit is contained in:
Maple 2026-04-26 13:15:56 +02:00
commit a88f1898a5
24 changed files with 148 additions and 213 deletions

View file

@ -1,7 +1,7 @@
use proc_macro2::{Ident, Span, TokenStream}; use proc_macro2::{Ident, Span, TokenStream};
use quote::{quote, ToTokens}; use quote::{quote, ToTokens};
use syn::token::{Brace, Paren, Semi}; use syn::token::{Brace, Paren, Semi};
use syn::{Attribute, LitInt, LitStr, ReturnType, Type}; use syn::{LitInt, LitStr, ReturnType, Type};
pub struct ProtoMethodData { pub struct ProtoMethodData {
pub id: LitInt, pub id: LitInt,

View file

@ -1,12 +1,12 @@
use log::{error, info}; use log::{error, info};
use rnex_core::{ use rnex_core::{
PID, PID,
executables::common::{OWN_IP_PUBLIC, try_get_ip}, executables::common::try_get_ip,
prudp::{socket_addr::PRUDPSockAddr, virtual_port::VirtualPort}, prudp::{socket_addr::PRUDPSockAddr, virtual_port::VirtualPort},
reggie::{RemoteEdgeNodeHolder, UnitPacketWrite}, reggie::{RemoteEdgeNodeHolder, UnitPacketWrite},
rmc::{ rmc::{
protocols::{ protocols::{
OnlyRemote, RemoteDisconnectable, RmcCallable, RmcConnection, RmcPureRemoteObject, RemoteDisconnectable, RmcCallable, RmcConnection, RmcPureRemoteObject,
new_rmc_gateway_connection, new_rmc_gateway_connection,
}, },
structures::RmcSerialize, structures::RmcSerialize,
@ -17,7 +17,7 @@ use rnex_core::{
use std::{ use std::{
env::{self, VarError}, env::{self, VarError},
error, error,
net::{AddrParseError, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}, net::{AddrParseError, Ipv4Addr, SocketAddr, SocketAddrV4},
ops::Deref, ops::Deref,
panic, panic,
str::FromStr, str::FromStr,
@ -75,6 +75,7 @@ const VIRTUAL_PORT_INSECURE: LazyLock<VirtualPort> =
const VIRTUAL_PORT_SECURE: LazyLock<VirtualPort> = const VIRTUAL_PORT_SECURE: LazyLock<VirtualPort> =
LazyLock::new(|| VirtualPort::parse(env!("RNEX_VIRTUAL_PORT_SECURE")).unwrap()); LazyLock::new(|| VirtualPort::parse(env!("RNEX_VIRTUAL_PORT_SECURE")).unwrap());
impl ProxyStartupParam { impl ProxyStartupParam {
#[inline(always)]
pub fn new(prox_ty: ProxyType) -> Result<Self, Error> { pub fn new(prox_ty: ProxyType) -> Result<Self, Error> {
let port = RNEX_DEFAULT_PORT let port = RNEX_DEFAULT_PORT
+ match prox_ty { + match prox_ty {
@ -82,7 +83,7 @@ impl ProxyStartupParam {
ProxyType::Secure => 1, ProxyType::Secure => 1,
}; };
let self_private = try_get_env("SERVER_IP_PRIVATE") let self_private = try_get_env("SERVER_IP_PRIVATE")
.unwrap_or(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, RNEX_DEFAULT_PORT)); .unwrap_or(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port));
let self_public: SocketAddrV4 = match try_get_env("SERVER_IP_PUBLIC") { let self_public: SocketAddrV4 = match try_get_env("SERVER_IP_PUBLIC") {
Ok(v) => v, Ok(v) => v,
Err(e) => try_get_ip() Err(e) => try_get_ip()
@ -121,6 +122,7 @@ impl<T: RemoteDisconnectable + RmcPureRemoteObject, C: FnOnce() + Send + Sync +
Self(T::new(conn), Some(drop_func)) Self(T::new(conn), Some(drop_func))
} }
#[allow(dead_code)]
pub async fn disconnect(&self) { pub async fn disconnect(&self) {
self.0.disconnect().await; self.0.disconnect().await;
} }

View file

@ -5,7 +5,7 @@ use crate::crypto::Crypto;
pub struct Insecure; pub struct Insecure;
impl Crypto for Insecure { impl Crypto for Insecure {
fn new_connection(&self, data: &[u8]) -> Option<(PID, Vec<u8>)> { fn new_connection(&self, _data: &[u8]) -> Option<(PID, Vec<u8>)> {
Some((100, vec![])) Some((100, vec![]))
} }
fn new() -> Self { fn new() -> Self {

View file

@ -17,7 +17,7 @@ use rnex_core::{
types_flags::{ types_flags::{
TypesFlags, TypesFlags,
flags::{ACK, NEED_ACK, RELIABLE}, flags::{ACK, NEED_ACK, RELIABLE},
types::{CONNECT, DATA, DISCONNECT, SYN}, types::{CONNECT, DATA, DISCONNECT, PING, SYN},
}, },
virtual_port::VirtualPort, virtual_port::VirtualPort,
}, },
@ -26,20 +26,20 @@ use rnex_core::{
use tokio::net::{TcpListener, TcpStream}; use tokio::net::{TcpListener, TcpStream};
use tokio_tungstenite::{ use tokio_tungstenite::{
WebSocketStream, WebSocketStream,
tungstenite::{ tungstenite::{Bytes, Message},
Bytes, Message, client::IntoClientRequest, http::header::ACCESS_CONTROL_REQUEST_METHOD,
},
}; };
struct ConnectionState { struct ConnectionState {
param: Arc<ProxyStartupParam>, param: Arc<ProxyStartupParam>,
active: bool, active: bool,
websocket: WebSocketStream<TcpStream>, websocket: WebSocketStream<TcpStream>,
#[allow(dead_code)]
pid: PID, pid: PID,
backend_conn: SplittableBufferConnection, backend_conn: SplittableBufferConnection,
addr: PRUDPSockAddr, addr: PRUDPSockAddr,
incoming_reliable: HashMap<u16, LitePacket<Bytes>>, incoming_reliable: HashMap<u16, LitePacket<Bytes>>,
client_reliable_counter: u16, client_reliable_counter: u16,
#[allow(dead_code)]
server_reliable_counter: u16, server_reliable_counter: u16,
} }
@ -71,10 +71,16 @@ impl ConnectionState {
); );
let data: Bytes = data.into(); let data: Bytes = data.into();
if header.types_flags.get_types() == DISCONNECT { if header.types_flags.get_types() == DISCONNECT {
self.websocket.send(Message::Binary(data.clone())).await; self.websocket
self.websocket.send(Message::Binary(data.clone())).await; .send(Message::Binary(data.clone()))
.await
.ok();
self.websocket
.send(Message::Binary(data.clone()))
.await
.ok();
} }
self.websocket.send(Message::Binary(data)).await; self.websocket.send(Message::Binary(data)).await.ok();
} }
if (header.types_flags.get_flags() & ACK) != 0 { if (header.types_flags.get_flags() & ACK) != 0 {
@ -111,6 +117,7 @@ impl ConnectionState {
} }
} }
} }
#[allow(dead_code)]
pub async fn process_reliable(&mut self) { pub async fn process_reliable(&mut self) {
while let Some(v) = self.incoming_reliable.remove(&self.client_reliable_counter) { while let Some(v) = self.incoming_reliable.remove(&self.client_reliable_counter) {
self.handle_incoming_prudp(v, true).await; self.handle_incoming_prudp(v, true).await;
@ -131,7 +138,7 @@ impl ConnectionState {
} }
} }
} }
v = self.backend_conn.recv() => { _ = self.backend_conn.recv() => {
} }
} }
@ -197,7 +204,7 @@ pub async fn websocket_thread_unconnected<C: Crypto>(
], ],
&[], &[],
); );
websocket.send(Message::Binary(data.into())).await; websocket.send(Message::Binary(data.into())).await.ok();
} }
CONNECT => { CONNECT => {
let Some(supported) = packet.packet_specific_iter() else { let Some(supported) = packet.packet_specific_iter() else {
@ -242,7 +249,7 @@ pub async fn websocket_thread_unconnected<C: Crypto>(
], ],
&data, &data,
); );
websocket.send(Message::Binary(data.into())).await; websocket.send(Message::Binary(data.into())).await.ok();
let addr = PRUDPSockAddr::new( let addr = PRUDPSockAddr::new(
addr, addr,

View file

@ -3,8 +3,7 @@ use std::{
io::{self, Cursor, Read, Write}, io::{self, Cursor, Read, Write},
}; };
use bytemuck::{Pod, Zeroable, bytes_of}; use bytemuck::{Pod, Zeroable, bytes_of_mut};
use futures_util::Stream;
use rnex_core::prudp::types_flags::TypesFlags; use rnex_core::prudp::types_flags::TypesFlags;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
@ -30,10 +29,10 @@ pub enum PacketSpecificData {
impl PacketSpecificData { impl PacketSpecificData {
fn consume(reader: &mut impl Read) -> io::Result<Self> { fn consume(reader: &mut impl Read) -> io::Result<Self> {
let mut option_id = 0; let mut option_id = 0u8;
reader.read_exact(&mut [option_id])?; reader.read_exact(bytes_of_mut(&mut option_id))?;
let mut size = 0; let mut size = 0u8;
reader.read_exact(&mut [size])?; reader.read_exact(bytes_of_mut(&mut size))?;
match option_id { match option_id {
0 => { 0 => {
@ -156,7 +155,7 @@ impl<T: AsRef<[u8]>> LitePacket<T> {
.get_mut(size_of::<LiteHeader>()..size_of::<LiteHeader>() + len as usize) .get_mut(size_of::<LiteHeader>()..size_of::<LiteHeader>() + len as usize)
} }
pub fn packet_specific_iter(&self) -> Option<PacketSpecificIter> { pub fn packet_specific_iter<'a>(&'a self) -> Option<PacketSpecificIter<'a>> {
self.packet_specific_raw() self.packet_specific_raw()
.map(Cursor::new) .map(Cursor::new)
.map(PacketSpecificIter) .map(PacketSpecificIter)

View file

@ -1,4 +1,4 @@
use std::{io::Write, rc::Rc}; use std::io::Write;
use hmac::Mac; use hmac::Mac;
use md5::{Digest, Md5}; use md5::{Digest, Md5};
@ -18,6 +18,7 @@ use crate::crypto::{
pub struct InsecureInstance { pub struct InsecureInstance {
pair: EncryptionPair<Rc4<U5>>, pair: EncryptionPair<Rc4<U5>>,
self_signat: [u8; 4], self_signat: [u8; 4],
#[allow(dead_code)]
remote_signat: [u8; 4], remote_signat: [u8; 4],
} }
@ -62,7 +63,7 @@ impl Crypto for Insecure {
fn instantiate( fn instantiate(
&self, &self,
packet_data: &[u8], _packet_data: &[u8],
self_signat: [u8; 4], self_signat: [u8; 4],
remote_signat: [u8; 4], remote_signat: [u8; 4],
) -> Option<(Self::Instance, Vec<u8>)> { ) -> Option<(Self::Instance, Vec<u8>)> {

View file

@ -24,6 +24,7 @@ pub struct SecureInstance {
pair: EncryptionPair<Rc4<U16>>, pair: EncryptionPair<Rc4<U16>>,
uid: u32, uid: u32,
self_signat: [u8; 4], self_signat: [u8; 4],
#[allow(dead_code)]
remote_signat: [u8; 4], remote_signat: [u8; 4],
} }

View file

@ -1,26 +1,13 @@
cfg_if::cfg_if! {
if #[cfg(feature = "prudpv0")] {
use bytemuck::{Pod, Zeroable};
use cfg_if::cfg_if; use cfg_if::cfg_if;
use log::{error, info, warn}; cfg_if! {
use proxy_common::{ProxyStartupParam, setup_edge_node_connection}; if #[cfg(feature = "prudpv0")] {
use rnex_core::executables::common::{OWN_IP_PRIVATE, OWN_IP_PUBLIC, SERVER_PORT}; use log::info;
use rnex_core::prudp::types_flags::TypesFlags; use proxy_common::ProxyStartupParam;
use rnex_core::prudp::types_flags::types::SYN;
use rnex_core::prudp::virtual_port::VirtualPort;
use rnex_core::reggie::EdgeNodeHolderConnectOption::Register;
use rnex_core::reggie::RemoteEdgeNodeHolder;
use rnex_core::rmc::protocols::{OnlyRemote, new_rmc_gateway_connection};
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::util::SplittableBufferConnection;
use std::env; use std::env;
use std::net::SocketAddrV4; use std::net::SocketAddrV4;
use std::process::abort;
use std::sync::{Arc, LazyLock}; use std::sync::{Arc, LazyLock};
use tokio::net::UdpSocket;
use crate::crypto::{Crypto, Insecure, Secure}; use crate::crypto::{Crypto, Insecure, Secure};
use crate::packet::PRUDPV0Packet;
use crate::server::Server; use crate::server::Server;
mod crypto; mod crypto;
@ -44,8 +31,6 @@ cfg_if::cfg_if! {
//implementations, e.g. secure and insecure(this also includes special cases like friends) //implementations, e.g. secure and insecure(this also includes special cases like friends)
async fn start_proxy<T: Crypto>(param: ProxyStartupParam) { async fn start_proxy<T: Crypto>(param: ProxyStartupParam) {
info!("creating cryptography instance");
let mut crypto = Arc::new(T::new());
info!("binding to socket"); info!("binding to socket");
let server: Arc<Server<T>> = Arc::new(Server::new(param).await); let server: Arc<Server<T>> = Arc::new(Server::new(param).await);

View file

@ -1,11 +1,9 @@
use std::mem::transmute;
use bytemuck::{Pod, Zeroable, try_from_bytes, try_from_bytes_mut}; use bytemuck::{Pod, Zeroable, try_from_bytes, try_from_bytes_mut};
use log::{error, info, warn}; use log::{info, warn};
use rnex_core::prudp::{ use rnex_core::prudp::{
types_flags::{ types_flags::{
self, TypesFlags, TypesFlags,
flags::{HAS_SIZE, NEED_ACK}, flags::HAS_SIZE,
types::{CONNECT, DATA, DISCONNECT, PING, SYN}, types::{CONNECT, DATA, DISCONNECT, PING, SYN},
}, },
virtual_port::VirtualPort, virtual_port::VirtualPort,
@ -165,6 +163,7 @@ impl<T: AsRef<[u8]>> PRUDPV0Packet<T> {
const DEFAULT_SIGNAT: [u8; 4] = [0x12, 0x34, 0x56, 0x78]; const DEFAULT_SIGNAT: [u8; 4] = [0x12, 0x34, 0x56, 0x78];
#[inline(always)] #[inline(always)]
#[allow(dead_code)]
const fn get_size_offset(tf: TypesFlags) -> usize { const fn get_size_offset(tf: TypesFlags) -> usize {
size_of::<PRUDPV0Header>() size_of::<PRUDPV0Header>()
+ (if tf.get_types() & (SYN | CONNECT) != 0 { + (if tf.get_types() & (SYN | CONNECT) != 0 {

View file

@ -1,32 +1,24 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
hash::Hash, net::{SocketAddr, SocketAddrV4},
net::{Ipv4Addr, SocketAddr, SocketAddrV4}, sync::{Arc, Weak},
sync::{
Arc, LazyLock, Weak,
atomic::{AtomicBool, AtomicU32},
},
time::Duration, time::Duration,
}; };
use log::{error, info, warn}; use log::{error, info, warn};
use proxy_common::{ProxyStartupParam, new_backend_connection}; use proxy_common::{ProxyStartupParam, new_backend_connection};
use rnex_core::{ use rnex_core::{
executables::common::{OWN_IP_PRIVATE, SERVER_PORT},
prudp::{ prudp::{
socket_addr::PRUDPSockAddr, socket_addr::PRUDPSockAddr,
types_flags::{ types_flags::{
TypesFlags, flags::{ACK, NEED_ACK, RELIABLE},
flags::{ACK, HAS_SIZE, NEED_ACK, RELIABLE},
types::{CONNECT, DATA, DISCONNECT, PING, SYN}, types::{CONNECT, DATA, DISCONNECT, PING, SYN},
}, },
virtual_port::VirtualPort,
}, },
rnex_proxy_common::ConnectionInitData,
util::{SendingBufferConnection, SplittableBufferConnection}, util::{SendingBufferConnection, SplittableBufferConnection},
}; };
use tokio::{ use tokio::{
net::{TcpSocket, UdpSocket}, net::UdpSocket,
spawn, spawn,
sync::{Mutex, RwLock}, sync::{Mutex, RwLock},
time::{Instant, sleep}, time::{Instant, sleep},
@ -35,8 +27,8 @@ use tokio::{
use crate::{ use crate::{
crypto::{Crypto, CryptoInstance}, crypto::{Crypto, CryptoInstance},
packet::{ packet::{
PRUDPV0Header, PRUDPV0Packet, new_connect_packet, new_data_packet, new_disconnect_packet, PRUDPV0Packet, new_connect_packet, new_data_packet, new_disconnect_packet, new_ping_packet,
new_ping_packet, new_syn_packet, precalc_size, new_syn_packet,
}, },
}; };
@ -49,16 +41,14 @@ pub struct InternalConnection<C: CryptoInstance> {
packet_queue: HashMap<u16, (Instant, PRUDPV0Packet<Vec<u8>>)>, packet_queue: HashMap<u16, (Instant, PRUDPV0Packet<Vec<u8>>)>,
} }
pub struct Connection<C: CryptoInstance> { pub struct Connection<C: CryptoInstance> {
alive: AtomicBool,
session_id: u8, session_id: u8,
target: SendingBufferConnection, target: SendingBufferConnection,
self_signat: [u8; 4],
remote_signat: [u8; 4],
addr: PRUDPSockAddr, addr: PRUDPSockAddr,
inner: Mutex<InternalConnection<C>>, inner: Mutex<InternalConnection<C>>,
} }
impl<C: CryptoInstance> InternalConnection<C> { impl<C: CryptoInstance> InternalConnection<C> {
#[allow(dead_code)]
fn next_server_count(&mut self) -> u16 { fn next_server_count(&mut self) -> u16 {
let prev_val = self.server_packet_counter; let prev_val = self.server_packet_counter;
let (val, _) = self.server_packet_counter.overflowing_add(1); let (val, _) = self.server_packet_counter.overflowing_add(1);
@ -148,7 +138,8 @@ impl<C: Crypto> Server<C> {
this.socket this.socket
.send_to(&data, conn.addr.regular_socket_addr) .send_to(&data, conn.addr.regular_socket_addr)
.await; .await
.ok();
break; break;
} }
@ -192,7 +183,8 @@ impl<C: Crypto> Server<C> {
self.socket self.socket
.send_to(&packet, conn.addr.regular_socket_addr) .send_to(&packet, conn.addr.regular_socket_addr)
.await; .await
.ok();
} }
if (Instant::now() - inner.last_action).as_secs() > 15 { if (Instant::now() - inner.last_action).as_secs() > 15 {
@ -210,13 +202,16 @@ impl<C: Crypto> Server<C> {
self.socket self.socket
.send_to(&packet, conn.addr.regular_socket_addr) .send_to(&packet, conn.addr.regular_socket_addr)
.await; .await
.ok();
self.socket self.socket
.send_to(&packet, conn.addr.regular_socket_addr) .send_to(&packet, conn.addr.regular_socket_addr)
.await; .await
.ok();
self.socket self.socket
.send_to(&packet, conn.addr.regular_socket_addr) .send_to(&packet, conn.addr.regular_socket_addr)
.await; .await
.ok();
drop(inner); drop(inner);
let mut conns = self.connections.write().await; let mut conns = self.connections.write().await;
@ -236,7 +231,10 @@ impl<C: Crypto> Server<C> {
let signat = [signat[0], signat[1], signat[2], signat[3]]; let signat = [signat[0], signat[1], signat[2], signat[3]];
let packet = new_syn_packet(ACK, header.destination, header.source, signat, &self.crypto); let packet = new_syn_packet(ACK, header.destination, header.source, signat, &self.crypto);
self.socket.send_to(&packet, addr.regular_socket_addr).await; self.socket
.send_to(&packet, addr.regular_socket_addr)
.await
.ok();
} }
async fn handle_connect(self: Arc<Self>, packet: PRUDPV0Packet<Vec<u8>>, addr: PRUDPSockAddr) { async fn handle_connect(self: Arc<Self>, packet: PRUDPV0Packet<Vec<u8>>, addr: PRUDPSockAddr) {
let Some(data) = packet.payload() else { let Some(data) = packet.payload() else {
@ -275,11 +273,8 @@ impl<C: Crypto> Server<C> {
let conn = Arc::new(Connection { let conn = Arc::new(Connection {
target: buf_conn.duplicate_sender(), target: buf_conn.duplicate_sender(),
remote_signat,
self_signat,
addr, addr,
session_id: header.session_id, session_id: header.session_id,
alive: AtomicBool::new(true),
inner: Mutex::new(InternalConnection { inner: Mutex::new(InternalConnection {
last_action: Instant::now(), last_action: Instant::now(),
crypto_instance: ci, crypto_instance: ci,
@ -320,9 +315,12 @@ impl<C: Crypto> Server<C> {
); );
info!("sending back connection accept"); info!("sending back connection accept");
self.socket.send_to(&packet, addr.regular_socket_addr).await; self.socket
.send_to(&packet, addr.regular_socket_addr)
.await
.ok();
} }
async fn handle_data(self: Arc<Self>, mut packet: PRUDPV0Packet<Vec<u8>>, addr: PRUDPSockAddr) { async fn handle_data(self: Arc<Self>, packet: PRUDPV0Packet<Vec<u8>>, addr: PRUDPSockAddr) {
let Some(frag_id) = packet.fragment_id() else { let Some(frag_id) = packet.fragment_id() else {
warn!("invalid packet from: {:?}", addr); warn!("invalid packet from: {:?}", addr);
return; return;
@ -349,7 +347,10 @@ impl<C: Crypto> Server<C> {
&mut conn.crypto_instance, &mut conn.crypto_instance,
&self.crypto, &self.crypto,
); );
self.socket.send_to(&ack, addr.regular_socket_addr).await; self.socket
.send_to(&ack, addr.regular_socket_addr)
.await
.ok();
conn.packet_queue.insert( conn.packet_queue.insert(
packet.header().unwrap().sequence_id, packet.header().unwrap().sequence_id,
(Instant::now(), packet), (Instant::now(), packet),
@ -375,7 +376,7 @@ impl<C: Crypto> Server<C> {
drop(conn); drop(conn);
} }
async fn handle_ping(self: Arc<Self>, mut packet: PRUDPV0Packet<Vec<u8>>, addr: PRUDPSockAddr) { async fn handle_ping(self: Arc<Self>, packet: PRUDPV0Packet<Vec<u8>>, addr: PRUDPSockAddr) {
info!("got ping"); info!("got ping");
let header = packet.header().unwrap(); let header = packet.header().unwrap();
@ -395,11 +396,14 @@ impl<C: Crypto> Server<C> {
); );
drop(inner); drop(inner);
self.socket.send_to(&packet, addr.regular_socket_addr).await; self.socket
.send_to(&packet, addr.regular_socket_addr)
.await
.ok();
} }
async fn handle_disconnect( async fn handle_disconnect(
self: Arc<Self>, self: Arc<Self>,
mut packet: PRUDPV0Packet<Vec<u8>>, packet: PRUDPV0Packet<Vec<u8>>,
addr: PRUDPSockAddr, addr: PRUDPSockAddr,
) { ) {
info!("got disconnect"); info!("got disconnect");
@ -425,9 +429,18 @@ impl<C: Crypto> Server<C> {
conns.remove(&(addr, header.session_id)); conns.remove(&(addr, header.session_id));
drop(conns); drop(conns);
self.socket.send_to(&packet, addr.regular_socket_addr).await; self.socket
self.socket.send_to(&packet, addr.regular_socket_addr).await; .send_to(&packet, addr.regular_socket_addr)
self.socket.send_to(&packet, addr.regular_socket_addr).await; .await
.ok();
self.socket
.send_to(&packet, addr.regular_socket_addr)
.await
.ok();
self.socket
.send_to(&packet, addr.regular_socket_addr)
.await
.ok();
} }
async fn get_connection( async fn get_connection(
&self, &self,

View file

@ -1,13 +1,6 @@
use cfg_if::cfg_if; use cfg_if::cfg_if;
use rnex_core::common::setup; use rnex_core::common::setup;
use rnex_core::executables::common::new_simple_backend;
use rnex_core::executables::friends_backend::start_friends_backend; use rnex_core::executables::friends_backend::start_friends_backend;
use rnex_core::nex::matchmake::MatchmakeManager;
use rnex_core::nex::remote_console::RemoteConsole;
use rnex_core::nex::user::User;
use rnex_core::rmc::protocols::{RemoteDisconnectable, RmcPureRemoteObject};
use std::sync::Arc;
use std::sync::atomic::AtomicU32;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {

View file

@ -8,15 +8,11 @@ use log::error;
use tokio::net::TcpListener; use tokio::net::TcpListener;
use crate::{ use crate::{
executables::common::{OWN_IP_PRIVATE, SERVER_PORT, new_simple_backend}, executables::common::{OWN_IP_PRIVATE, SERVER_PORT},
nex::friends_handler::{ nex::friends_handler::{FriendsGuest, FriendsManager, FriendsUser, RemoteFriendRemote},
FriendsGuest, FriendsManager, FriendsUser, RemoteFriendRemote, RemoteFriendsUser,
},
reggie::UnitPacketRead, reggie::UnitPacketRead,
rmc::{ rmc::{
protocols::{ protocols::{RmcPureRemoteObject, new_rmc_gateway_connection},
RmcCallable, RmcPureRemoteObject, friends::RemoteFriends, new_rmc_gateway_connection,
},
structures::RmcSerialize, structures::RmcSerialize,
}, },
rnex_proxy_common::ConnectionInitData, rnex_proxy_common::ConnectionInitData,
@ -65,8 +61,8 @@ pub async fn start_friends_backend() {
}) })
}); });
} else { } else {
new_rmc_gateway_connection(stream.into(), move |r| { new_rmc_gateway_connection(stream.into(), move |_| {
Arc::new_cyclic(move |this| FriendsGuest { Arc::new_cyclic(move |_| FriendsGuest {
fm, fm,
addr: c.prudpsock_addr, addr: c.prudpsock_addr,
}) })

View file

@ -1,3 +1,10 @@
use cfg_if::cfg_if;
pub mod common; pub mod common;
cfg_if! {
if #[cfg(feature = "friends")]{
pub mod friends_backend; pub mod friends_backend;
} else {
pub mod regular_backend; pub mod regular_backend;
}
}

View file

@ -18,13 +18,13 @@ use rnex_core::PID;
cfg_if! { cfg_if! {
if #[cfg(feature = "friends")]{ if #[cfg(feature = "friends")]{
pub type SESSION_KEY_LENGTH_TY = U16; pub type SessionLengthTy = U16;
} else { } else {
use rc4::consts::U32; use rc4::consts::U32;
pub type SESSION_KEY_LENGTH_TY = U32; pub type SessionLengthTy = U32;
} }
} }
pub const SESSION_KEY_LENGTH: usize = SESSION_KEY_LENGTH_TY::USIZE; pub const SESSION_KEY_LENGTH: usize = SessionLengthTy::USIZE;
type Md5Hmac = Hmac<md5::Md5>; type Md5Hmac = Hmac<md5::Md5>;

View file

@ -337,82 +337,3 @@ impl Auth for AuthHandler {
Err(ErrorCode::Core_Exception) Err(ErrorCode::Core_Exception)
} }
} }
mod test {
use std::io::Cursor;
use rc4::{KeyInit, Rc4, StreamCipher};
use rnex_core::PID;
use rnex_core::kerberos::KerberosDateTime;
use rnex_core::rmc::structures::connection_data::ConnectionData;
use rnex_core::rmc::{
response::ErrorCode,
structures::{RmcSerialize, qresult::QResult},
};
use crate::kerberos::{self, derive_key};
use crate::rmc;
use crate::rmc::message::RMCMessage;
use crate::rmc::response::{RMCResponse, RMCResponseResult};
#[test]
fn test() {
return;
let packet = [
26, 1, 0, 0, 10, 1, 30, 0, 0, 0, 1, 128, 0, 0, 1, 0, 1, 0, 86, 4, 0, 0, 116, 0, 0, 0,
144, 209, 130, 175, 45, 215, 95, 55, 226, 192, 51, 54, 201, 84, 118, 150, 159, 164, 32,
103, 134, 252, 199, 168, 178, 5, 6, 208, 206, 241, 94, 23, 136, 37, 109, 247, 156, 252,
189, 233, 142, 115, 206, 72, 180, 57, 106, 223, 37, 59, 144, 208, 250, 197, 51, 202,
185, 156, 51, 159, 219, 117, 250, 103, 184, 1, 103, 108, 15, 14, 174, 160, 192, 146,
135, 10, 55, 125, 68, 181, 88, 127, 183, 34, 4, 213, 19, 146, 81, 56, 248, 213, 241,
168, 205, 253, 29, 10, 123, 198, 177, 157, 247, 209, 113, 167, 231, 42, 214, 15, 12,
200, 192, 230, 125, 227, 74, 0, 112, 114, 117, 100, 112, 115, 58, 47, 80, 73, 68, 61,
50, 59, 115, 105, 100, 61, 49, 59, 115, 116, 114, 101, 97, 109, 61, 49, 48, 59, 116,
121, 112, 101, 61, 50, 59, 97, 100, 100, 114, 101, 115, 115, 61, 57, 49, 46, 57, 56,
46, 49, 50, 56, 46, 56, 54, 59, 112, 111, 114, 116, 61, 54, 48, 48, 49, 59, 67, 73, 68,
61, 49, 0, 0, 0, 0, 0, 1, 0, 0, 162, 243, 240, 168, 31, 0, 0, 0, 51, 0, 98, 114, 97,
110, 99, 104, 58, 111, 114, 105, 103, 105, 110, 47, 112, 114, 111, 106, 101, 99, 116,
47, 119, 117, 112, 45, 97, 103, 109, 106, 32, 98, 117, 105, 108, 100, 58, 51, 95, 56,
95, 49, 53, 95, 50, 48, 48, 52, 95, 48, 0,
];
let rmc_packet = RMCResponse::new(&mut Cursor::new(&packet)).unwrap();
println!("{:?}", rmc_packet);
let RMCResponseResult::Success {
call_id,
method_id,
data,
} = rmc_packet.response_result
else {
panic!();
};
println!("{}", hex::encode(&data));
let mut data =
<(QResult, PID, Vec<u8>, ConnectionData, String) as RmcSerialize>::deserialize(
&mut Cursor::new(&data[..]),
)
.unwrap();
println!("{:?}", data);
let key = derive_key(1110, "AAAAAAAAAAAAAAAA".as_bytes());
let mut rc4 = Rc4::new((&key).into());
rc4.apply_keystream(&mut data.2);
println!("raw tick: {:?}", data.2);
let tick: &kerberos::Ticket =
bytemuck::from_bytes(&data.2[..size_of::<kerberos::Ticket>()]);
let remainder = &data.2[size_of::<kerberos::Ticket>()..];
println!("tick: {:?}", tick);
let data = <Vec<u8> as RmcSerialize>::deserialize(&mut Cursor::new(remainder)).unwrap();
println!("inner ticket raw: {:?}", data);
println!("{:?}", data);
}
}

View file

@ -312,7 +312,7 @@ impl Friends for FriendsUser {
async fn delete_persistent_notification( async fn delete_persistent_notification(
&self, &self,
notifs: Vec<PersistentNotification>, _notifs: Vec<PersistentNotification>,
) -> Result<(), ErrorCode> { ) -> Result<(), ErrorCode> {
Ok(()) Ok(())
} }

View file

@ -1,7 +1,15 @@
use cfg_if::cfg_if;
pub mod account; pub mod account;
pub mod auth_handler; pub mod auth_handler;
pub mod common; pub mod common;
cfg_if! {
if #[cfg(feature = "friends")]{
pub mod friends_handler; pub mod friends_handler;
} else {
pub mod matchmake; pub mod matchmake;
pub mod remote_console; pub mod remote_console;
pub mod user; pub mod user;
}
}

View file

@ -6,7 +6,7 @@ use typenum::U16;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::{ use crate::{
kerberos::{SESSION_KEY_LENGTH, SESSION_KEY_LENGTH_TY, TicketInternalData, derive_key}, kerberos::{SESSION_KEY_LENGTH, SessionLengthTy, TicketInternalData, derive_key},
nex::account::Account, nex::account::Account,
rmc::structures::RmcSerialize, rmc::structures::RmcSerialize,
}; };
@ -53,7 +53,7 @@ pub fn read_secure_connection_data(
let request_data_length = request_data.len(); let request_data_length = request_data.len();
let request_data = &mut request_data[0..request_data_length - 0x10]; let request_data = &mut request_data[0..request_data_length - 0x10];
let mut rc4: StreamCipherCoreWrapper<Rc4Core<SESSION_KEY_LENGTH_TY>> = let mut rc4: StreamCipherCoreWrapper<Rc4Core<SessionLengthTy>> =
Rc4::new_from_slice(&session_key).expect("unable to init rc4 keystream"); Rc4::new_from_slice(&session_key).expect("unable to init rc4 keystream");
rc4.apply_keystream(request_data); rc4.apply_keystream(request_data);

View file

@ -1,8 +1,5 @@
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::{ use std::fmt::{Debug, Formatter};
fmt::{Debug, Formatter},
slice,
};
use v_byte_helpers::SwapEndian; use v_byte_helpers::SwapEndian;
#[repr(transparent)] #[repr(transparent)]

View file

@ -8,11 +8,11 @@ use rnex_core::rmc::structures::qresult::QResult;
cfg_if! { cfg_if! {
if #[cfg(feature = "nx")]{ if #[cfg(feature = "nx")]{
type LOGIN_EX_RET = (QResult, PID, Vec<u8>, ConnectionData, String, String); type LoginExRet = (QResult, PID, Vec<u8>, ConnectionData, String, String);
type REQUEST_TICKET_RET = (QResult, Vec<u8>, String); type RequestTicketRet = (QResult, Vec<u8>, String);
} else { } else {
type LOGIN_EX_RET = (QResult, PID, Vec<u8>, ConnectionData, String); type LoginExRet = (QResult, PID, Vec<u8>, ConnectionData, String);
type REQUEST_TICKET_RET = (QResult, Vec<u8>); type RequestTicketRet = (QResult, Vec<u8>);
} }
} }
@ -31,14 +31,14 @@ pub trait Auth {
/// representation of the `LoginEx` method(for details see the /// representation of the `LoginEx` method(for details see the
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol)) /// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
#[method_id(2)] #[method_id(2)]
async fn login_ex(&self, name: String, extra_data: Any) -> Result<LOGIN_EX_RET, ErrorCode>; async fn login_ex(&self, name: String, extra_data: Any) -> Result<LoginExRet, ErrorCode>;
#[method_id(3)] #[method_id(3)]
async fn request_ticket( async fn request_ticket(
&self, &self,
source_pid: PID, source_pid: PID,
destination_pid: PID, destination_pid: PID,
) -> Result<REQUEST_TICKET_RET, ErrorCode>; ) -> Result<RequestTicketRet, ErrorCode>;
/// representation of the `RequestTicket` method(for details see the /// representation of the `RequestTicket` method(for details see the
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol)) /// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))

View file

@ -2,7 +2,7 @@ use macros::{RmcSerialize, method_id, rmc_proto};
use rnex_core::{kerberos::KerberosDateTime, rmc::response::ErrorCode}; use rnex_core::{kerberos::KerberosDateTime, rmc::response::ErrorCode};
use rnex_core::rmc::structures::{data::Data, rmc_struct}; use rnex_core::rmc::structures::data::Data;
#[derive(RmcSerialize, Debug, Clone)] #[derive(RmcSerialize, Debug, Clone)]
#[rmc_struct(0)] #[rmc_struct(0)]

View file

@ -1,4 +1,4 @@
use macros::{RmcSerialize, method_id, rmc_proto, rmc_struct}; use macros::{RmcSerialize, method_id, rmc_proto};
use rnex_core::PID; use rnex_core::PID;

View file

@ -1,4 +1,4 @@
use macros::{rmc_struct, rmc_proto, RmcSerialize, method_id}; use macros::{RmcSerialize, method_id, rmc_proto};
use rnex_core::kerberos::KerberosDateTime; use rnex_core::kerberos::KerberosDateTime;
use rnex_core::rmc::structures::qbuffer::QBuffer; use rnex_core::rmc::structures::qbuffer::QBuffer;
@ -10,7 +10,7 @@ use rnex_core::rmc::structures::ranking::UploadCompetitionData;
#[rmc_struct(0)] #[rmc_struct(0)]
pub struct ResultsRange { pub struct ResultsRange {
pub offset: u32, pub offset: u32,
pub size: u32 pub size: u32,
} }
#[derive(RmcSerialize, Debug, Default, Clone)] #[derive(RmcSerialize, Debug, Default, Clone)]
@ -28,7 +28,7 @@ pub struct CompetitionRankingScoreInfo{
pub score_data: Vec<CompetitionRankingScoreData>, pub score_data: Vec<CompetitionRankingScoreData>,
pub unk: u32, pub unk: u32,
pub team_wins: Vec<u32>, pub team_wins: Vec<u32>,
pub team_votes: Vec<u32> pub team_votes: Vec<u32>,
} }
#[derive(RmcSerialize, Debug, Clone)] #[derive(RmcSerialize, Debug, Clone)]
@ -39,13 +39,19 @@ pub struct CompetitionRankingScoreData{
pub score: u32, pub score: u32,
pub modified: KerberosDateTime, pub modified: KerberosDateTime,
pub unk2: u8, pub unk2: u8,
pub appdata: QBuffer pub appdata: QBuffer,
} }
#[rmc_proto(112)] #[rmc_proto(112)]
pub trait Ranking { pub trait Ranking {
#[method_id(16)] #[method_id(16)]
async fn competition_ranking_get_param(&self, param: CompetitionRankingGetParam) -> Result<Vec<CompetitionRankingScoreInfo>,ErrorCode>; async fn competition_ranking_get_param(
&self,
param: CompetitionRankingGetParam,
) -> Result<Vec<CompetitionRankingScoreInfo>, ErrorCode>;
#[method_id(18)] #[method_id(18)]
async fn upload_competition_ranking_score(&self, param: UploadCompetitionData) -> Result<bool, ErrorCode>; async fn upload_competition_ranking_score(
&self,
param: UploadCompetitionData,
) -> Result<bool, ErrorCode>;
} }