use generic_array::GenericArray; use reth_primitives::{keccak256, NodeRecord, PeerId}; /// The key type for the table. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub(crate) struct NodeKey(pub(crate) PeerId); impl From for NodeKey { fn from(value: PeerId) -> Self { NodeKey(value) } } impl From for discv5::Key { fn from(value: NodeKey) -> Self { let hash = keccak256(value.0.as_bytes()); let hash = *GenericArray::from_slice(hash.as_bytes()); discv5::Key::new_raw(value, hash) } } impl From<&NodeRecord> for NodeKey { fn from(node: &NodeRecord) -> Self { NodeKey(node.id) } } /// Converts a `PeerId` into the required `Key` type for the table #[inline] pub(crate) fn kad_key(node: PeerId) -> discv5::Key { discv5::kbucket::Key::from(NodeKey::from(node)) }