[Fix] Harden MTP codec, transport, and SDK security
This commit is contained in:
parent
188caf56cc
commit
a7e804c603
73 changed files with 11892 additions and 5756 deletions
|
|
@ -2,22 +2,26 @@ use mtp_common::CommunicationError;
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
};
|
||||
use tokio::sync::watch;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ConnectionHandle {
|
||||
connection_id: u64,
|
||||
closed: AtomicBool,
|
||||
close_tx: watch::Sender<Option<CommunicationError>>,
|
||||
close_rx: watch::Receiver<Option<CommunicationError>>,
|
||||
remote_addr: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
static NEXT_CONNECTION_ID: AtomicU64 = AtomicU64::new(1);
|
||||
|
||||
impl ConnectionHandle {
|
||||
pub fn new() -> Self {
|
||||
let (close_tx, close_rx) = watch::channel(None);
|
||||
Self {
|
||||
connection_id: NEXT_CONNECTION_ID.fetch_add(1, Ordering::Relaxed).max(1),
|
||||
closed: AtomicBool::new(false),
|
||||
close_tx,
|
||||
close_rx,
|
||||
|
|
@ -35,6 +39,11 @@ impl ConnectionHandle {
|
|||
self.remote_addr
|
||||
}
|
||||
|
||||
/// Stable process-local identifier for authentication-rate-limit scopes.
|
||||
pub fn connection_id(&self) -> u64 {
|
||||
self.connection_id
|
||||
}
|
||||
|
||||
pub fn is_open(&self) -> bool {
|
||||
!self.closed.load(Ordering::SeqCst)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue