fix warnings
This commit is contained in:
parent
70ced21e59
commit
a88f1898a5
24 changed files with 148 additions and 213 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::token::{Brace, Paren, Semi};
|
||||
use syn::{Attribute, LitInt, LitStr, ReturnType, Type};
|
||||
use syn::{LitInt, LitStr, ReturnType, Type};
|
||||
|
||||
pub struct ProtoMethodData {
|
||||
pub id: LitInt,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use log::{error, info};
|
||||
use rnex_core::{
|
||||
PID,
|
||||
executables::common::{OWN_IP_PUBLIC, try_get_ip},
|
||||
executables::common::try_get_ip,
|
||||
prudp::{socket_addr::PRUDPSockAddr, virtual_port::VirtualPort},
|
||||
reggie::{RemoteEdgeNodeHolder, UnitPacketWrite},
|
||||
rmc::{
|
||||
protocols::{
|
||||
OnlyRemote, RemoteDisconnectable, RmcCallable, RmcConnection, RmcPureRemoteObject,
|
||||
RemoteDisconnectable, RmcCallable, RmcConnection, RmcPureRemoteObject,
|
||||
new_rmc_gateway_connection,
|
||||
},
|
||||
structures::RmcSerialize,
|
||||
|
|
@ -17,7 +17,7 @@ use rnex_core::{
|
|||
use std::{
|
||||
env::{self, VarError},
|
||||
error,
|
||||
net::{AddrParseError, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
net::{AddrParseError, Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
ops::Deref,
|
||||
panic,
|
||||
str::FromStr,
|
||||
|
|
@ -75,6 +75,7 @@ const VIRTUAL_PORT_INSECURE: LazyLock<VirtualPort> =
|
|||
const VIRTUAL_PORT_SECURE: LazyLock<VirtualPort> =
|
||||
LazyLock::new(|| VirtualPort::parse(env!("RNEX_VIRTUAL_PORT_SECURE")).unwrap());
|
||||
impl ProxyStartupParam {
|
||||
#[inline(always)]
|
||||
pub fn new(prox_ty: ProxyType) -> Result<Self, Error> {
|
||||
let port = RNEX_DEFAULT_PORT
|
||||
+ match prox_ty {
|
||||
|
|
@ -82,7 +83,7 @@ impl ProxyStartupParam {
|
|||
ProxyType::Secure => 1,
|
||||
};
|
||||
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") {
|
||||
Ok(v) => v,
|
||||
Err(e) => try_get_ip()
|
||||
|
|
@ -121,6 +122,7 @@ impl<T: RemoteDisconnectable + RmcPureRemoteObject, C: FnOnce() + Send + Sync +
|
|||
Self(T::new(conn), Some(drop_func))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn disconnect(&self) {
|
||||
self.0.disconnect().await;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::crypto::Crypto;
|
|||
pub struct 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![]))
|
||||
}
|
||||
fn new() -> Self {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use rnex_core::{
|
|||
types_flags::{
|
||||
TypesFlags,
|
||||
flags::{ACK, NEED_ACK, RELIABLE},
|
||||
types::{CONNECT, DATA, DISCONNECT, SYN},
|
||||
types::{CONNECT, DATA, DISCONNECT, PING, SYN},
|
||||
},
|
||||
virtual_port::VirtualPort,
|
||||
},
|
||||
|
|
@ -26,20 +26,20 @@ use rnex_core::{
|
|||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio_tungstenite::{
|
||||
WebSocketStream,
|
||||
tungstenite::{
|
||||
Bytes, Message, client::IntoClientRequest, http::header::ACCESS_CONTROL_REQUEST_METHOD,
|
||||
},
|
||||
tungstenite::{Bytes, Message},
|
||||
};
|
||||
|
||||
struct ConnectionState {
|
||||
param: Arc<ProxyStartupParam>,
|
||||
active: bool,
|
||||
websocket: WebSocketStream<TcpStream>,
|
||||
#[allow(dead_code)]
|
||||
pid: PID,
|
||||
backend_conn: SplittableBufferConnection,
|
||||
addr: PRUDPSockAddr,
|
||||
incoming_reliable: HashMap<u16, LitePacket<Bytes>>,
|
||||
client_reliable_counter: u16,
|
||||
#[allow(dead_code)]
|
||||
server_reliable_counter: u16,
|
||||
}
|
||||
|
||||
|
|
@ -71,10 +71,16 @@ impl ConnectionState {
|
|||
);
|
||||
let data: Bytes = data.into();
|
||||
if header.types_flags.get_types() == DISCONNECT {
|
||||
self.websocket.send(Message::Binary(data.clone())).await;
|
||||
self.websocket.send(Message::Binary(data.clone())).await;
|
||||
self.websocket
|
||||
.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 {
|
||||
|
|
@ -111,6 +117,7 @@ impl ConnectionState {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub async fn process_reliable(&mut self) {
|
||||
while let Some(v) = self.incoming_reliable.remove(&self.client_reliable_counter) {
|
||||
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 => {
|
||||
let Some(supported) = packet.packet_specific_iter() else {
|
||||
|
|
@ -242,7 +249,7 @@ pub async fn websocket_thread_unconnected<C: Crypto>(
|
|||
],
|
||||
&data,
|
||||
);
|
||||
websocket.send(Message::Binary(data.into())).await;
|
||||
websocket.send(Message::Binary(data.into())).await.ok();
|
||||
|
||||
let addr = PRUDPSockAddr::new(
|
||||
addr,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ use std::{
|
|||
io::{self, Cursor, Read, Write},
|
||||
};
|
||||
|
||||
use bytemuck::{Pod, Zeroable, bytes_of};
|
||||
use futures_util::Stream;
|
||||
use bytemuck::{Pod, Zeroable, bytes_of_mut};
|
||||
use rnex_core::prudp::types_flags::TypesFlags;
|
||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
||||
|
|
@ -30,10 +29,10 @@ pub enum PacketSpecificData {
|
|||
|
||||
impl PacketSpecificData {
|
||||
fn consume(reader: &mut impl Read) -> io::Result<Self> {
|
||||
let mut option_id = 0;
|
||||
reader.read_exact(&mut [option_id])?;
|
||||
let mut size = 0;
|
||||
reader.read_exact(&mut [size])?;
|
||||
let mut option_id = 0u8;
|
||||
reader.read_exact(bytes_of_mut(&mut option_id))?;
|
||||
let mut size = 0u8;
|
||||
reader.read_exact(bytes_of_mut(&mut size))?;
|
||||
|
||||
match option_id {
|
||||
0 => {
|
||||
|
|
@ -156,7 +155,7 @@ impl<T: AsRef<[u8]>> LitePacket<T> {
|
|||
.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()
|
||||
.map(Cursor::new)
|
||||
.map(PacketSpecificIter)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{io::Write, rc::Rc};
|
||||
use std::io::Write;
|
||||
|
||||
use hmac::Mac;
|
||||
use md5::{Digest, Md5};
|
||||
|
|
@ -18,6 +18,7 @@ use crate::crypto::{
|
|||
pub struct InsecureInstance {
|
||||
pair: EncryptionPair<Rc4<U5>>,
|
||||
self_signat: [u8; 4],
|
||||
#[allow(dead_code)]
|
||||
remote_signat: [u8; 4],
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +63,7 @@ impl Crypto for Insecure {
|
|||
|
||||
fn instantiate(
|
||||
&self,
|
||||
packet_data: &[u8],
|
||||
_packet_data: &[u8],
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
) -> Option<(Self::Instance, Vec<u8>)> {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ pub struct SecureInstance {
|
|||
pair: EncryptionPair<Rc4<U16>>,
|
||||
uid: u32,
|
||||
self_signat: [u8; 4],
|
||||
#[allow(dead_code)]
|
||||
remote_signat: [u8; 4],
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,13 @@
|
|||
cfg_if::cfg_if! {
|
||||
use cfg_if::cfg_if;
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "prudpv0")] {
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use cfg_if::cfg_if;
|
||||
use log::{error, info, warn};
|
||||
use proxy_common::{ProxyStartupParam, setup_edge_node_connection};
|
||||
use rnex_core::executables::common::{OWN_IP_PRIVATE, OWN_IP_PUBLIC, SERVER_PORT};
|
||||
use rnex_core::prudp::types_flags::TypesFlags;
|
||||
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 log::info;
|
||||
use proxy_common::ProxyStartupParam;
|
||||
use std::env;
|
||||
use std::net::SocketAddrV4;
|
||||
use std::process::abort;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
use tokio::net::UdpSocket;
|
||||
|
||||
use crate::crypto::{Crypto, Insecure, Secure};
|
||||
use crate::packet::PRUDPV0Packet;
|
||||
use crate::server::Server;
|
||||
|
||||
mod crypto;
|
||||
|
|
@ -44,8 +31,6 @@ cfg_if::cfg_if! {
|
|||
//implementations, e.g. secure and insecure(this also includes special cases like friends)
|
||||
|
||||
async fn start_proxy<T: Crypto>(param: ProxyStartupParam) {
|
||||
info!("creating cryptography instance");
|
||||
let mut crypto = Arc::new(T::new());
|
||||
info!("binding to socket");
|
||||
|
||||
let server: Arc<Server<T>> = Arc::new(Server::new(param).await);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
use std::mem::transmute;
|
||||
|
||||
use bytemuck::{Pod, Zeroable, try_from_bytes, try_from_bytes_mut};
|
||||
use log::{error, info, warn};
|
||||
use log::{info, warn};
|
||||
use rnex_core::prudp::{
|
||||
types_flags::{
|
||||
self, TypesFlags,
|
||||
flags::{HAS_SIZE, NEED_ACK},
|
||||
TypesFlags,
|
||||
flags::HAS_SIZE,
|
||||
types::{CONNECT, DATA, DISCONNECT, PING, SYN},
|
||||
},
|
||||
virtual_port::VirtualPort,
|
||||
|
|
@ -165,6 +163,7 @@ impl<T: AsRef<[u8]>> PRUDPV0Packet<T> {
|
|||
|
||||
const DEFAULT_SIGNAT: [u8; 4] = [0x12, 0x34, 0x56, 0x78];
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
const fn get_size_offset(tf: TypesFlags) -> usize {
|
||||
size_of::<PRUDPV0Header>()
|
||||
+ (if tf.get_types() & (SYN | CONNECT) != 0 {
|
||||
|
|
|
|||
|
|
@ -1,32 +1,24 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
hash::Hash,
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
sync::{
|
||||
Arc, LazyLock, Weak,
|
||||
atomic::{AtomicBool, AtomicU32},
|
||||
},
|
||||
net::{SocketAddr, SocketAddrV4},
|
||||
sync::{Arc, Weak},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use log::{error, info, warn};
|
||||
use proxy_common::{ProxyStartupParam, new_backend_connection};
|
||||
use rnex_core::{
|
||||
executables::common::{OWN_IP_PRIVATE, SERVER_PORT},
|
||||
prudp::{
|
||||
socket_addr::PRUDPSockAddr,
|
||||
types_flags::{
|
||||
TypesFlags,
|
||||
flags::{ACK, HAS_SIZE, NEED_ACK, RELIABLE},
|
||||
flags::{ACK, NEED_ACK, RELIABLE},
|
||||
types::{CONNECT, DATA, DISCONNECT, PING, SYN},
|
||||
},
|
||||
virtual_port::VirtualPort,
|
||||
},
|
||||
rnex_proxy_common::ConnectionInitData,
|
||||
util::{SendingBufferConnection, SplittableBufferConnection},
|
||||
};
|
||||
use tokio::{
|
||||
net::{TcpSocket, UdpSocket},
|
||||
net::UdpSocket,
|
||||
spawn,
|
||||
sync::{Mutex, RwLock},
|
||||
time::{Instant, sleep},
|
||||
|
|
@ -35,8 +27,8 @@ use tokio::{
|
|||
use crate::{
|
||||
crypto::{Crypto, CryptoInstance},
|
||||
packet::{
|
||||
PRUDPV0Header, PRUDPV0Packet, new_connect_packet, new_data_packet, new_disconnect_packet,
|
||||
new_ping_packet, new_syn_packet, precalc_size,
|
||||
PRUDPV0Packet, new_connect_packet, new_data_packet, new_disconnect_packet, new_ping_packet,
|
||||
new_syn_packet,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -49,16 +41,14 @@ pub struct InternalConnection<C: CryptoInstance> {
|
|||
packet_queue: HashMap<u16, (Instant, PRUDPV0Packet<Vec<u8>>)>,
|
||||
}
|
||||
pub struct Connection<C: CryptoInstance> {
|
||||
alive: AtomicBool,
|
||||
session_id: u8,
|
||||
target: SendingBufferConnection,
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
addr: PRUDPSockAddr,
|
||||
inner: Mutex<InternalConnection<C>>,
|
||||
}
|
||||
|
||||
impl<C: CryptoInstance> InternalConnection<C> {
|
||||
#[allow(dead_code)]
|
||||
fn next_server_count(&mut self) -> u16 {
|
||||
let prev_val = self.server_packet_counter;
|
||||
let (val, _) = self.server_packet_counter.overflowing_add(1);
|
||||
|
|
@ -148,7 +138,8 @@ impl<C: Crypto> Server<C> {
|
|||
|
||||
this.socket
|
||||
.send_to(&data, conn.addr.regular_socket_addr)
|
||||
.await;
|
||||
.await
|
||||
.ok();
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -192,7 +183,8 @@ impl<C: Crypto> Server<C> {
|
|||
|
||||
self.socket
|
||||
.send_to(&packet, conn.addr.regular_socket_addr)
|
||||
.await;
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
|
||||
if (Instant::now() - inner.last_action).as_secs() > 15 {
|
||||
|
|
@ -210,13 +202,16 @@ impl<C: Crypto> Server<C> {
|
|||
|
||||
self.socket
|
||||
.send_to(&packet, conn.addr.regular_socket_addr)
|
||||
.await;
|
||||
.await
|
||||
.ok();
|
||||
self.socket
|
||||
.send_to(&packet, conn.addr.regular_socket_addr)
|
||||
.await;
|
||||
.await
|
||||
.ok();
|
||||
self.socket
|
||||
.send_to(&packet, conn.addr.regular_socket_addr)
|
||||
.await;
|
||||
.await
|
||||
.ok();
|
||||
drop(inner);
|
||||
|
||||
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 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) {
|
||||
let Some(data) = packet.payload() else {
|
||||
|
|
@ -275,11 +273,8 @@ impl<C: Crypto> Server<C> {
|
|||
|
||||
let conn = Arc::new(Connection {
|
||||
target: buf_conn.duplicate_sender(),
|
||||
remote_signat,
|
||||
self_signat,
|
||||
addr,
|
||||
session_id: header.session_id,
|
||||
alive: AtomicBool::new(true),
|
||||
inner: Mutex::new(InternalConnection {
|
||||
last_action: Instant::now(),
|
||||
crypto_instance: ci,
|
||||
|
|
@ -320,9 +315,12 @@ impl<C: Crypto> Server<C> {
|
|||
);
|
||||
|
||||
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 {
|
||||
warn!("invalid packet from: {:?}", addr);
|
||||
return;
|
||||
|
|
@ -349,7 +347,10 @@ impl<C: Crypto> Server<C> {
|
|||
&mut conn.crypto_instance,
|
||||
&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(
|
||||
packet.header().unwrap().sequence_id,
|
||||
(Instant::now(), packet),
|
||||
|
|
@ -375,7 +376,7 @@ impl<C: Crypto> Server<C> {
|
|||
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");
|
||||
let header = packet.header().unwrap();
|
||||
|
||||
|
|
@ -395,11 +396,14 @@ impl<C: Crypto> Server<C> {
|
|||
);
|
||||
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(
|
||||
self: Arc<Self>,
|
||||
mut packet: PRUDPV0Packet<Vec<u8>>,
|
||||
packet: PRUDPV0Packet<Vec<u8>>,
|
||||
addr: PRUDPSockAddr,
|
||||
) {
|
||||
info!("got disconnect");
|
||||
|
|
@ -425,9 +429,18 @@ impl<C: Crypto> Server<C> {
|
|||
conns.remove(&(addr, header.session_id));
|
||||
drop(conns);
|
||||
|
||||
self.socket.send_to(&packet, addr.regular_socket_addr).await;
|
||||
self.socket.send_to(&packet, addr.regular_socket_addr).await;
|
||||
self.socket.send_to(&packet, addr.regular_socket_addr).await;
|
||||
self.socket
|
||||
.send_to(&packet, addr.regular_socket_addr)
|
||||
.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(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,6 @@
|
|||
use cfg_if::cfg_if;
|
||||
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::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]
|
||||
async fn main() {
|
||||
|
|
|
|||
|
|
@ -8,15 +8,11 @@ use log::error;
|
|||
use tokio::net::TcpListener;
|
||||
|
||||
use crate::{
|
||||
executables::common::{OWN_IP_PRIVATE, SERVER_PORT, new_simple_backend},
|
||||
nex::friends_handler::{
|
||||
FriendsGuest, FriendsManager, FriendsUser, RemoteFriendRemote, RemoteFriendsUser,
|
||||
},
|
||||
executables::common::{OWN_IP_PRIVATE, SERVER_PORT},
|
||||
nex::friends_handler::{FriendsGuest, FriendsManager, FriendsUser, RemoteFriendRemote},
|
||||
reggie::UnitPacketRead,
|
||||
rmc::{
|
||||
protocols::{
|
||||
RmcCallable, RmcPureRemoteObject, friends::RemoteFriends, new_rmc_gateway_connection,
|
||||
},
|
||||
protocols::{RmcPureRemoteObject, new_rmc_gateway_connection},
|
||||
structures::RmcSerialize,
|
||||
},
|
||||
rnex_proxy_common::ConnectionInitData,
|
||||
|
|
@ -65,8 +61,8 @@ pub async fn start_friends_backend() {
|
|||
})
|
||||
});
|
||||
} else {
|
||||
new_rmc_gateway_connection(stream.into(), move |r| {
|
||||
Arc::new_cyclic(move |this| FriendsGuest {
|
||||
new_rmc_gateway_connection(stream.into(), move |_| {
|
||||
Arc::new_cyclic(move |_| FriendsGuest {
|
||||
fm,
|
||||
addr: c.prudpsock_addr,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,3 +1,10 @@
|
|||
use cfg_if::cfg_if;
|
||||
|
||||
pub mod common;
|
||||
pub mod friends_backend;
|
||||
pub mod regular_backend;
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "friends")]{
|
||||
pub mod friends_backend;
|
||||
} else {
|
||||
pub mod regular_backend;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ use rnex_core::PID;
|
|||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "friends")]{
|
||||
pub type SESSION_KEY_LENGTH_TY = U16;
|
||||
pub type SessionLengthTy = U16;
|
||||
} else {
|
||||
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>;
|
||||
|
||||
|
|
|
|||
|
|
@ -337,82 +337,3 @@ impl Auth for AuthHandler {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ impl Friends for FriendsUser {
|
|||
|
||||
async fn delete_persistent_notification(
|
||||
&self,
|
||||
notifs: Vec<PersistentNotification>,
|
||||
_notifs: Vec<PersistentNotification>,
|
||||
) -> Result<(), ErrorCode> {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
use cfg_if::cfg_if;
|
||||
|
||||
pub mod account;
|
||||
pub mod auth_handler;
|
||||
pub mod common;
|
||||
pub mod friends_handler;
|
||||
pub mod matchmake;
|
||||
pub mod remote_console;
|
||||
pub mod user;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "friends")]{
|
||||
pub mod friends_handler;
|
||||
} else {
|
||||
pub mod matchmake;
|
||||
pub mod remote_console;
|
||||
pub mod user;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use typenum::U16;
|
|||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
||||
use crate::{
|
||||
kerberos::{SESSION_KEY_LENGTH, SESSION_KEY_LENGTH_TY, TicketInternalData, derive_key},
|
||||
kerberos::{SESSION_KEY_LENGTH, SessionLengthTy, TicketInternalData, derive_key},
|
||||
nex::account::Account,
|
||||
rmc::structures::RmcSerialize,
|
||||
};
|
||||
|
|
@ -53,7 +53,7 @@ pub fn read_secure_connection_data(
|
|||
let request_data_length = request_data.len();
|
||||
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.apply_keystream(request_data);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
use bytemuck::{Pod, Zeroable};
|
||||
use std::{
|
||||
fmt::{Debug, Formatter},
|
||||
slice,
|
||||
};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use v_byte_helpers::SwapEndian;
|
||||
|
||||
#[repr(transparent)]
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ use rnex_core::rmc::structures::qresult::QResult;
|
|||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "nx")]{
|
||||
type LOGIN_EX_RET = (QResult, PID, Vec<u8>, ConnectionData, String, String);
|
||||
type REQUEST_TICKET_RET = (QResult, Vec<u8>, String);
|
||||
type LoginExRet = (QResult, PID, Vec<u8>, ConnectionData, String, String);
|
||||
type RequestTicketRet = (QResult, Vec<u8>, String);
|
||||
} else {
|
||||
type LOGIN_EX_RET = (QResult, PID, Vec<u8>, ConnectionData, String);
|
||||
type REQUEST_TICKET_RET = (QResult, Vec<u8>);
|
||||
type LoginExRet = (QResult, PID, Vec<u8>, ConnectionData, String);
|
||||
type RequestTicketRet = (QResult, Vec<u8>);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,14 +31,14 @@ pub trait Auth {
|
|||
/// representation of the `LoginEx` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
#[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)]
|
||||
async fn request_ticket(
|
||||
&self,
|
||||
source_pid: PID,
|
||||
destination_pid: PID,
|
||||
) -> Result<REQUEST_TICKET_RET, ErrorCode>;
|
||||
) -> Result<RequestTicketRet, ErrorCode>;
|
||||
|
||||
/// representation of the `RequestTicket` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use macros::{RmcSerialize, method_id, rmc_proto};
|
|||
|
||||
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)]
|
||||
#[rmc_struct(0)]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use macros::{RmcSerialize, method_id, rmc_proto, rmc_struct};
|
||||
use macros::{RmcSerialize, method_id, rmc_proto};
|
||||
|
||||
use rnex_core::PID;
|
||||
|
||||
|
|
|
|||
|
|
@ -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::rmc::structures::qbuffer::QBuffer;
|
||||
|
|
@ -8,9 +8,9 @@ use rnex_core::rmc::structures::ranking::UploadCompetitionData;
|
|||
|
||||
#[derive(RmcSerialize, Debug, Default, Clone)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct ResultsRange{
|
||||
pub struct ResultsRange {
|
||||
pub offset: u32,
|
||||
pub size: u32
|
||||
pub size: u32,
|
||||
}
|
||||
|
||||
#[derive(RmcSerialize, Debug, Default, Clone)]
|
||||
|
|
@ -23,29 +23,35 @@ pub struct CompetitionRankingGetParam {
|
|||
|
||||
#[derive(RmcSerialize, Debug, Default, Clone)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct CompetitionRankingScoreInfo{
|
||||
pub struct CompetitionRankingScoreInfo {
|
||||
pub fest_id: u32,
|
||||
pub score_data: Vec<CompetitionRankingScoreData>,
|
||||
pub unk: u32,
|
||||
pub team_wins: Vec<u32>,
|
||||
pub team_votes: Vec<u32>
|
||||
pub team_votes: Vec<u32>,
|
||||
}
|
||||
|
||||
#[derive(RmcSerialize, Debug, Clone)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct CompetitionRankingScoreData{
|
||||
pub struct CompetitionRankingScoreData {
|
||||
pub unk: u32,
|
||||
pub pid: u32,
|
||||
pub score: u32,
|
||||
pub modified: KerberosDateTime,
|
||||
pub unk2: u8,
|
||||
pub appdata: QBuffer
|
||||
pub appdata: QBuffer,
|
||||
}
|
||||
|
||||
#[rmc_proto(112)]
|
||||
pub trait Ranking{
|
||||
pub trait Ranking {
|
||||
#[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)]
|
||||
async fn upload_competition_ranking_score(&self, param: UploadCompetitionData) -> Result<bool, ErrorCode>;
|
||||
async fn upload_competition_ranking_score(
|
||||
&self,
|
||||
param: UploadCompetitionData,
|
||||
) -> Result<bool, ErrorCode>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue