pub struct DhtKey(/* private fields */);Expand description
DHT key derived from trust root and capability path.
A 256-bit hash used as the key in a Kademlia-style DHT. Keys are derived deterministically from trust root and capability path, enabling capability-based discovery.
§Key Derivation
key = SHA256(trust_root || "/" || capability_path)§Examples
use agent_uri::{TrustRoot, CapabilityPath};
use agent_uri_dht::DhtKey;
let trust_root = TrustRoot::parse("anthropic.com").unwrap();
let path = CapabilityPath::parse("assistant/chat").unwrap();
let key = DhtKey::derive(&trust_root, &path);
// Keys are deterministic
let key2 = DhtKey::derive(&trust_root, &path);
assert_eq!(key, key2);Implementations§
Source§impl DhtKey
impl DhtKey
Sourcepub const fn from_bytes(bytes: [u8; 32]) -> Self
pub const fn from_bytes(bytes: [u8; 32]) -> Self
Sourcepub fn derive(trust_root: &TrustRoot, capability_path: &CapabilityPath) -> Self
pub fn derive(trust_root: &TrustRoot, capability_path: &CapabilityPath) -> Self
Sourcepub fn derive_at_depth(
trust_root: &TrustRoot,
capability_path: &CapabilityPath,
depth: usize,
) -> Option<Self>
pub fn derive_at_depth( trust_root: &TrustRoot, capability_path: &CapabilityPath, depth: usize, ) -> Option<Self>
Derives a DHT key for a specific path depth (prefix query support).
This enables hierarchical discovery by deriving keys for path prefixes.
§Arguments
trust_root- The trust root (authority)capability_path- The full capability pathdepth- The number of path segments to include (1-indexed)
§Returns
A key for the path truncated to the specified depth.
Returns None if depth is 0 or exceeds the path depth.
§Examples
use agent_uri::{TrustRoot, CapabilityPath};
use agent_uri_dht::DhtKey;
let trust_root = TrustRoot::parse("anthropic.com").unwrap();
let path = CapabilityPath::parse("assistant/chat/streaming").unwrap();
// Key for "assistant" only
let key1 = DhtKey::derive_at_depth(&trust_root, &path, 1).unwrap();
// Key for "assistant/chat"
let key2 = DhtKey::derive_at_depth(&trust_root, &path, 2).unwrap();
// Full path key
let key3 = DhtKey::derive_at_depth(&trust_root, &path, 3).unwrap();
assert_eq!(key3, DhtKey::derive(&trust_root, &path));Sourcepub fn distance(&self, other: &Self) -> Self
pub fn distance(&self, other: &Self) -> Self
Computes the XOR distance to another key.
This is the fundamental distance metric for Kademlia routing. Closer keys (lower XOR distance) are more likely to be stored on the same or nearby nodes.
§Arguments
other- The key to compute distance to
§Returns
A DhtKey representing the XOR distance (interpretable as a 256-bit unsigned integer).
Sourcepub fn leading_zeros(&self) -> u32
pub fn leading_zeros(&self) -> u32
Returns the leading zero bits in the key.
Useful for Kademlia bucket calculations.
Trait Implementations§
impl Copy for DhtKey
Source§impl<'de> Deserialize<'de> for DhtKey
Available on crate feature serde only.
impl<'de> Deserialize<'de> for DhtKey
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for DhtKey
Source§impl Ord for DhtKey
impl Ord for DhtKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for DhtKey
impl PartialOrd for DhtKey
impl StructuralPartialEq for DhtKey
Auto Trait Implementations§
impl Freeze for DhtKey
impl RefUnwindSafe for DhtKey
impl Send for DhtKey
impl Sync for DhtKey
impl Unpin for DhtKey
impl UnsafeUnpin for DhtKey
impl UnwindSafe for DhtKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)