chore: fix warnings
This commit is contained in:
parent
730234c3bf
commit
ce81f09a85
12 changed files with 49 additions and 76 deletions
|
|
@ -1,9 +1,7 @@
|
|||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
use bytemuck::Pod;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||
|
||||
#[cfg(target_endian = "little")]
|
||||
pub const IS_LITTLE_ENDIAN: bool = true;
|
||||
|
|
@ -212,7 +210,7 @@ impl<T: SwapEndian, U: SwapEndian, V: SwapEndian, W: SwapEndian> SwapEndian for
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: SwapEndian, const size: usize> SwapEndian for [T; size]{
|
||||
impl<T: SwapEndian, const SIZE: usize> SwapEndian for [T; SIZE]{
|
||||
#[inline]
|
||||
fn swap_endian(mut self) -> Self {
|
||||
for elem in &mut self{
|
||||
|
|
|
|||
13
src/main.rs
13
src/main.rs
|
|
@ -1,23 +1,20 @@
|
|||
use std::env::current_dir;
|
||||
use std::{env, fs};
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{env, fs};
|
||||
use std::fs::File;
|
||||
use std::io::Cursor;
|
||||
use std::net::{Ipv4Addr, SocketAddrV4};
|
||||
use chrono::Local;
|
||||
use log::{error, info, trace};
|
||||
use log::info;
|
||||
use once_cell::sync::Lazy;
|
||||
use rc4::{KeyInit, Rc4, StreamCipher};
|
||||
use rc4::consts::U5;
|
||||
use simplelog::{ColorChoice, CombinedLogger, Config, LevelFilter, TerminalMode, TermLogger, WriteLogger};
|
||||
use crate::protocols::auth;
|
||||
use crate::protocols::server::RMCProtocolServer;
|
||||
use crate::prudp::socket::{Socket, SocketData};
|
||||
use crate::prudp::socket::Socket;
|
||||
use crate::prudp::packet::{PRUDPPacket, VirtualPort};
|
||||
use crate::prudp::router::Router;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{RMCResponse, RMCResponseResult, send_response};
|
||||
use crate::rmc::response::ErrorCode::{Core_InvalidIndex, Core_NotImplemented};
|
||||
|
||||
mod endianness;
|
||||
mod prudp;
|
||||
|
|
@ -55,7 +52,7 @@ async fn main() {
|
|||
start_servers().await;
|
||||
}
|
||||
|
||||
async fn auth_server_handle_rmc(packet: PRUDPPacket, rmc_message: RMCMessage){
|
||||
async fn auth_server_handle_rmc(_packet: PRUDPPacket, _rmc_message: RMCMessage){
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::io::Cursor;
|
||||
use log::{error, info};
|
||||
use log::error;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponse, RMCResponseResult};
|
||||
use crate::rmc::structures::{string, any, RmcSerialize};
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::structures::{RmcSerialize};
|
||||
use crate::rmc::structures::any::Any;
|
||||
|
||||
pub fn login_ex(name: &str) -> RMCResponseResult{
|
||||
pub fn login_ex(_name: &str) -> RMCResponseResult{
|
||||
// todo: figure out how the AuthenticationInfo struct works, parse it and validate login info
|
||||
|
||||
//return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
|
|
@ -15,7 +15,7 @@ pub fn login_ex(name: &str) -> RMCResponseResult{
|
|||
pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(str) = String::deserialize(&mut reader) else {
|
||||
let Ok(_str) = String::deserialize(&mut reader) else {
|
||||
error!("error reading packet");
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
mod method_login_ex;
|
||||
|
||||
use log::{error, info};
|
||||
use log::{error};
|
||||
use crate::define_protocol;
|
||||
use crate::protocols::auth::method_login_ex::{login_ex, login_ex_raw_params};
|
||||
use crate::protocols::auth::method_login_ex::{ login_ex_raw_params};
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponse, RMCResponseResult};
|
||||
use crate::rmc::response::{ErrorCode, RMCResponse};
|
||||
|
||||
|
||||
define_protocol!{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use rc4::Rc4;
|
||||
|
||||
pub trait AuthModule{
|
||||
fn get_auth_key(addr: Ipv4Addr) -> [u8; 32];
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
use std::io;
|
||||
use std::io::{Cursor, Write};
|
||||
use std::io::{Write};
|
||||
use std::mem::transmute;
|
||||
use tokio::sync::Mutex;
|
||||
use bytemuck::bytes_of;
|
||||
use hmac::digest::consts::U5;
|
||||
use hmac::digest::KeyInit;
|
||||
use rc4::{Rc4, StreamCipher};
|
||||
use crate::prudp::packet::{PRUDPHeader, PRUDPPacket, TypesFlags};
|
||||
use crate::prudp::packet::flags::{HAS_SIZE, NEED_ACK, RELIABLE};
|
||||
use crate::prudp::packet::{PRUDPPacket};
|
||||
use crate::prudp::packet::flags::{NEED_ACK, RELIABLE};
|
||||
use crate::prudp::packet::PacketOption::FragmentId;
|
||||
use crate::prudp::packet::types::DATA;
|
||||
use crate::prudp::socket::{ConnectionData, SocketData};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::io::{Read, Seek, Write};
|
||||
use std::io::{Read, Write};
|
||||
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
use super::{string, Result, RmcSerialize};
|
||||
use super::{Result, RmcSerialize};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Any{
|
||||
|
|
@ -9,14 +9,14 @@ pub struct Any{
|
|||
}
|
||||
|
||||
impl RmcSerialize for Any{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> Result<()> {
|
||||
fn serialize(&self, _writer: &mut dyn Write) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
fn deserialize(mut reader: &mut dyn Read) -> Result<Self> {
|
||||
let name = String::deserialize(reader)?;
|
||||
|
||||
// also length ?
|
||||
let len2: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
let _len2: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
let length: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
|
||||
let mut data = vec![0; length as usize];
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use std::io;
|
||||
use std::io::{Read, Seek, Write};
|
||||
use std::str::Utf8Error;
|
||||
use std::io::{Read, Write};
|
||||
use std::string::FromUtf8Error;
|
||||
use md5::digest::impl_oid_carrier;
|
||||
use thiserror::Error;
|
||||
|
||||
//ideas for the future: make a proc macro library which allows generation of struct reads
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use std::ffi::CString;
|
||||
use std::io::{Read, Seek, Write};
|
||||
use std::io::{Read, Write};
|
||||
use bytemuck::bytes_of;
|
||||
use log::error;
|
||||
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue