MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / wrap

Function wrap

nodedb-cluster/src/swim/wire/authenticated.rs:103–112  ·  view source on GitHub ↗

Encode `msg` and wrap it in an authenticated envelope destined for `to`. Returns the bytes to hand to `UdpSocket::send_to`. `to` is retained in the signature as documentation (callers pass the destination they are about to `send_to`), but the outbound seq is a single sender-global counter — see `PeerSeqSender`.

(auth: &SwimAuth, _to: SocketAddr, msg: &SwimMessage)

Source from the content-addressed store, hash-verified

101/// destination they are about to `send_to`), but the outbound seq is a
102/// single sender-global counter — see `PeerSeqSender`.
103pub fn wrap(auth: &SwimAuth, _to: SocketAddr, msg: &SwimMessage) -> Result<Vec<u8>, SwimError> {
104 let inner = codec::encode(msg)?;
105 let seq = auth.seq_out.next();
106 let mut out = Vec::with_capacity(auth_envelope::ENVELOPE_OVERHEAD + inner.len());
107 auth_envelope::write_envelope(auth.local_addr_hash, seq, &inner, &auth.mac_key, &mut out)
108 .map_err(|e| SwimError::Encode {
109 detail: format!("swim envelope: {e}"),
110 })?;
111 Ok(out)
112}
113
114/// Parse an inbound datagram: verify MAC, bind envelope's advertised
115/// origin to the observed remote address, reject replays, then decode

Callers 6

sendMethod · 0.85
rejects_tampered_macFunction · 0.85
rejects_replayFunction · 0.85

Calls 4

write_envelopeFunction · 0.85
encodeFunction · 0.70
nextMethod · 0.45
lenMethod · 0.45

Tested by 5

rejects_tampered_macFunction · 0.68
rejects_replayFunction · 0.68