things
This commit is contained in:
parent
4d4fc6c7bf
commit
fc94f655b2
43 changed files with 1957 additions and 694 deletions
20
rnex-core/src/prudp/encryption.rs
Normal file
20
rnex-core/src/prudp/encryption.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use std::sync::LazyLock;
|
||||
|
||||
use rc4::{Key, StreamCipher};
|
||||
use typenum::U5;
|
||||
|
||||
pub struct EncryptionPair<T: StreamCipher + Send> {
|
||||
pub send: T,
|
||||
pub recv: T,
|
||||
}
|
||||
|
||||
impl<T: StreamCipher + Send> EncryptionPair<T> {
|
||||
pub fn init_both<F: Fn() -> T>(func: F) -> Self {
|
||||
Self {
|
||||
recv: func(),
|
||||
send: func(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub static DEFAULT_KEY: LazyLock<Key<U5>> = LazyLock::new(|| Key::from(*b"CD&ML"));
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
pub mod virtual_port;
|
||||
pub mod encryption;
|
||||
pub mod socket_addr;
|
||||
pub mod station_url;
|
||||
pub mod socket_addr;
|
||||
pub mod types_flags;
|
||||
pub mod virtual_port;
|
||||
|
|
|
|||
64
rnex-core/src/prudp/types_flags.rs
Normal file
64
rnex-core/src/prudp/types_flags.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use v_byte_helpers::SwapEndian;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone, Pod, Zeroable, SwapEndian, Default, Eq, PartialEq)]
|
||||
pub struct TypesFlags(pub u16);
|
||||
|
||||
impl TypesFlags {
|
||||
#[inline]
|
||||
pub const fn get_types(self) -> u8 {
|
||||
(self.0 & 0x000F) as u8
|
||||
}
|
||||
#[inline]
|
||||
pub const fn get_flags(self) -> u16 {
|
||||
(self.0 & 0xFFF0) >> 4
|
||||
}
|
||||
#[inline]
|
||||
pub const fn types(self, val: u8) -> Self {
|
||||
Self((self.0 & 0xFFF0) | (val as u16 & 0x000F))
|
||||
}
|
||||
#[inline]
|
||||
pub const fn flags(self, val: u16) -> Self {
|
||||
Self((self.0 & 0x000F) | ((val << 4) & 0xFFF0))
|
||||
}
|
||||
#[inline]
|
||||
pub const fn set_flag(&mut self, val: u16) {
|
||||
self.0 |= (val & 0xFFF) << 4;
|
||||
}
|
||||
#[inline]
|
||||
pub const fn set_types(&mut self, val: u8) {
|
||||
self.0 |= val as u16 & 0x0F;
|
||||
}
|
||||
}
|
||||
impl Debug for TypesFlags {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let stream_type = self.get_types();
|
||||
let port_number = self.get_flags();
|
||||
write!(
|
||||
f,
|
||||
"TypesFlags{{ types: {}, flags: {} }}",
|
||||
stream_type, port_number
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod flags {
|
||||
pub const ACK: u16 = 0x001;
|
||||
pub const RELIABLE: u16 = 0x002;
|
||||
pub const NEED_ACK: u16 = 0x004;
|
||||
pub const HAS_SIZE: u16 = 0x008;
|
||||
pub const MULTI_ACK: u16 = 0x200;
|
||||
}
|
||||
|
||||
pub mod types {
|
||||
pub const SYN: u8 = 0x0;
|
||||
pub const CONNECT: u8 = 0x1;
|
||||
pub const DATA: u8 = 0x2;
|
||||
pub const DISCONNECT: u8 = 0x3;
|
||||
pub const PING: u8 = 0x4;
|
||||
/// no idea what user is supposed to mean
|
||||
pub const USER: u8 = 0x5;
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
use std::fmt::{Debug, Formatter};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::{
|
||||
fmt::{Debug, Formatter},
|
||||
slice,
|
||||
};
|
||||
use v_byte_helpers::SwapEndian;
|
||||
|
||||
#[repr(transparent)]
|
||||
|
|
@ -7,7 +10,6 @@ use v_byte_helpers::SwapEndian;
|
|||
pub struct VirtualPort(pub u8);
|
||||
|
||||
impl VirtualPort {
|
||||
|
||||
#[inline]
|
||||
pub const fn get_stream_type(self) -> u8 {
|
||||
(self.0 & 0xF0) >> 4
|
||||
|
|
@ -38,12 +40,21 @@ impl VirtualPort {
|
|||
pub fn new(port: u8, stream_type: u8) -> Self {
|
||||
Self(0).stream_type(stream_type).port_number(port)
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn parse(data: &str) -> Option<Self> {
|
||||
let (p1, p2) = data.split_once(':')?;
|
||||
Some(Self::new(p1.parse().ok()?, p2.parse().ok()?))
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
write!(
|
||||
f,
|
||||
"VirtualPort{{ stream_type: {}, port_number: {} }}",
|
||||
stream_type, port_number
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue