diff options
| author | tv <tv@krebsco.de> | 2026-10-22 20:37:34 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-22 20:37:34 +0200 |
| commit | c97161adb3142041c00d649a51924318b5a2d6e4 (patch) | |
| tree | 5a6a9ed95c9f4745fe5fe9a5dd262563e24bd572 /src/transport | |
| parent | d332830dfee1c6da4726cd69698f9edd18a33e0e (diff) | |
introduce pre-shared swarm key
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/mod.rs | 4 | ||||
| -rw-r--r-- | src/transport/mycelium.rs | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 0afb5ee..58db611 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -43,6 +43,8 @@ impl ParsedMessage { #[derive(Debug, Clone)] pub struct HelloRequest { pub epoch: Epoch, + /// Proof of the swarm key (`swarm::auth`); empty without one. + pub auth: Vec<u8>, } #[derive(Debug, Clone)] @@ -50,6 +52,8 @@ pub struct HelloReply { pub swarm_id: String, pub peers: Vec<String>, pub epoch: Epoch, + /// Proof of the swarm key (`swarm::auth`); empty without one. + pub auth: Vec<u8>, } #[derive(Debug, Clone)] diff --git a/src/transport/mycelium.rs b/src/transport/mycelium.rs index dc2c66e..0c0093a 100644 --- a/src/transport/mycelium.rs +++ b/src/transport/mycelium.rs @@ -795,6 +795,8 @@ fn bytes_to_keepalive(bytes: &[u8]) -> Result<Keepalive, TransportError> { pub struct HelloRequestShadow { #[serde(default)] epoch: EpochShadow, + #[serde(default)] + auth: ByteBuf, } #[derive(Serialize, Deserialize)] @@ -805,6 +807,8 @@ pub struct HelloReplyShadow<'a> { pub peers: Vec<String>, #[serde(default)] epoch: EpochShadow, + #[serde(default)] + auth: ByteBuf, } #[derive(Serialize, Deserialize)] @@ -849,12 +853,14 @@ mod automerge_msg_codec { pub fn hello_request_to_bytes(msg: &HelloRequest) -> Result<Vec<u8>, rmp_serde::encode::Error> { rmp_serde::to_vec(&HelloRequestShadow { epoch: epoch_to_shadow(&msg.epoch), + auth: ByteBuf::from(msg.auth.clone()), }) } pub fn bytes_to_hello_request(bytes: &[u8]) -> Result<HelloRequest, TransportError> { let shadow: HelloRequestShadow = rmp_serde::from_slice(bytes)?; Ok(HelloRequest { epoch: epoch_from_shadow(shadow.epoch)?, + auth: shadow.auth.into_vec(), }) } @@ -864,6 +870,7 @@ pub fn hello_reply_to_bytes(msg: &HelloReply) -> Result<Vec<u8>, rmp_serde::enco swarm_id: Cow::Borrowed(&msg.swarm_id), peers: msg.peers.clone(), // Vec must be cloned for serialization wrapper matching epoch: epoch_to_shadow(&msg.epoch), + auth: ByteBuf::from(msg.auth.clone()), }; rmp_serde::to_vec(&shadow) } @@ -873,6 +880,7 @@ pub fn bytes_to_hello_reply(bytes: &[u8]) -> Result<HelloReply, TransportError> swarm_id: shadow.swarm_id.into_owned(), peers: shadow.peers, epoch: epoch_from_shadow(shadow.epoch)?, + auth: shadow.auth.into_vec(), }) } |
