diff options
Diffstat (limited to 'src/mycelium.rs')
| -rw-r--r-- | src/mycelium.rs | 82 |
1 files changed, 1 insertions, 81 deletions
diff --git a/src/mycelium.rs b/src/mycelium.rs index 96b9e6d..e623659 100644 --- a/src/mycelium.rs +++ b/src/mycelium.rs @@ -19,9 +19,7 @@ use url::Url; use crate::transport::EncodedMessage; use crate::transport::Keepalive; -use crate::transport::{ - Epoch, HelloReply, HelloRequest, SnapshotReply, SnapshotRequest, SyncEnvelope, -}; +use crate::transport::{Epoch, HelloReply, HelloRequest, SyncEnvelope}; use crate::transport::{MessageHandler, ParsedMessage, Transport}; const MYCELIUM_POLL_TIMEOUT_SECS: u64 = 300; @@ -32,8 +30,6 @@ const TOPIC_HELLO_REPLY: &str = "continuum.v1.hello-reply"; const TOPIC_SYNC: &str = "continuum.v1.sync"; const TOPIC_PING: &str = "continuum.v1.ping"; const TOPIC_PONG: &str = "continuum.v1.pong"; -const TOPIC_SNAPSHOT_REQUEST: &str = "continuum.v1.snapshot-request"; -const TOPIC_SNAPSHOT_REPLY: &str = "continuum.v1.snapshot-reply"; const EMPTY_QUEUE_DELAY: Duration = Duration::from_millis(25); @@ -715,12 +711,6 @@ fn decode_payload(topic: &str, payload: &str) -> Result<ParsedMessage, Transport } TOPIC_PING => Ok(ParsedMessage::Ping(bytes_to_keepalive(&bytes)?)), TOPIC_PONG => Ok(ParsedMessage::Pong(bytes_to_keepalive(&bytes)?)), - TOPIC_SNAPSHOT_REQUEST => Ok(ParsedMessage::SnapshotRequest(bytes_to_snapshot_request( - &bytes, - )?)), - TOPIC_SNAPSHOT_REPLY => Ok(ParsedMessage::SnapshotReply(bytes_to_snapshot_reply( - &bytes, - )?)), t => Err(TransportError::UnknownTopic(t.to_string())), } } @@ -748,10 +738,6 @@ fn format_message( ParsedMessage::Sync(env) => (TOPIC_SYNC, sync_envelope_to_bytes(env)?), ParsedMessage::Ping(k) => (TOPIC_PING, keepalive_to_bytes(k)?), ParsedMessage::Pong(k) => (TOPIC_PONG, keepalive_to_bytes(k)?), - ParsedMessage::SnapshotRequest(req) => { - (TOPIC_SNAPSHOT_REQUEST, snapshot_request_to_bytes(req)?) - } - ParsedMessage::SnapshotReply(res) => (TOPIC_SNAPSHOT_REPLY, snapshot_reply_to_bytes(res)?), }; Ok(OutboundMessage { dst: Destination { @@ -929,72 +915,6 @@ pub fn bytes_to_sync_envelope(bytes: &[u8]) -> Result<SyncEnvelope, TransportErr }) } -// --- Snapshot transfer --- -#[derive(Serialize, Deserialize)] -struct SnapshotRequestShadow { - epoch: EpochShadow, - wanted: EpochShadow, - offset: u64, -} - -#[derive(Serialize, Deserialize)] -struct SnapshotReplyShadow { - epoch: EpochShadow, - wanted: EpochShadow, - digest: ByteBuf, - total: u64, - offset: u64, - data: ByteBuf, - refused: String, -} - -fn snapshot_request_to_bytes(msg: &SnapshotRequest) -> Result<Vec<u8>, rmp_serde::encode::Error> { - rmp_serde::to_vec(&SnapshotRequestShadow { - epoch: epoch_to_shadow(&msg.epoch), - wanted: epoch_to_shadow(&msg.wanted), - offset: msg.offset, - }) -} - -fn bytes_to_snapshot_request(bytes: &[u8]) -> Result<SnapshotRequest, TransportError> { - let shadow: SnapshotRequestShadow = rmp_serde::from_slice(bytes)?; - Ok(SnapshotRequest { - epoch: epoch_from_shadow(shadow.epoch)?, - wanted: epoch_from_shadow(shadow.wanted)?, - offset: shadow.offset, - }) -} - -fn snapshot_reply_to_bytes(msg: &SnapshotReply) -> Result<Vec<u8>, rmp_serde::encode::Error> { - rmp_serde::to_vec(&SnapshotReplyShadow { - epoch: epoch_to_shadow(&msg.epoch), - wanted: epoch_to_shadow(&msg.wanted), - digest: ByteBuf::from(msg.digest.to_vec()), - total: msg.total, - offset: msg.offset, - data: ByteBuf::from(msg.data.clone()), - refused: msg.refused.clone(), - }) -} - -fn bytes_to_snapshot_reply(bytes: &[u8]) -> Result<SnapshotReply, TransportError> { - let shadow: SnapshotReplyShadow = rmp_serde::from_slice(bytes)?; - let digest = shadow - .digest - .as_slice() - .try_into() - .map_err(|_| TransportError::InvalidPayload("digest must be 32 bytes".into()))?; - Ok(SnapshotReply { - epoch: epoch_from_shadow(shadow.epoch)?, - wanted: epoch_from_shadow(shadow.wanted)?, - digest, - total: shadow.total, - offset: shadow.offset, - data: shadow.data.into_vec(), - refused: shadow.refused, - }) -} - #[derive(Error, Debug)] pub enum TransportError { #[error("Mycelium delivered a message without a sender public key")] |
