aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/tor.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-06 04:31:04 +0100
committertv <tv@krebsco.de>2026-11-06 04:31:04 +0100
commitd0760c918ab75c837548ca27f19a46d387f77004 (patch)
tree98c9b47404e0ad2e6ef740bc33b50bfdc330ae7d /src/transport/tor.rs
parenta56afd335558eda0fee6f511cc9469d3848e5637 (diff)
strangers messages small
Diffstat (limited to 'src/transport/tor.rs')
-rw-r--r--src/transport/tor.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/transport/tor.rs b/src/transport/tor.rs
index 7ecd624..bc95626 100644
--- a/src/transport/tor.rs
+++ b/src/transport/tor.rs
@@ -182,6 +182,8 @@ struct Shared {
/// handed on at once (`is_probe`).
inbound: mpsc::Sender<Inbound>,
probes: mpsc::Sender<Inbound>,
+ /// Whose messages may be large (`transport::Admission`).
+ admission: std::sync::OnceLock<crate::transport::Admission>,
}
fn lock<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T> {
@@ -291,6 +293,7 @@ impl TorTransport {
next_connection: AtomicU64::new(0),
inbound,
probes,
+ admission: std::sync::OnceLock::new(),
});
let (stopping, stopped) = watch::channel(false);
{
@@ -508,8 +511,16 @@ impl Shared {
return error.into();
}
let length = u32::from_be_bytes(length) as usize;
- if length > MAX_MESSAGE {
- return anyhow!("a message of {length} bytes; at most {MAX_MESSAGE} are read");
+ let limit = crate::transport::Admission::limit(
+ self.admission.get(),
+ SCHEME,
+ location,
+ MAX_MESSAGE,
+ );
+ if length > limit {
+ return anyhow!(
+ "a message of {length} bytes; at most {limit} are read from this peer"
+ );
}
let mut body = vec![0u8; length];
match tokio::time::timeout(stream_timeout(length), reader.read_exact(&mut body)).await {
@@ -558,6 +569,10 @@ impl Shared {
#[async_trait]
impl Transport for TorTransport {
+ fn set_admission(&self, admission: crate::transport::Admission) {
+ let _ = self.shared.admission.set(admission);
+ }
+
fn local_id(&self) -> &str {
&self.shared.local_id
}