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

Function addr_hash

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

Deterministic hash of a `SocketAddr` into a `u64`. Uses SHA-256 truncated to the first 8 bytes. Deterministic across processes and hosts so that sender and receiver agree on the value. Not a MAC — the envelope MAC is the actual integrity primitive; this hash exists only as a binding between the envelope's claimed origin and the packet's observed source address.

(addr: SocketAddr)

Source from the content-addressed store, hash-verified

55/// hash exists only as a binding between the envelope's claimed origin
56/// and the packet's observed source address.
57pub fn addr_hash(addr: SocketAddr) -> u64 {
58 let mut h = Sha256::new();
59 h.update(addr.to_string().as_bytes());
60 let digest = h.finalize();
61 u64::from_le_bytes(digest[..8].try_into().expect("sha256 is 32 bytes"))
62}
63
64/// Per-transport auth state: MAC key, per-peer outbound counters, and a
65/// per-peer inbound replay-detection window. Owned by the

Callers 2

newMethod · 0.85
unwrapFunction · 0.85

Calls 5

to_stringMethod · 0.80
updateMethod · 0.45
as_bytesMethod · 0.45
finalizeMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected