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,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>)> {

View file

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

View file

@ -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);

View file

@ -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 {

View file

@ -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,