chore: fix warnings

This commit is contained in:
DJMrTV 2025-02-01 17:31:13 +01:00
commit ce81f09a85
12 changed files with 49 additions and 76 deletions

View file

@ -1,5 +1,4 @@
use std::net::Ipv4Addr;
use rc4::Rc4;
pub trait AuthModule{
fn get_auth_key(addr: Ipv4Addr) -> [u8; 32];

View file

@ -1,7 +1,11 @@
// no clue why this produces a warning where `#[repr(u16)]` is below,
// the thing is says to do also breaks the code, so we just
// force the compiler to shut up here
#![allow(unused_parens)]
use std::fmt::{Debug, Formatter};
use std::hint::unreachable_unchecked;
use std::io;
use std::io::{Cursor, ErrorKind, Read, Seek, Write};
use std::io::{Cursor, Read, Seek, Write};
use std::net::SocketAddrV4;
use bytemuck::{Pod, Zeroable};
use hmac::{Hmac, Mac};
@ -9,7 +13,7 @@ use log::{error, trace, warn};
use md5::{Md5, Digest};
use thiserror::Error;
use v_byte_macros::{EnumTryInto, SwapEndian};
use crate::endianness::{IS_BIG_ENDIAN, IS_LITTLE_ENDIAN, ReadExtensions};
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use crate::prudp::packet::flags::ACK;
use crate::prudp::packet::PacketOption::{ConnectionSignature, FragmentId, InitialSequenceId, MaximumSubstreamId, SupportedFunctions};
use crate::prudp::sockaddr::PRUDPSockAddr;
@ -103,7 +107,7 @@ impl VirtualPort {
#[inline]
pub const fn get_port_number(self) -> u8 {
(self.0 & 0x0F)
self.0 & 0x0F
}
#[inline]
@ -168,8 +172,10 @@ impl Default for PRUDPHeader{
}
}
#[repr(u16)]
#[derive(EnumTryInto)]
#[repr(u16)]
enum PacketSpecificData {
E = 0x10
}

View file

@ -1,24 +1,19 @@
use std::{env, io, thread};
use std::cell::OnceCell;
use std::{env, io};
use std::io::Cursor;
use std::marker::PhantomData;
use tokio::net::UdpSocket;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use std::net::{SocketAddr, SocketAddrV4};
use std::net::SocketAddr::V4;
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, OnceLock};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use tokio::task::JoinHandle;
use once_cell::sync::Lazy;
use log::{error, info, trace, warn};
use log::{error, info, trace};
use thiserror::Error;
use tokio::io::Join;
use tokio::sync::RwLock;
use crate::prudp::auth_module::AuthModule;
use crate::prudp::socket::{Socket, SocketData};
use crate::prudp::socket::SocketData;
use crate::prudp::packet::{PRUDPPacket, VirtualPort};
use crate::prudp::router::Error::VirtualPortTaken;
use crate::prudp::sockaddr::PRUDPSockAddr;
static SERVER_DATAGRAMS: Lazy<u8> = Lazy::new(||{
env::var("SERVER_DATAGRAM_COUNT").ok()
@ -41,10 +36,10 @@ pub enum Error{
impl Router {
fn process_prudp_packet(&self, packet: &PRUDPPacket){
fn process_prudp_packet(&self, _packet: &PRUDPPacket){
}
async fn process_prudp_packets<'a>(self: Arc<Self>, socket: Arc<UdpSocket>, addr: SocketAddrV4, udp_message: Vec<u8>){
async fn process_prudp_packets<'a>(self: Arc<Self>, _socket: Arc<UdpSocket>, addr: SocketAddrV4, udp_message: Vec<u8>){
let mut stream = Cursor::new(&udp_message);
while stream.position() as usize != udp_message.len() {
@ -124,8 +119,8 @@ impl Router {
};
{
let socket = socket.clone();
let server= arc.clone();
let _socket = socket.clone();
let _server = arc.clone();
tokio::spawn(async {
//server thread sender entry

View file

@ -1,30 +1,19 @@
use std::array;
use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::io::Write;
use std::ops::Deref;
use std::pin::Pin;
use tokio::net::UdpSocket;
use std::sync::{Arc};
use tokio::sync::{Mutex, MutexGuard, RwLock};
use hmac::{Hmac, Mac};
use log::{error, info, trace, warn};
use rand::random;
use rc4::consts::{U256, U5};
use rc4::{Rc4, Rc4Core, StreamCipher};
use rc4::cipher::{KeySizeUser, StreamCipherCoreWrapper};
use rustls::internal::msgs::handshake::SessionId;
use tokio::io::AsyncWriteExt;
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::task::JoinHandle;
use tokio_stream::wrappers::ReceiverStream;
use crate::prudp::packet::{flags, PacketOption, PRUDPPacket, types, VirtualPort};
use rc4::StreamCipher;
use crate::prudp::packet::{PacketOption, PRUDPPacket, VirtualPort};
use crate::prudp::packet::flags::{ACK, HAS_SIZE, MULTI_ACK, NEED_ACK, RELIABLE};
use crate::prudp::packet::PacketOption::{ConnectionSignature, MaximumSubstreamId, SupportedFunctions};
use crate::prudp::packet::types::{CONNECT, DATA, PING, SYN};
use crate::prudp::router::{Error, Router};
use crate::prudp::sockaddr::PRUDPSockAddr;
use rc4::KeyInit;
// due to the way this is designed crashing the router thread causes deadlock, sorry ;-;
@ -53,7 +42,6 @@ pub struct ActiveConnectionData {
pub reliable_client_counter: u16,
pub reliable_server_counter: u16,
pub reliable_client_queue: VecDeque<PRUDPPacket>,
pub connection_data_channel: Sender<Vec<u8>>,
server_encryption: Box<dyn StreamCipher + Send + Sync>,
client_decryption: Box<dyn StreamCipher + Send + Sync>,
pub server_session_id: u8,
@ -237,7 +225,7 @@ impl SocketData {
response_packet.options.push(ConnectionSignature(Default::default()));
let mut init_seq_id = 0;
//let mut init_seq_id = 0;
for option in &packet.options {
match option {
@ -246,8 +234,8 @@ impl SocketData {
ConnectionSignature(sig) => {
connection.server_signature = *sig
}
PacketOption::InitialSequenceId(id) => {
init_seq_id = *id;
PacketOption::InitialSequenceId(_id) => {
//init_seq_id = *id;
}
_ => { /* ? */ }
}
@ -272,8 +260,6 @@ impl SocketData {
self.socket.send_to(&vec, client_address.regular_socket_addr).await.expect("failed to send data back");
let (send, recv) = channel(100);
let (accepted, (client_decryption, server_encryption))
= (self.on_connect_handler)(packet.clone()).await;
@ -283,7 +269,6 @@ impl SocketData {
}
connection.active_connection_data = Some(ActiveConnectionData {
connection_data_channel: send,
client_decryption,
server_encryption,
reliable_client_queue: VecDeque::new(),
@ -328,7 +313,7 @@ impl SocketData {
.then(|| a.reliable_client_queue.pop_front())).flatten().flatten()
} {
if packet.options.iter().any(|v| match v{
PacketOption::FragmentId(f) => (*f != 0),
PacketOption::FragmentId(f) => *f != 0,
_ => false,
}){
error!("fragmented packets are unsupported right now")