diff options
| author | tv <tv@krebsco.de> | 2026-10-30 15:55:21 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-30 15:55:21 +0100 |
| commit | 055efc604d8cf56b2cdd05bbd863acb9c2ea12d6 (patch) | |
| tree | ef3f557b93f7daf3bef0c2cc6d0e38048bec4377 /src/transport | |
| parent | 54a8d7b3409f6a5857b6fc9a964a36b66c28ae25 (diff) | |
make mycelium optional
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/mod.rs | 9 | ||||
| -rw-r--r-- | src/transport/paths.rs | 2 | ||||
| -rw-r--r-- | src/transport/sim.rs | 26 |
3 files changed, 33 insertions, 4 deletions
diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 9d43e5a..d8c6e2b 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -18,6 +18,7 @@ pub(crate) mod firewall; pub(crate) mod identity; #[cfg(feature = "libp2p")] pub(crate) mod libp2p; +#[cfg(feature = "mycelium")] pub(crate) mod mycelium; pub(crate) mod paths; #[cfg(test)] @@ -28,6 +29,11 @@ pub(crate) mod tor; pub(crate) mod traffic; pub(crate) mod wire; +#[cfg(not(any(feature = "mycelium", feature = "libp2p", feature = "tor")))] +compile_error!( + "continuum needs a transport: build with at least one of the mycelium, libp2p and tor features, e.g. `cargo build --features mycelium`" +); + /// Starts the transport `name` (one of `config::TRANSPORTS`) as `settings` configure /// it: its scheme and the transport, or None if `stop` came first (some take a while to /// start: a supervised Mycelium daemon, arti). `key`: the node key, which some prove @@ -39,8 +45,9 @@ pub(crate) async fn start( stop: tokio::sync::watch::Receiver<bool>, ) -> Result<Option<(&'static str, std::sync::Arc<dyn Transport>)>> { use std::sync::Arc; - let _ = key; + let _ = (key, &stop); let started: Option<(&'static str, Arc<dyn Transport>)> = match name { + #[cfg(feature = "mycelium")] "mycelium" => mycelium::start(settings, stop) .await? .map(|transport| (mycelium::SCHEME, Arc::new(transport) as Arc<dyn Transport>)), diff --git a/src/transport/paths.rs b/src/transport/paths.rs index e8858da..4d0e775 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -1228,7 +1228,7 @@ mod tests { Ok(seed.to_owned()) } fn encode(&self, peer: &str, message: &ParsedMessage) -> Result<EncodedMessage> { - crate::transport::mycelium::encode_message(peer, message) + crate::transport::sim::encode_message(peer, message) } async fn send_encoded(&self, _message: &EncodedMessage) -> Result<()> { Err(anyhow!("broken")) diff --git a/src/transport/sim.rs b/src/transport/sim.rs index 500050b..2410bba 100644 --- a/src/transport/sim.rs +++ b/src/transport/sim.rs @@ -2,7 +2,8 @@ //! [`SimTransport`] on a shared [`SimNet`]. //! //! Messages go through the Mycelium wire encoding (`mycelium::encode_message`), so the -//! codec is exercised as in production. The net delays, loses and duplicates them per +//! codec is exercised as in production; without the mycelium feature, through the wire +//! encoding alone, as libp2p and Tor send it. The net delays, loses and duplicates them per //! link, from a seeded generator; nodes can be taken down (everything to and from them //! is lost) and brought up again; and a test can inject a message as if a node had sent //! it, e.g. one that arrives late. @@ -24,7 +25,8 @@ use bytes::Bytes; use tokio::sync::{mpsc, oneshot}; use tracing::{debug, warn}; -use super::mycelium::{decode_message, encode_message}; +#[cfg(feature = "mycelium")] +pub(crate) use super::mycelium::{decode_message, encode_message}; use super::{EncodedMessage, MessageHandler, MessageKind, ParsedMessage, Transport}; use crate::locks::MutexExt; use crate::testrand::Rng; @@ -249,6 +251,26 @@ pub(crate) struct SimTransport { inbox: tokio::sync::Mutex<Option<mpsc::UnboundedReceiver<Delivery>>>, } +/// Without Mycelium: a message in the wire encoding alone, as libp2p and Tor send it. +#[cfg(not(feature = "mycelium"))] +pub(crate) fn encode_message(peer: &str, message: &ParsedMessage) -> Result<EncodedMessage> { + let body = super::wire::encode(message)?; + Ok(EncodedMessage { + peer: peer.to_owned(), + address: peer.to_owned(), + payload_len: body.len(), + body: body.into(), + kind: message.kind(), + message: None, + }) +} + +/// The message in a body made by [`encode_message`]. +#[cfg(not(feature = "mycelium"))] +pub(crate) fn decode_message(body: &[u8]) -> Result<ParsedMessage> { + Ok(super::wire::decode(body)?) +} + #[async_trait] impl Transport for SimTransport { fn local_id(&self) -> &str { |
