This commit is contained in:
Maple 2025-09-21 15:59:27 +02:00
commit aab4414904
71 changed files with 293 additions and 4316 deletions

3712
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,91 +1,7 @@
[package]
name = "rust-nex"
version = "0.1.0"
edition = "2021"
[profile.prod]
inherits = "release"
overflow-checks = false
strip = true
debug = false
debug-assertions = false
lto = true
incremental = false
[dependencies]
bytemuck = { version = "1.21.0", features = ["derive"] }
dotenv = "0.15.0"
once_cell = "1.20.2"
rc4 = "0.1.0"
thiserror = "2.0.11"
v_byte_macros = { git = "https://github.com/DJMrTV/VByteMacros" }
simplelog = "0.12.2"
chrono = "0.4.39"
log = "0.4.25"
anyhow = "1.0.95"
rand = "0.8.5"
hmac = "0.12.1"
md-5 = "^0.10.6"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread", "net", "sync", "fs"] }
tokio-stream = { version = "0.1.17", features = ["io-util"] }
tonic = "0.12.3"
prost = "0.13.4"
hex = "0.4.3"
macros = { path = "macros" }
rocket = { version = "0.5.1", features = ["json", "serde_json"] }
serde = { version = "1.0.217", features = ["derive"] }
async-trait = "0.1.86"
paste = "1.0.15"
typenum = "1.18.0"
futures = "0.3.31"
reqwest = "0.12.18"
json = "0.12.4"
ctrlc = "3.4.7"
rsa = "0.9.8"
sha2 = "0.10.9"
chacha20 = "0.9.1"
rustls = "0.23.27"
rustls-pki-types = "1.12.0"
rustls-webpki = "0.103.3"
tokio-rustls = "0.26.2"
tokio-tungstenite = "0.27.0"
tungstenite = "0.27.0"
[build-dependencies]
tonic-build = "0.12.3"
[features]
default = ["secure", "auth"]
secure = []
auth = []
no_tls = []
[[bin]]
name = "proxy_insecure"
path = "src/executables/proxy_insecure.rs"
[[bin]]
name = "proxy_secure"
path = "src/executables/proxy_secure.rs"
[[bin]]
name = "backend_server_insecure"
path = "src/executables/backend_server_insecure.rs"
[[bin]]
name = "backend_server_secure"
path = "src/executables/backend_server_secure.rs"
[[bin]]
name = "edge_node_holder_server"
path = "src/executables/edge_node_holder_server.rs"
[workspace]
resolver = "3"
members = [
"macros",
"rnex-core",
"prudpv1"
]

12
bu Normal file
View file

@ -0,0 +1,12 @@
[build-dependencies]
tonic-build = "0.12.3"
[features]
default = ["secure", "auth"]
secure = []
auth = []
no_tls = []

View file

