[Fix] Harden MTP codec, transport, and SDK security

This commit is contained in:
Alex Emmet 2026-08-18 20:57:45 +02:00
commit a7e804c603
No known key found for this signature in database
73 changed files with 11892 additions and 5756 deletions

View file

@ -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)
}