aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/sim.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-30 15:55:21 +0100
committertv <tv@krebsco.de>2026-10-30 15:55:21 +0100
commit055efc604d8cf56b2cdd05bbd863acb9c2ea12d6 (patch)
treeef3f557b93f7daf3bef0c2cc6d0e38048bec4377 /src/transport/sim.rs
parent54a8d7b3409f6a5857b6fc9a964a36b66c28ae25 (diff)
make mycelium optional
Diffstat (limited to 'src/transport/sim.rs')
-rw-r--r--src/transport/sim.rs26
1 files changed, 24 insertions, 2 deletions
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 {