| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.DHT.Distance
Description
XOR distance metric for the Kademlia DHT.
All distance computations operate on 256-bit SHA-256 keys. Distance is the XOR of two keys interpreted as a 256-bit unsigned integer.
Synopsis
- peerIdToKey :: PeerId -> DHTKey
- xorDistance :: DHTKey -> DHTKey -> DHTKey
- commonPrefixLength :: DHTKey -> DHTKey -> Int
- compareDistance :: DHTKey -> DHTKey -> DHTKey -> Ordering
- sortByDistance :: DHTKey -> [BucketEntry] -> [BucketEntry]
Documentation
peerIdToKey :: PeerId -> DHTKey Source #
Convert a Peer ID to its DHT key by hashing with SHA-256.
commonPrefixLength :: DHTKey -> DHTKey -> Int Source #
Count the number of leading zero bits (common prefix length). Same key → 256. First bit differs → 0.
compareDistance :: DHTKey -> DHTKey -> DHTKey -> Ordering Source #
Compare two keys by distance to a target. Returns LT if a is closer to target than b, GT if farther, EQ if equal.
sortByDistance :: DHTKey -> [BucketEntry] -> [BucketEntry] Source #
Sort bucket entries by ascending XOR distance to a target key.