@ -65,7 +65,7 @@ fn gen_serialize_data_struct(
let ident = f.ident.as_ref().unwrap();
serialize_content.append_all(quote! {
self.#ident.serialize(writer)?;
rnex_core::rmc::structures::RmcSerialize::serialize(&self.#ident, writer)?;
})
}
@ -143,7 +143,7 @@ fn gen_serialize_data_struct(
quote! {
#pre_inner
rust_nex::rmc::structures::rmc_struct::write_struct(writer, #version, |mut writer|{
rnex_core::rmc::structures::rmc_struct::write_struct(writer, #version, |mut writer|{
#serialize_base_content
})?;
@ -176,7 +176,7 @@ fn gen_serialize_data_struct(
quote! {
#pre_inner
Ok(rust_nex::rmc::structures::rmc_struct::read_struct(reader, #version, move |mut reader|{
Ok(rnex_core::rmc::structures::rmc_struct::read_struct(reader, #version, move |mut reader|{
#deserialize_base_content
})?)
}
@ -235,7 +235,7 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
let name = &field.ident;
base.append_all(quote!{
#name: <#ty as rust_nex::rmc::structures::RmcSerialize>::deserialize(reader)?,
#name: <#ty as rnex_core::rmc::structures::RmcSerialize>::deserialize(reader)?,
});
}
@ -248,7 +248,7 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
let ty = &field.ty;
base.append_all(quote!{
<#ty as rust_nex::rmc::structures::RmcSerialize>::deserialize(reader)?,
<#ty as rnex_core::rmc::structures::RmcSerialize>::deserialize(reader)?,
});
}
@ -260,7 +260,7 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
};
let mut se_with_fields = quote! {
<#ty as rust_nex::rmc::structures::RmcSerialize>::serialize(&#val, writer)?;
<#ty as rnex_core::rmc::structures::RmcSerialize>::serialize(&#val, writer)?;
};
match &variant.fields {
@ -270,7 +270,7 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
let name = &field.ident;
se_with_fields.append_all(quote!{
<#ty as rust_nex::rmc::structures::RmcSerialize>::serialize(#name ,writer)?;
<#ty as rnex_core::rmc::structures::RmcSerialize>::serialize(#name ,writer)?;
});
}
}
@ -281,7 +281,7 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
let ident = Ident::new(&format!("val_{}", i), Span::call_site());
se_with_fields.append_all(quote!{
<#ty as rust_nex::rmc::structures::RmcSerialize>::serialize(#ident, writer)?;
<#ty as rnex_core::rmc::structures::RmcSerialize>::serialize(#ident, writer)?;
});
}
}
@ -344,9 +344,9 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
};
let deserialize_base_content = quote! {
let val: Self = match <#ty as rust_nex::rmc::structures::RmcSerialize>::deserialize(reader)?{
let val: Self = match <#ty as rnex_core::rmc::structures::RmcSerialize>::deserialize(reader)?{
#inner_match_de
v => return Err(rust_nex::rmc::structures::Error::UnexpectedValue(v as _))
v => return Err(rnex_core::rmc::structures::Error::UnexpectedValue(v as _))
};
Ok(val)
@ -364,14 +364,14 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
let ident = derive_input.ident;
let tokens = quote! {
impl rust_nex::rmc::structures::RmcSerialize for #ident{
fn serialize(&self, writer: &mut dyn ::std::io::Write) -> rust_nex::rmc::structures::Result<()>{
impl rnex_core::rmc::structures::RmcSerialize for #ident{
fn serialize(&self, writer: &mut dyn ::std::io::Write) -> rnex_core::rmc::structures::Result<()>{
#serialize_base_content
}
fn deserialize(reader: &mut dyn ::std::io::Read) -> rust_nex::rmc::structures::Result<Self>{
fn deserialize(reader: &mut dyn ::std::io::Read) -> rnex_core::rmc::structures::Result<Self>{
#deserialize_base_content
}
}
@ -511,8 +511,8 @@ pub fn rmc_struct(attr: TokenStream, input: TokenStream) -> TokenStream {
}
impl rust_nex::rmc::protocols::RmcCallable for #struct_name{
async fn rmc_call(&self, remote_response_connection: &rust_nex::util::SendingBufferConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>){
impl rnex_core::rmc::protocols::RmcCallable for #struct_name{
async fn rmc_call(&self, remote_response_connection: &rnex_core::util::SendingBufferConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>){
<Self as #ident>::rmc_call(self, remote_response_connection, protocol_id, method_id, call_id, rest).await;
}
}

View file

@ -73,7 +73,7 @@ impl RmcProtocolData{
for (param_name, param_type) in parameters{
quote!{
let Ok(#param_name) =
<#param_type as rust_nex::rmc::structures::RmcSerialize>::deserialize(
<#param_type as rnex_core::rmc::structures::RmcSerialize>::deserialize(
&mut cursor
) else
}.to_tokens(tokens);
@ -84,7 +84,7 @@ impl RmcProtocolData{
quote! {
{
log::error!(#error_msg);
return Err(rust_nex::rmc::response::ErrorCode::Core_InvalidArgument);
return Err(rnex_core::rmc::response::ErrorCode::Core_InvalidArgument);
};
}.to_tokens(tokens)
} else {
@ -116,7 +116,7 @@ impl RmcProtocolData{
quote!{
let retval = retval?;
let mut vec = Vec::new();
rust_nex::rmc::structures::RmcSerialize::serialize(&retval, &mut vec).ok();
rnex_core::rmc::structures::RmcSerialize::serialize(&retval, &mut vec).ok();
Ok(vec)
}.to_tokens(tokens);
}
@ -126,7 +126,7 @@ impl RmcProtocolData{
quote!{
async fn rmc_call_proto(
&self,
remote_response_connection: &rust_nex::util::SendingBufferConnection,
remote_response_connection: &rnex_core::util::SendingBufferConnection,
method_id: u32,
call_id: u32,
data: Vec<u8>,
@ -165,7 +165,7 @@ impl RmcProtocolData{
}.to_tokens(tokens);
if self.has_returns {
quote! {
Err(rust_nex::rmc::response::ErrorCode::Core_NotImplemented)
Err(rnex_core::rmc::response::ErrorCode::Core_NotImplemented)
}.to_tokens(tokens);
}
});
@ -176,7 +176,7 @@ impl RmcProtocolData{
if *has_returns{
quote!{
rust_nex::rmc::response::send_result(
rnex_core::rmc::response::send_result(
remote_response_connection,
ret,
#id,
@ -209,7 +209,7 @@ impl RmcProtocolData{
// boilerplate tokens which all raw traits need
quote!{
#[doc(hidden)]
pub trait #remote_name: rust_nex::rmc::protocols::HasRmcConnection
pub trait #remote_name: rnex_core::rmc::protocols::HasRmcConnection
}.to_tokens(tokens);
// generate the body of the raw protocol trait
@ -247,12 +247,12 @@ impl RmcProtocolData{
for (param_name, param_type) in parameters{
quote!{
rust_nex::result::ResultExtension::display_err_or_some(
<#param_type as rust_nex::rmc::structures::RmcSerialize>::serialize(
rnex_core::result::ResultExtension::display_err_or_some(
<#param_type as rnex_core::rmc::structures::RmcSerialize>::serialize(
&#param_name,
&mut cursor
)
).ok_or(rust_nex::rmc::response::ErrorCode::Core_InvalidArgument)
).ok_or(rnex_core::rmc::response::ErrorCode::Core_InvalidArgument)
}.to_tokens(tokens);
if self.has_returns {
quote! {
@ -268,25 +268,25 @@ impl RmcProtocolData{
quote!{
let call_id = rand::random();
let message = rust_nex::rmc::message::RMCMessage{
let message = rnex_core::rmc::message::RMCMessage{
call_id,
method_id: #method_id,
protocol_id: #proto_id,
rest_of_data: send_data
};
let rmc_conn = <Self as rust_nex::rmc::protocols::HasRmcConnection>::get_connection(self);
let rmc_conn = <Self as rnex_core::rmc::protocols::HasRmcConnection>::get_connection(self);
}.to_tokens(tokens);
if *has_returns{
quote!{
rust_nex::result::ResultExtension::display_err_or_some(
rnex_core::result::ResultExtension::display_err_or_some(
rmc_conn.make_raw_call(&message).await
).ok_or(rust_nex::rmc::response::ErrorCode::Core_Exception)
).ok_or(rnex_core::rmc::response::ErrorCode::Core_Exception)
}.to_tokens(tokens);
} else {
quote!{
rust_nex::result::ResultExtension::display_err_or_some(
rnex_core::result::ResultExtension::display_err_or_some(
rmc_conn.make_raw_call_no_response(&message).await
);
}.to_tokens(tokens);

View file

@ -0,0 +1,18 @@
use std::env;
use std::net::SocketAddrV4;
use once_cell::sync::Lazy;
pub static EDGE_NODE_HOLDER: Lazy<SocketAddrV4> = Lazy::new(||{
env::var("EDGE_NODE_HOLDER")
.ok()
.and_then(|s| s.parse().ok())
.expect("EDGE_NODE_HOLDER not set")
});
pub static FORWARD_DESTINATION: Lazy<SocketAddrV4> =
Lazy::new(||
env::var("FORWARD_DESTINATION")
.ok()
.and_then(|s| s.parse().ok())
.expect("FORWARD_DESTINATION not set")
);

View file

@ -1,5 +1,7 @@
use rust_nex::reggie::RemoteEdgeNodeHolder;
use rnex_core::reggie::UnitPacketRead;
use rnex_core::reggie::UnitPacketWrite;
use rnex_core::rmc::structures::RmcSerialize;
use std::env;
use std::ffi::CStr;
use std::io::{Read, Write};
@ -7,35 +9,23 @@ use std::net::{Ipv4Addr, SocketAddrV4};
use std::sync::{Arc, OnceLock};
use std::time::Duration;
use bytemuck::{Pod, Zeroable};
use chacha20::{ChaCha20, Key};
use chacha20::cipher::{Iv, KeyIvInit, StreamCipher};
use log::{error, warn};
use macros::rmc_struct;
use once_cell::sync::Lazy;
use rsa::pkcs8::{DecodePrivateKey, DecodePublicKey, Document};
use rsa::{BigUint, Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};
use rsa::pkcs1::EncodeRsaPublicKey;
use rsa::pss::BlindedSigningKey;
use rsa::signature::{RandomizedSigner, SignatureEncoding};
use sha2::Sha256;
use tokio::net::{TcpSocket, TcpStream};
use tokio::sync::RwLock;
use tokio::task;
use tokio::time::sleep;
use rust_nex::common::setup;
use rust_nex::executables::common::{FORWARD_DESTINATION, OWN_IP_PRIVATE, OWN_IP_PUBLIC, SECURE_EDGE_NODE_HOLDER, SERVER_PORT};
use rust_nex::prudp::packet::VirtualPort;
use rust_nex::prudp::router::Router;
use rust_nex::prudp::station_url::StationUrl;
use rust_nex::prudp::unsecure::Unsecure;
use rust_nex::reggie::{UnitPacketRead, UnitPacketWrite};
use rust_nex::reggie::EdgeNodeHolderConnectOption::{DontRegister, Register};
use rust_nex::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rust_nex::rmc::response::ErrorCode;
use rust_nex::rmc::structures::RmcSerialize;
use rust_nex::rnex_proxy_common::ConnectionInitData;
use rust_nex::util::SplittableBufferConnection;
use prudpv1::executables::common::{FORWARD_DESTINATION, EDGE_NODE_HOLDER};
use prudpv1::prudp::router::Router;
use prudpv1::prudp::unsecure::Unsecure;
use rnex_core::common::setup;
use rnex_core::executables::common::{OWN_IP_PRIVATE, OWN_IP_PUBLIC, SERVER_PORT};
use rnex_core::prudp::virtual_port::VirtualPort;
use rnex_core::reggie::EdgeNodeHolderConnectOption::Register;
use rnex_core::reggie::RemoteEdgeNodeHolder;
use rnex_core::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_core::util::SplittableBufferConnection;
@ -43,7 +33,7 @@ use rust_nex::util::SplittableBufferConnection;
async fn main() {
setup();
let conn = tokio::net::TcpStream::connect(&*SECURE_EDGE_NODE_HOLDER).await.unwrap();
let conn = tokio::net::TcpStream::connect(&*EDGE_NODE_HOLDER).await.unwrap();
let conn: SplittableBufferConnection = conn.into();

View file

@ -1,35 +1,37 @@
use std::net::SocketAddrV4;
use std::sync::Arc;
use rnex_core::reggie::UnitPacketRead;
use rnex_core::reggie::UnitPacketWrite;
use rnex_core::rmc::structures::RmcSerialize;
use std::env;
use std::ffi::CStr;
use std::io::{Read, Write};
use std::net::{Ipv4Addr, SocketAddrV4};
use std::sync::{Arc, OnceLock};
use std::time::Duration;
use futures::future::Remote;
use bytemuck::{Pod, Zeroable};
use log::{error, warn};
use macros::rmc_struct;
use tokio::net::TcpStream;
use once_cell::sync::Lazy;
use tokio::net::{TcpSocket, TcpStream};
use tokio::sync::RwLock;
use tokio::task;
use tokio::time::sleep;
use tokio_rustls::client::TlsStream;
use tokio_tungstenite::MaybeTlsStream;
use rust_nex::common::setup;
use rust_nex::executables::common::{AUTH_SERVER_ACCOUNT, FORWARD_DESTINATION, OWN_IP_PRIVATE, OWN_IP_PUBLIC, SECURE_EDGE_NODE_HOLDER, SECURE_SERVER_ACCOUNT, SERVER_PORT};
use rust_nex::prudp::packet::VirtualPort;
use rust_nex::prudp::router::Router;
use rust_nex::prudp::secure::Secure;
use rust_nex::prudp::unsecure::Unsecure;
use rust_nex::reggie::EdgeNodeHolderConnectOption::{DontRegister, Register};
use rust_nex::rmc::response::ErrorCode;
use rust_nex::rnex_proxy_common::ConnectionInitData;
use rust_nex::reggie::{RemoteEdgeNodeHolder, UnitPacketWrite};
use rust_nex::rmc::structures::RmcSerialize;
use rust_nex::reggie::UnitPacketRead;
use rust_nex::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote, RemoteInstantiatable};
use rust_nex::util::SplittableBufferConnection;
use prudpv1::executables::common::{FORWARD_DESTINATION, EDGE_NODE_HOLDER};
use prudpv1::prudp::router::Router;
use prudpv1::prudp::secure::Secure;
use prudpv1::prudp::unsecure::Unsecure;
use rnex_core::common::setup;
use rnex_core::executables::common::{OWN_IP_PRIVATE, OWN_IP_PUBLIC, SECURE_SERVER_ACCOUNT, SERVER_PORT};
use rnex_core::prudp::virtual_port::VirtualPort;
use rnex_core::reggie::EdgeNodeHolderConnectOption::Register;
use rnex_core::reggie::RemoteEdgeNodeHolder;
use rnex_core::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_core::util::SplittableBufferConnection;
#[tokio::main]
async fn main() {
setup();
let conn = tokio::net::TcpStream::connect(&*SECURE_EDGE_NODE_HOLDER).await.unwrap();
let conn = tokio::net::TcpStream::connect(&*EDGE_NODE_HOLDER).await.unwrap();
let conn: SplittableBufferConnection = conn.into();

View file

@ -2,7 +2,5 @@ pub mod packet;
pub mod router;
pub mod socket;
mod auth_module;
pub mod sockaddr;
pub mod station_url;
pub mod secure;
pub mod unsecure;

View file

@ -12,11 +12,12 @@ use hmac::{Hmac, Mac};
use log::{error, warn};
use md5::{Md5, Digest};
use thiserror::Error;
use v_byte_macros::{SwapEndian};
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{SwapEndian};
use v_byte_helpers::{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;
use rnex_core::prudp::socket_addr::PRUDPSockAddr;
use rnex_core::prudp::virtual_port::VirtualPort;
type Md5Hmac = Hmac<Md5>;
@ -96,51 +97,7 @@ impl Debug for TypesFlags {
}
}
#[repr(transparent)]
#[derive(PartialEq, Eq, Ord, PartialOrd, Copy, Clone, Pod, Zeroable, SwapEndian, Hash)]
pub struct VirtualPort(pub(crate) u8);
impl VirtualPort {
#[inline]
pub const fn get_stream_type(self) -> u8 {
(self.0 & 0xF0) >> 4
}
#[inline]
pub const fn get_port_number(self) -> u8 {
self.0 & 0x0F
}
#[inline]
pub fn stream_type(self, val: u8) -> Self {
let masked_val = val & 0x0F;
assert_eq!(masked_val, val);
Self((self.0 & 0x0F) | (masked_val << 4))
}
#[inline]
pub fn port_number(self, val: u8) -> Self {
let masked_val = val & 0x0F;
assert_eq!(masked_val, val);
Self((self.0 & 0xF0) | masked_val)
}
#[inline]
pub fn new(port: u8, stream_type: u8) -> Self {
Self(0).stream_type(stream_type).port_number(port)
}
}
impl Debug for VirtualPort {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let stream_type = self.get_stream_type();
let port_number = self.get_port_number();
write!(f, "VirtualPort{{ stream_type: {}, port_number: {} }}", stream_type, port_number)
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, Pod, Zeroable, SwapEndian, Eq, PartialEq)]
@ -481,7 +438,8 @@ impl PRUDPV1Packet {
mod test {
use crate::prudp::packet::flags::{NEED_ACK, RELIABLE};
use crate::prudp::packet::types::DATA;
use super::{OptionId, PacketOption, PRUDPV1Header, TypesFlags, VirtualPort};
use super::{OptionId, PacketOption, PRUDPV1Header, TypesFlags};
use rnex_core::prudp::virtual_port::VirtualPort;
#[test]
fn size_test() {
assert_eq!(size_of::<PRUDPV1Header>(), 14);

View file

@ -15,7 +15,8 @@ use tokio::select;
use tokio::sync::RwLock;
use tokio::time::sleep;
use crate::prudp::socket::{new_socket_pair, AnyInternalSocket, CryptoHandler, ExternalSocket};
use crate::prudp::packet::{PRUDPV1Packet, VirtualPort};
use crate::prudp::packet::{PRUDPV1Packet};
use rnex_core::prudp::virtual_port::VirtualPort;
use crate::prudp::router::Error::VirtualPortTaken;
static SERVER_DATAGRAMS: Lazy<u8> = Lazy::new(||{

View file

@ -5,12 +5,12 @@ use rc4::cipher::StreamCipherCoreWrapper;
use rc4::{KeyInit, Rc4, Rc4Core, StreamCipher};
use rc4::consts::U16;
use typenum::U5;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use crate::kerberos::{derive_key, TicketInternalData};
use crate::nex::account::Account;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use rnex_core::kerberos::{derive_key, TicketInternalData};
use rnex_core::nex::account::Account;
use crate::prudp::packet::PRUDPV1Packet;
use crate::prudp::socket::{CryptoHandler, CryptoHandlerConnectionInstance, EncryptionPair};
use crate::rmc::structures::RmcSerialize;
use rnex_core::rmc::structures::RmcSerialize;
pub fn read_secure_connection_data(data: &[u8], act: &Account) -> Option<([u8; 32], u32, u32)>{
let mut cursor = Cursor::new(data);

View file

@ -3,8 +3,9 @@ use crate::prudp::packet::types::{CONNECT, DATA, DISCONNECT, PING, SYN};
use crate::prudp::packet::PacketOption::{
ConnectionSignature, FragmentId, MaximumSubstreamId, SupportedFunctions,
};
use crate::prudp::packet::{PRUDPV1Header, PRUDPV1Packet, TypesFlags, VirtualPort};
use crate::prudp::sockaddr::PRUDPSockAddr;
use crate::prudp::packet::{PRUDPV1Header, PRUDPV1Packet, TypesFlags};
use rnex_core::prudp::virtual_port::VirtualPort;
use rnex_core::prudp::socket_addr::PRUDPSockAddr;
use async_trait::async_trait;
use log::info;
use log::error;

View file

@ -1,4 +1,4 @@
use rust_nex::reggie::{RemoteEdgeNodeHolder, UnitPacketRead};
use rnex_core::reggie::{RemoteEdgeNodeHolder, UnitPacketRead};
use log::{error, info};
use once_cell::sync::Lazy;
use rustls::client::danger::HandshakeSignatureValid;
@ -10,7 +10,7 @@ use rustls::{
SignatureScheme,
};
use rustls_pki_types::PrivateKeyDer;
use rust_nex::common::setup;
use rnex_core::common::setup;
use std::borrow::ToOwned;
use std::{env, fs};
use std::io::Cursor;
@ -21,28 +21,22 @@ use tokio::io::AsyncReadExt;
use tokio::net::{TcpListener, TcpSocket, TcpStream};
use tokio::task;
use tokio_rustls::TlsAcceptor;
use rust_nex::define_rmc_proto;
use rust_nex::executables::common::{OWN_IP_PRIVATE, SECURE_EDGE_NODE_HOLDER, SECURE_SERVER_ACCOUNT, SERVER_PORT};
use rust_nex::nex::auth_handler::AuthHandler;
use rust_nex::reggie::EdgeNodeHolderConnectOption::DontRegister;
use rust_nex::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rust_nex::rmc::response::ErrorCode;
use rust_nex::rmc::structures::RmcSerialize;
use rust_nex::rnex_proxy_common::ConnectionInitData;
use rust_nex::util::SplittableBufferConnection;
use rnex_core::define_rmc_proto;
use rnex_core::executables::common::{OWN_IP_PRIVATE, SECURE_SERVER_ACCOUNT, SERVER_PORT};
use rnex_core::nex::auth_handler::AuthHandler;
use rnex_core::reggie::EdgeNodeHolderConnectOption::DontRegister;
use rnex_core::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_core::util::SplittableBufferConnection;
pub static SECURE_PROXY_ADDR: Lazy<Ipv4Addr> = Lazy::new(|| {
env::var("SECURE_PROXY_ADDR")
pub static FORWARD_EDGE_NODE_HOLDER: Lazy<SocketAddrV4> = Lazy::new(||{
env::var("FORWARD_EDGE_NODE_HOLDER")
.ok()
.and_then(|s| s.parse().ok())
.expect("no secure proxy ip specified")
});
pub static SECURE_PROXY_PORT: Lazy<u16> = Lazy::new(|| {
env::var("SECURE_PROXY_PORT")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(10000)
.expect("SECURE_EDGE_NODE_HOLDER not set")
});
@ -51,7 +45,7 @@ pub static SECURE_PROXY_PORT: Lazy<u16> = Lazy::new(|| {
async fn main() {
setup();
let conn = TcpStream::connect(&*SECURE_EDGE_NODE_HOLDER).await.unwrap();
let conn = TcpStream::connect(&*FORWARD_EDGE_NODE_HOLDER).await.unwrap();
let conn: SplittableBufferConnection = conn.into();

View file

@ -1,22 +1,22 @@
use std::io::Cursor;
use rust_nex::rmc::structures::RmcSerialize;
use rust_nex::reggie::{RemoteEdgeNodeHolder, UnitPacketRead};
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::reggie::{RemoteEdgeNodeHolder, UnitPacketRead};
use std::net::SocketAddrV4;
use std::sync::Arc;
use std::sync::atomic::AtomicU32;
use log::{error, info};
use tokio::net::{TcpListener, TcpStream};
use tokio::task;
use rust_nex::common::setup;
use rust_nex::executables::common::{OWN_IP_PRIVATE, SECURE_EDGE_NODE_HOLDER, SERVER_PORT};
use rust_nex::nex::matchmake::MatchmakeManager;
use rust_nex::nex::remote_console::RemoteConsole;
use rust_nex::nex::user::User;
use rust_nex::reggie::EdgeNodeHolderConnectOption::DontRegister;
use rust_nex::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rust_nex::rnex_proxy_common::ConnectionInitData;
use rust_nex::rmc::protocols::RemoteInstantiatable;
use rust_nex::util::SplittableBufferConnection;
use rnex_core::common::setup;
use rnex_core::executables::common::{OWN_IP_PRIVATE, SERVER_PORT};
use rnex_core::nex::matchmake::MatchmakeManager;
use rnex_core::nex::remote_console::RemoteConsole;
use rnex_core::nex::user::User;
use rnex_core::reggie::EdgeNodeHolderConnectOption::DontRegister;
use rnex_core::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote};
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_core::rmc::protocols::RemoteInstantiatable;
use rnex_core::util::SplittableBufferConnection;
#[tokio::main]
async fn main() {

View file

@ -3,8 +3,8 @@ use std::net::{Ipv4Addr, SocketAddrV4};
use macros::{method_id, rmc_proto, RmcSerialize};
use once_cell::sync::Lazy;
use tonic::transport::Server;
use rust_nex::define_rmc_proto;
use rust_nex::prudp::station_url::StationUrl;
use crate::define_rmc_proto;
use crate::prudp::station_url::StationUrl;
use crate::nex::account::Account;
use crate::rmc::response::ErrorCode;
@ -40,17 +40,5 @@ pub static AUTH_SERVER_ACCOUNT: Lazy<Account> =
pub static SECURE_SERVER_ACCOUNT: Lazy<Account> =
Lazy::new(|| Account::new(2, "Quazal Rendez-Vous", &KERBEROS_SERVER_PASSWORD));
pub static SECURE_EDGE_NODE_HOLDER: Lazy<SocketAddrV4> = Lazy::new(||{
env::var("SECURE_EDGE_NODE_HOLDER")
.ok()
.and_then(|s| s.parse().ok())
.expect("SECURE_EDGE_NODE_HOLDER not set")
});
pub static FORWARD_DESTINATION: Lazy<SocketAddrV4> =
Lazy::new(||
env::var("FORWARD_DESTINATION")
.ok()
.and_then(|s| s.parse().ok())
.expect("FORWARD_DESTINATION not set")
);

View file

@ -5,13 +5,13 @@ use log::error;
use macros::rmc_struct;
use tokio::net::TcpListener;
use tokio::sync::RwLock;
use rust_nex::common::setup;
use rust_nex::executables::common::{OWN_IP_PRIVATE, SERVER_PORT};
use rust_nex::reggie::{EdgeNodeHolderConnectOption, EdgeNodeManagement, LocalEdgeNodeHolder};
use rust_nex::rmc::protocols::new_rmc_gateway_connection;
use rust_nex::rmc::response::ErrorCode;
use rust_nex::util::SplittableBufferConnection;
use rust_nex::rmc::structures::RmcSerialize;
use rnex_core::common::setup;
use rnex_core::executables::common::{OWN_IP_PRIVATE, SERVER_PORT};
use rnex_core::reggie::{EdgeNodeHolderConnectOption, EdgeNodeManagement, LocalEdgeNodeHolder};
use rnex_core::rmc::protocols::new_rmc_gateway_connection;
use rnex_core::rmc::response::ErrorCode;
use rnex_core::util::SplittableBufferConnection;
use rnex_core::rmc::structures::RmcSerialize;
#[rmc_struct(EdgeNodeHolder)]
struct EdgeNode{

View file

@ -0,0 +1 @@
pub mod common;

View file

@ -5,5 +5,4 @@
use tonic::{Request, Status};
type InterceptorFunc = Box<(dyn Fn(Request<()>) -> Result<Request<()>, Status> + Send)>;
mod protobufs;
pub mod account;

View file

@ -135,7 +135,7 @@ pub struct Ticket{
}
impl Ticket{
pub(crate) fn encrypt(&self, key: [u8; 16], internal_data: &[u8]) -> Box<[u8]>{
pub fn encrypt(&self, key: [u8; 16], internal_data: &[u8]) -> Box<[u8]>{
let mut data = bytes_of(self).to_vec();
internal_data.serialize(&mut data).expect("unable to write to vec");

View file

@ -6,9 +6,8 @@
extern crate self as rust_nex;
extern crate self as rnex_core;
pub mod endianness;
pub mod prudp;
pub mod rmc;
//mod protocols;
@ -24,3 +23,4 @@ pub mod reggie;
pub mod rnex_proxy_common;
pub mod util;
pub mod executables;
pub use macros::*;

View file

@ -14,11 +14,6 @@ use crate::nex::account::Account;
use crate::nex::auth_handler::{AuthHandler, RemoteAuthClientProtocol};
use crate::nex::remote_console::RemoteConsole;
use crate::nex::user::{RemoteUserProtocol, User};
use crate::prudp::packet::VirtualPort;
use crate::prudp::router::Router;
use crate::prudp::secure::Secure;
use crate::prudp::sockaddr::PRUDPSockAddr;
use crate::prudp::unsecure::Unsecure;
use crate::rmc::protocols::auth::Auth;
use crate::rmc::protocols::auth::RawAuth;
use crate::rmc::protocols::auth::RawAuthInfo;
@ -51,7 +46,6 @@ use crate::kerberos::KerberosDateTime;
use crate::nex::matchmake::MatchmakeManager;
use crate::rmc::protocols::secure::RemoteSecure;
mod endianness;
mod prudp;
pub mod rmc;
//mod protocols;

View file

@ -2,18 +2,18 @@ use std::hash::{DefaultHasher, Hasher};
use std::net::SocketAddrV4;
use std::sync::Arc;
use crate::grpc::account;
use crate::kerberos::{derive_key, KerberosDateTime, Ticket};
use crate::nex::account::Account;
use crate::rmc::protocols::auth::{Auth, RawAuth, RawAuthInfo, RemoteAuth};
use crate::rmc::response::ErrorCode;
use crate::rmc::response::ErrorCode::Core_Unknown;
use crate::rmc::structures::any::Any;
use crate::rmc::structures::connection_data::ConnectionData;
use crate::rmc::structures::qresult::QResult;
use rnex_core::kerberos::{derive_key, KerberosDateTime, Ticket};
use rnex_core::nex::account::Account;
use rnex_core::rmc::protocols::auth::{Auth, RawAuth, RawAuthInfo, RemoteAuth};
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::response::ErrorCode::Core_Unknown;
use rnex_core::rmc::structures::any::Any;
use rnex_core::rmc::structures::connection_data::ConnectionData;
use rnex_core::rmc::structures::qresult::QResult;
use crate::{define_rmc_proto, kerberos};
use macros::rmc_struct;
use crate::reggie::{RemoteEdgeNodeHolder, RemoteEdgeNodeManagement};
use crate::rmc::protocols::OnlyRemote;
use rnex_core::rmc::protocols::OnlyRemote;
define_rmc_proto!(
proto AuthClientProtocol{
@ -157,10 +157,10 @@ impl Auth for AuthHandler {
#[cfg(test)]
mod test {
use crate::rmc::structures::connection_data::ConnectionData;
use crate::rmc::structures::qresult::QResult;
use crate::rmc::structures::RmcSerialize;
use crate::rmc::response::RMCResponse;
use rnex_core::rmc::structures::connection_data::ConnectionData;
use rnex_core::rmc::structures::qresult::QResult;
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::rmc::response::RMCResponse;
use std::io::Cursor;
#[test]
@ -169,7 +169,7 @@ mod test {
let stuff = hex::decode("200100000a0106000000028000000100010051b3995774000000a6321c7f78847c1c5e9fb825eb26bd91841f1a40d92fc694159666119cb13527f1463ac48ad42a63e6613ede67041554b1770978112e6f1f3e177a2bfc75933216dbe38f70133a1eb28e2ae32a4b5c4b0c3e3efd4c02907992e259b257270b57a9dbe7792f4721b07f8fafb9e32d50f2555c616a015c0000004b007072756470733a2f5049443d323b7369643d313b73747265616d3d31303b747970653d323b616464726573733d322e3234332e39352e3131333b706f72743d31303030313b4349443d3100000000000100002c153ba51f00000033006272616e63683a6f726967696e2f70726f6a6563742f7775702d61676d6a206275696c643a335f385f31355f323030345f3000").unwrap();
let stuff = RMCResponse::new(&mut Cursor::new(stuff)).unwrap();
let crate::rmc::response::RMCResponseResult::Success { call_id, method_id, data: stuff} = stuff.response_result else {
let rnex_core::rmc::response::RMCResponseResult::Success { call_id, method_id, data: stuff} = stuff.response_result else {
panic!()
};

View file

@ -8,15 +8,15 @@ use log::info;
use rand::random;
use tokio::sync::{Mutex, RwLock};
use tokio::time::sleep;
use crate::kerberos::KerberosDateTime;
use rnex_core::kerberos::KerberosDateTime;
use crate::nex::user::User;
use crate::rmc::protocols::notifications::{NotificationEvent, RemoteNotification};
use crate::rmc::protocols::notifications::notification_types::{HOST_CHANGED, OWNERSHIP_CHANGED};
use crate::rmc::response::ErrorCode;
use crate::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_SessionVoid};
use crate::rmc::structures::matchmake::{Gathering, MatchmakeParam, MatchmakeSession, MatchmakeSessionSearchCriteria};
use crate::rmc::structures::matchmake::gathering_flags::PERSISTENT_GATHERING;
use crate::rmc::structures::variant::Variant;
use rnex_core::rmc::protocols::notifications::notification_types::{HOST_CHANGED, OWNERSHIP_CHANGED};
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_SessionVoid};
use rnex_core::rmc::structures::matchmake::{Gathering, MatchmakeParam, MatchmakeSession, MatchmakeSessionSearchCriteria};
use rnex_core::rmc::structures::matchmake::gathering_flags::PERSISTENT_GATHERING;
use rnex_core::rmc::structures::variant::Variant;
pub struct MatchmakeManager{
pub gid_counter: AtomicU32,

View file

@ -1,33 +1,33 @@
use crate::define_rmc_proto;
use crate::nex::matchmake::{ExtendedMatchmakeSession, MatchmakeManager};
use crate::nex::remote_console::RemoteConsole;
use crate::prudp::sockaddr::PRUDPSockAddr;
use crate::prudp::station_url::UrlOptions::{
use rnex_core::prudp::station_url::StationUrl;
use rnex_core::prudp::station_url::UrlOptions::{
Address, NatFiltering, NatMapping, NatType, Port, PrincipalID, RVConnectionID,
};
use crate::prudp::station_url::{StationUrl};
use crate::rmc::protocols::matchmake::{
Matchmake, RawMatchmake, RawMatchmakeInfo, RemoteMatchmake,
};
use crate::rmc::protocols::ranking::{Ranking, RawRanking, RawRankingInfo, RemoteRanking};
use crate::rmc::protocols::matchmake_extension::{
use rnex_core::rmc::protocols::ranking::{Ranking, RawRanking, RawRankingInfo, RemoteRanking};
use rnex_core::rmc::protocols::matchmake_extension::{
MatchmakeExtension, RawMatchmakeExtension, RawMatchmakeExtensionInfo, RemoteMatchmakeExtension,
};
use crate::rmc::protocols::nat_traversal::{NatTraversal, RawNatTraversal, RawNatTraversalInfo, RemoteNatTraversal, RemoteNatTraversalConsole};
use crate::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure};
use crate::rmc::protocols::matchmake_ext::{MatchmakeExt, RawMatchmakeExt, RawMatchmakeExtInfo, RemoteMatchmakeExt};
use crate::rmc::response::ErrorCode;
use crate::rmc::structures::matchmake::{AutoMatchmakeParam, CreateMatchmakeSessionParam, JoinMatchmakeSessionParam, MatchmakeSession};
use rnex_core::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure};
use rnex_core::rmc::protocols::matchmake_ext::{MatchmakeExt, RawMatchmakeExt, RawMatchmakeExtInfo, RemoteMatchmakeExt};
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::structures::matchmake::{AutoMatchmakeParam, CreateMatchmakeSessionParam, JoinMatchmakeSessionParam, MatchmakeSession};
use crate::rmc::structures::qresult::QResult;
use rnex_core::rmc::structures::qresult::QResult;
use macros::rmc_struct;
use std::sync::{Arc, Weak};
use log::info;
use tokio::sync::{Mutex, RwLock};
use crate::prudp::station_url::nat_types::PUBLIC;
use rnex_core::prudp::socket_addr::PRUDPSockAddr;
use rnex_core::prudp::station_url::nat_types::PUBLIC;
use crate::rmc::protocols::notifications::{NotificationEvent, RemoteNotification};
use crate::rmc::response::ErrorCode::{Core_Exception, Core_InvalidArgument, RendezVous_AccountExpired};
use rnex_core::rmc::response::ErrorCode::{Core_Exception, Core_InvalidArgument, RendezVous_AccountExpired};
define_rmc_proto!(
proto UserProtocol{

View file

@ -0,0 +1,3 @@
pub mod virtual_port;
pub mod station_url;
pub mod socket_addr;

View file

@ -1,8 +1,9 @@
use std::io::Write;
use std::net::SocketAddrV4;
use hmac::{Hmac, Mac};
use hmac::{Hmac};
use md5::digest::Mac;
use macros::RmcSerialize;
use crate::prudp::packet::VirtualPort;
use rnex_core::prudp::virtual_port::VirtualPort;
type Md5Hmac = Hmac<md5::Md5>;
@ -24,7 +25,7 @@ impl PRUDPSockAddr{
}
}
pub(super) fn calculate_connection_signature(&self) -> [u8; 16] {
pub fn calculate_connection_signature(&self) -> [u8; 16] {
let mut hmac = Md5Hmac::new_from_slice(&[0; 16]).expect("fuck");
let mut data = self.regular_socket_addr.ip().octets().to_vec();

View file

@ -0,0 +1,49 @@
use std::fmt::{Debug, Formatter};
use bytemuck::{Pod, Zeroable};
use v_byte_helpers::SwapEndian;
#[repr(transparent)]
#[derive(PartialEq, Eq, Ord, PartialOrd, Copy, Clone, Pod, Zeroable, SwapEndian, Hash, Default)]
pub struct VirtualPort(pub u8);
impl VirtualPort {
#[inline]
pub const fn get_stream_type(self) -> u8 {
(self.0 & 0xF0) >> 4
}
#[inline]
pub const fn get_port_number(self) -> u8 {
self.0 & 0x0F
}
#[inline]
pub fn stream_type(self, val: u8) -> Self {
let masked_val = val & 0x0F;
assert_eq!(masked_val, val);
Self((self.0 & 0x0F) | (masked_val << 4))
}
#[inline]
pub fn port_number(self, val: u8) -> Self {
let masked_val = val & 0x0F;
assert_eq!(masked_val, val);
Self((self.0 & 0xF0) | masked_val)
}
#[inline]
pub fn new(port: u8, stream_type: u8) -> Self {
Self(0).stream_type(stream_type).port_number(port)
}
}
impl Debug for VirtualPort {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let stream_type = self.get_stream_type();
let port_number = self.get_port_number();
write!(f, "VirtualPort{{ stream_type: {}, port_number: {} }}", stream_type, port_number)
}
}

View file

@ -20,11 +20,11 @@ use tokio_rustls::client::TlsStream;
use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};
use tokio_tungstenite::tungstenite::Message;
use webpki::anchor_from_trusted_cert;
use rust_nex::common::setup;
use crate::common::setup;
use crate::define_rmc_proto;
use crate::nex::account::Account;
use crate::rmc::protocols::{new_rmc_gateway_connection, OnlyRemote, RmcCallable, RmcConnection};
use crate::rmc::response::ErrorCode;
use rnex_core::rmc::response::ErrorCode;
use crate::rmc::structures::RmcSerialize;
pub trait UnitPacketRead: AsyncRead + Unpin{

View file

@ -2,7 +2,7 @@ use std::io;
use std::io::{Read, Seek, Write};
use bytemuck::bytes_of;
use log::error;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::response::{ErrorCode, RMCResponseResult};
#[derive(Debug, Clone, PartialEq, Eq)]

View file

@ -1,7 +1,7 @@
use crate::rmc::response::ErrorCode;
use crate::rmc::structures::any::Any;
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::structures::any::Any;
use crate::rmc::structures::connection_data::ConnectionData;
use crate::rmc::structures::qresult::QResult;
use rnex_core::rmc::structures::qresult::QResult;
use macros::{method_id, rmc_proto};

View file

@ -1,6 +1,6 @@
use macros::{method_id, rmc_proto};
use crate::prudp::station_url::StationUrl;
use crate::rmc::response::ErrorCode;
use rnex_core::prudp::station_url::StationUrl;
use rnex_core::rmc::response::ErrorCode;
#[rmc_proto(21)]
pub trait Matchmake{

View file

@ -1,5 +1,5 @@
use macros::{method_id, rmc_proto};
use crate::rmc::response::ErrorCode;
use rnex_core::rmc::response::ErrorCode;
#[rmc_proto(50)]
pub trait MatchmakeExt{

View file

@ -1,6 +1,6 @@
use macros::{method_id, rmc_proto};
use crate::rmc::response::ErrorCode;
use crate::rmc::structures::matchmake::{AutoMatchmakeParam, CreateMatchmakeSessionParam, JoinMatchmakeSessionParam, MatchmakeSession};
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::structures::matchmake::{AutoMatchmakeParam, CreateMatchmakeSessionParam, JoinMatchmakeSessionParam, MatchmakeSession};
#[rmc_proto(109)]
pub trait MatchmakeExtension{

View file

@ -154,7 +154,7 @@ macro_rules! define_rmc_proto {
}) => {
paste::paste!{
pub trait [<Local $name>]: std::any::Any $( + [<Raw $protocol>] + $protocol)* {
async fn rmc_call(&self, remote_response_connection: &rust_nex::util::SendingBufferConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>){
async fn rmc_call(&self, remote_response_connection: &rnex_core::util::SendingBufferConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>){
match protocol_id{
$(
[<Raw $protocol Info>]::PROTOCOL_ID => <Self as [<Raw $protocol>]>::rmc_call_proto(self, remote_response_connection, method_id, call_id, rest).await,
@ -164,10 +164,10 @@ macro_rules! define_rmc_proto {
}
}
pub struct [<Remote $name>](rust_nex::rmc::protocols::RmcConnection);
pub struct [<Remote $name>](rnex_core::rmc::protocols::RmcConnection);
impl rust_nex::rmc::protocols::RemoteInstantiatable for [<Remote $name>]{
fn new(conn: rust_nex::rmc::protocols::RmcConnection) -> Self{
impl rnex_core::rmc::protocols::RemoteInstantiatable for [<Remote $name>]{
fn new(conn: rnex_core::rmc::protocols::RmcConnection) -> Self{
Self(conn)
}
async fn disconnect(&self){
@ -175,8 +175,8 @@ macro_rules! define_rmc_proto {
}
}
impl rust_nex::rmc::protocols::HasRmcConnection for [<Remote $name>]{
fn get_connection(&self) -> &rust_nex::rmc::protocols::RmcConnection{
impl rnex_core::rmc::protocols::HasRmcConnection for [<Remote $name>]{
fn get_connection(&self) -> &rnex_core::rmc::protocols::RmcConnection{
&self.0
}
}

View file

@ -1,5 +1,5 @@
use macros::{method_id, rmc_proto};
use crate::rmc::response::ErrorCode;
use rnex_core::rmc::response::ErrorCode;
#[rmc_proto(3)]
pub trait NatTraversal{

View file

@ -1,7 +1,7 @@
use macros::{method_id, rmc_proto};
use crate::prudp::station_url::StationUrl;
use crate::rmc::response::ErrorCode;
use crate::rmc::structures::qresult::QResult;
use rnex_core::prudp::station_url::StationUrl;
use rnex_core::rmc::response::ErrorCode;
use rnex_core::rmc::structures::qresult::QResult;
#[rmc_proto(11)]
pub trait Secure {

View file

@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write};
use std::mem::transmute;
use bytemuck::bytes_of;
use log::error;
use v_byte_macros::EnumTryInto;
use crate::endianness::{ReadExtensions, IS_BIG_ENDIAN};
use v_byte_helpers::EnumTryInto;
use v_byte_helpers::{ReadExtensions, IS_BIG_ENDIAN};
use crate::rmc::response::ErrorCode::Core_Exception;
use crate::rmc::structures::qresult::ERROR_MASK;
use crate::util::SendingBufferConnection;

View file

@ -1,5 +1,5 @@
use std::io::{Read, Write};
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use super::{Result, RmcSerialize};
#[derive(Debug, Default)]

View file

@ -1,7 +1,6 @@
use macros::RmcSerialize;
use crate::kerberos::KerberosDateTime;
use crate::rmc::structures::RmcSerialize;
use rnex_core::kerberos::KerberosDateTime;
#[derive(Debug, RmcSerialize)]
#[rmc_struct(1)]

View file

@ -3,7 +3,7 @@ use std::io::{Read, Write};
use std::mem::MaybeUninit;
use bytemuck::bytes_of;
use serde::Serialize;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::structures::RmcSerialize;

View file

@ -1,5 +1,5 @@
use crate::kerberos::KerberosDateTime;
use crate::rmc::structures::variant::Variant;
use rnex_core::kerberos::KerberosDateTime;
use rnex_core::rmc::structures::variant::Variant;
use macros::RmcSerialize;
// rmc structure

View file

@ -1,6 +1,6 @@
use std::io::{Read, Write};
use std::net::{Ipv4Addr, SocketAddrV4};
use crate::prudp::packet::VirtualPort;
use rnex_core::prudp::virtual_port::VirtualPort;
use crate::rmc::structures::RmcSerialize;
impl RmcSerialize for SocketAddrV4{

View file

@ -1,6 +1,6 @@
use std::io::{Read, Write};
use bytemuck::bytes_of;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::structures::RmcSerialize;
impl RmcSerialize for u8{

View file

@ -1,6 +1,6 @@
use std::io::{Read, Write};
use bytemuck::bytes_of;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::structures::{Result, RmcSerialize};

View file

@ -1,7 +1,7 @@
use std::io::{Read, Write};
use bytemuck::{bytes_of, Pod, Zeroable};
use v_byte_macros::SwapEndian;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::SwapEndian;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::response::ErrorCode;
use crate::rmc::structures::{RmcSerialize, Result};

View file

@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use macros::RmcSerialize;
use crate::rmc::structures::qbuffer::QBuffer;
use rnex_core::rmc::structures::qbuffer::QBuffer;
#[derive(RmcSerialize, Debug)]
#[rmc_struct(0)]
@ -27,7 +27,7 @@ mod test{
use bytemuck::from_bytes;
use tokio::io::AsyncReadExt;
use crate::rmc::structures::ranking::{UploadCompetitionData, UserData};
use crate::rmc::structures::RmcSerialize;
use rnex_core::rmc::structures::RmcSerialize;
#[test]
fn test() {

View file

@ -1,6 +1,6 @@
use std::io::{Cursor, Read, Write};
use bytemuck::bytes_of;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::structures::Error::VersionMismatch;
use crate::rmc::structures::Result;

View file

@ -1,7 +1,7 @@
use std::io::{Read, Write};
use bytemuck::bytes_of;
use log::error;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use super::{Result, RmcSerialize};
impl RmcSerialize for String{

View file

@ -1,5 +1,5 @@
use macros::RmcSerialize;
use crate::prudp::sockaddr::PRUDPSockAddr;
use crate::prudp::socket_addr::PRUDPSockAddr;
#[derive(Debug, RmcSerialize)]
#[rmc_struct(0)]

View file

@ -5,7 +5,7 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::sync::Notify;
use tokio::task;
use rust_nex::reggie::{UnitPacketRead, UnitPacketWrite};
use crate::reggie::{UnitPacketRead, UnitPacketWrite};
#[derive(Clone)]
pub struct SendingBufferConnection(Sender<Vec<u8>>, Arc<Notify>);

View file

@ -1,230 +0,0 @@
use std::{io, mem};
use std::io::Read;
use std::marker::PhantomData;
use bytemuck::Pod;
#[cfg(target_endian = "little")]
pub const IS_LITTLE_ENDIAN: bool = true;
#[cfg(target_endian = "big")]
pub const IS_LITTLE_ENDIAN: bool = false;
pub const IS_BIG_ENDIAN: bool = !IS_LITTLE_ENDIAN;
pub mod little_endian{
use std::io;
use std::io::Read;
#[inline]
pub fn read_u16(reader: &mut (impl Read + ?Sized)) -> io::Result<u16>{
let mut data = [0u8; 2];
reader.read_exact(&mut data)?;
Ok(((data[0] as u16) << 8) | (data[1] as u16))
}
#[inline]
pub fn read_u32(reader: &mut (impl Read + ?Sized)) -> io::Result<u32>{
let mut data = [0u8; 4];
reader.read_exact(&mut data)?;
Ok(
((data[0] as u32) << 24) |
((data[1] as u32) << 16) |
((data[2] as u32) << 8) |
(data[3] as u32)
)
}
}
pub struct StructMultiReadIter<'a, T: Pod + SwapEndian>{
reader: &'a mut dyn Read,
left_to_read: usize,
swap_endian: bool,
_phantom_data: PhantomData<&'static T>
}
impl<'a, T: Pod + SwapEndian> Iterator for StructMultiReadIter<'a, T>{
type Item = io::Result<T>;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.left_to_read == 0{
None
} else {
Some(self.reader.read_struct(self.swap_endian))
}
}
}
impl<'a, T: Pod + SwapEndian> Drop for StructMultiReadIter<'a, T>{
#[inline]
fn drop(&mut self) {
// read all the structs we would be reading and discard them to make the result after using
// this always be the same
while let Some(_) = self.next() { }
}
}
pub trait ReadExtensions: Read{
#[inline]
fn read_le_u16(&mut self) -> io::Result<u16>{
little_endian::read_u16(self)
}
#[inline]
fn read_le_u32(&mut self) -> io::Result<u32>{
little_endian::read_u32(self)
}
#[inline]
fn read_le_struct<T: Pod + SwapEndian>(&mut self) -> io::Result<T>{
let mut data = T::zeroed();
let bytes = bytemuck::bytes_of_mut(&mut data);
self.read_exact(bytes)?;
if cfg!(not(target_endian = "little")){
data = data.swap_endian();
}
Ok(data)
}
#[inline]
fn read_struct<T: Pod + SwapEndian>(&mut self, swap_endian: bool) -> io::Result<T>{
let mut data = T::zeroed();
let bytes = bytemuck::bytes_of_mut(&mut data);
self.read_exact(bytes)?;
if swap_endian{
data = data.swap_endian();
}
Ok(data)
}
fn read_struct_multi<T: Pod + SwapEndian>(&mut self, swap_endian: bool, count: usize) -> io::Result<StructMultiReadIter<T>>;
}
impl<T: Read> ReadExtensions for T{
// i was forced to put this here because it requires info about self
#[inline]
fn read_struct_multi<U: Pod + SwapEndian>(&mut self, swap_endian: bool, count: usize) -> io::Result<StructMultiReadIter<'_, U>>{
Ok(StructMultiReadIter{
reader: self,
swap_endian,
left_to_read: count,
_phantom_data: Default::default()
})
}
}
pub trait SwapEndian: Clone + Copy{
fn swap_endian(self) -> Self;
}
impl SwapEndian for u8{
#[inline]
fn swap_endian(self) -> Self {
self
}
}
impl SwapEndian for u16{
#[inline]
fn swap_endian(self) -> Self {
self.swap_bytes()
}
}
impl SwapEndian for u32{
#[inline]
fn swap_endian(self) -> Self {
self.swap_bytes()
}
}
impl SwapEndian for u64{
#[inline]
fn swap_endian(self) -> Self {
self.swap_bytes()
}
}
impl SwapEndian for f64{
#[inline]
fn swap_endian(self) -> Self {
//trust me this is safe
unsafe{ mem::transmute::<_, f64>(mem::transmute::<_, u64>(self).swap_bytes()) }
}
}
impl SwapEndian for i8{
#[inline]
fn swap_endian(self) -> Self {
self
}
}
impl SwapEndian for i16{
#[inline]
fn swap_endian(self) -> Self {
self.swap_bytes()
}
}
impl SwapEndian for i32{
#[inline]
fn swap_endian(self) -> Self {
self.swap_bytes()
}
}
impl SwapEndian for i64{
#[inline]
fn swap_endian(self) -> Self {
self.swap_bytes()
}
}
impl<T: SwapEndian, U: SwapEndian> SwapEndian for (T, U){
#[inline]
fn swap_endian(self) -> Self {
(self.0.swap_endian(), self.1.swap_endian())
}
}
impl<T: SwapEndian, U: SwapEndian, V: SwapEndian> SwapEndian for (T, U, V){
#[inline]
fn swap_endian(self) -> Self {
(self.0.swap_endian(), self.1.swap_endian(), self.2.swap_endian())
}
}
impl<T: SwapEndian, U: SwapEndian, V: SwapEndian, W: SwapEndian> SwapEndian for (T, U, V, W){
#[inline]
fn swap_endian(self) -> Self {
(self.0.swap_endian(), self.1.swap_endian(), self.2.swap_endian(), self.3.swap_endian())
}
}
impl<T: SwapEndian, const SIZE: usize> SwapEndian for [T; SIZE]{
#[inline]
fn swap_endian(mut self) -> Self {
for elem in &mut self{
*elem = elem.swap_endian();
}
self
}
}

View file

@ -1,5 +0,0 @@
pub mod account {
tonic::include_proto!("account");
}