diff options
| author | tv <tv@krebsco.de> | 2026-11-06 04:31:04 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-06 04:31:04 +0100 |
| commit | d0760c918ab75c837548ca27f19a46d387f77004 (patch) | |
| tree | 98c9b47404e0ad2e6ef740bc33b50bfdc330ae7d /src/transport/mycelium/mod.rs | |
| parent | a56afd335558eda0fee6f511cc9469d3848e5637 (diff) | |
strangers messages small
Diffstat (limited to 'src/transport/mycelium/mod.rs')
| -rw-r--r-- | src/transport/mycelium/mod.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/transport/mycelium/mod.rs b/src/transport/mycelium/mod.rs index 7bae0a7..369d683 100644 --- a/src/transport/mycelium/mod.rs +++ b/src/transport/mycelium/mod.rs @@ -89,6 +89,8 @@ pub(crate) struct MyceliumTransport { messages_endpoint: Url, pubkey_basepath: Url, local_id: String, + /// Whose messages may be large (`transport::Admission`). + admission: std::sync::OnceLock<crate::transport::Admission>, } /// This transport's options, checked when the configuration is loaded @@ -247,6 +249,7 @@ impl MyceliumTransport { messages_endpoint: rest_url.join("/api/v1/messages")?, pubkey_basepath: rest_url.join("/api/v1/pubkey/")?, local_id: admin.node_pubkey, + admission: std::sync::OnceLock::new(), }; transport.discard_backlog().await; Ok(transport) @@ -317,6 +320,10 @@ impl MyceliumTransport { #[async_trait] impl Transport for MyceliumTransport { + fn set_admission(&self, admission: crate::transport::Admission) { + let _ = self.admission.set(admission); + } + fn local_id(&self) -> &str { &self.local_id } @@ -413,6 +420,21 @@ impl Transport for MyceliumTransport { // PINGs and PONGs aren't handled after the message before them (`is_probe`). let handler: std::sync::Arc<HandlerFn> = std::sync::Arc::from(handler); while let Some(inbound_message) = rx.recv().await { + // Mycelium has taken it whole already; a stranger's large one isn't decoded. + let limit = crate::transport::Admission::limit( + self.admission.get(), + SCHEME, + &inbound_message.src_pk, + MAX_INBOUND_BYTES, + ); + if base64_decoded_len(&inbound_message.payload) > limit { + tracing::debug!( + from = %Addressed(SCHEME, &inbound_message.src_pk), + limit, + "Dropping a large message from a peer not admitted" + ); + continue; + } match parse_message(&inbound_message) { Ok((sender, parsed)) => { // The message itself is logged above, in the paths layer. |
