1. traffic stats not work.
2. magisk zip malformat
This commit is contained in:
Sijie.Sun
2025-05-27 09:28:28 +08:00
committed by GitHub
parent d7c3179c6e
commit f9c24bc205
21 changed files with 151 additions and 59 deletions
+42 -16
View File
@@ -1,4 +1,7 @@
use std::sync::atomic::{AtomicU32, Ordering::Relaxed};
use std::{
cell::UnsafeCell,
sync::atomic::{AtomicU32, Ordering::Relaxed},
};
pub struct WindowLatency {
latency_us_window: Vec<AtomicU32>,
@@ -58,13 +61,38 @@ impl WindowLatency {
}
}
#[derive(Default, Copy, Clone, Debug)]
#[derive(Debug)]
pub struct Throughput {
tx_bytes: u64,
rx_bytes: u64,
tx_bytes: UnsafeCell<u64>,
rx_bytes: UnsafeCell<u64>,
tx_packets: UnsafeCell<u64>,
rx_packets: UnsafeCell<u64>,
}
tx_packets: u64,
rx_packets: u64,
impl Clone for Throughput {
fn clone(&self) -> Self {
Self {
tx_bytes: UnsafeCell::new(unsafe { *self.tx_bytes.get() }),
rx_bytes: UnsafeCell::new(unsafe { *self.rx_bytes.get() }),
tx_packets: UnsafeCell::new(unsafe { *self.tx_packets.get() }),
rx_packets: UnsafeCell::new(unsafe { *self.rx_packets.get() }),
}
}
}
// add sync::Send and sync::Sync traits to Throughput
unsafe impl Send for Throughput {}
unsafe impl Sync for Throughput {}
impl Default for Throughput {
fn default() -> Self {
Self {
tx_bytes: UnsafeCell::new(0),
rx_bytes: UnsafeCell::new(0),
tx_packets: UnsafeCell::new(0),
rx_packets: UnsafeCell::new(0),
}
}
}
impl Throughput {
@@ -73,34 +101,32 @@ impl Throughput {
}
pub fn tx_bytes(&self) -> u64 {
self.tx_bytes
unsafe { *self.tx_bytes.get() }
}
pub fn rx_bytes(&self) -> u64 {
self.rx_bytes
unsafe { *self.rx_bytes.get() }
}
pub fn tx_packets(&self) -> u64 {
self.tx_packets
unsafe { *self.tx_packets.get() }
}
pub fn rx_packets(&self) -> u64 {
self.rx_packets
unsafe { *self.rx_packets.get() }
}
pub fn record_tx_bytes(&self, bytes: u64) {
#[allow(invalid_reference_casting)]
unsafe {
*(&self.tx_bytes as *const u64 as *mut u64) += bytes;
*(&self.tx_packets as *const u64 as *mut u64) += 1;
*self.tx_bytes.get() += bytes;
*self.tx_packets.get() += 1;
}
}
pub fn record_rx_bytes(&self, bytes: u64) {
#[allow(invalid_reference_casting)]
unsafe {
*(&self.rx_bytes as *const u64 as *mut u64) += bytes;
*(&self.rx_packets as *const u64 as *mut u64) += 1;
*self.rx_bytes.get() += bytes;
*self.rx_packets.get() += 1;
}
}
}