diff options
Diffstat (limited to 'src/transport/sim.rs')
| -rw-r--r-- | src/transport/sim.rs | 26 |
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 { |
