pub struct DHTNode {
pub peer_id: PeerId,
pub addresses: Vec<MultiAddr>,
pub address_types: Vec<AddressType>,
pub distance: Option<Vec<u8>>,
pub reliability: f64,
}Expand description
DHT node representation for network operations.
The addresses field stores one or more typed MultiAddr values.
Peers may be multi-homed or reachable via NAT traversal at several
endpoints.
Fields§
§peer_id: PeerId§addresses: Vec<MultiAddr>§address_types: Vec<AddressType>Type tag for each address, parallel to addresses by index.
Defaults to empty on deserialization (legacy records or wire data from
nodes that predate ADR-014). When empty, callers treat all addresses
as [AddressType::Unverified] — a legacy peer never asserted
reachability for its published sockets, so the conservative default
is “publisher did not claim direct-dialability.” This excludes the
entries from first_direct_dialable (relay-candidate selection)
while keeping them in the general dial priority queue as a
last-resort cold-start fallback.
Populated when constructing from DHT routing-table entries so
consumers (e.g., saorsa-node) can inspect the address types of
peers returned by find_closest_nodes_local().
distance: Option<Vec<u8>>Optional per-record metadata. In current DHT responses this may carry
a marker-encoded PublishAddressSet sequence so newer nodes can prefer
fresher address records without changing the wire shape for older nodes.
reliability: f64Implementations§
Source§impl DHTNode
impl DHTNode
Sourcepub fn typed_addresses(&self) -> Vec<(MultiAddr, AddressType)>
pub fn typed_addresses(&self) -> Vec<(MultiAddr, AddressType)>
Pair each address with its type tag.
Local-scope IP addresses are always returned as [AddressType::Lan],
even if the sender advertised a stronger tag. Other untagged entries
(legacy records that predate ADR-014, or any position past the end of
address_types) default to [AddressType::Unverified]. A legacy
publisher never asserted reachability for these sockets, so we refuse
to let them stand in for a verified Direct tag.
The returned vec preserves the storage order from addresses;
callers that need Relay-first ordering should pass the result to
[DhtNetworkManager::dialable_addresses_typed] or use
Self::addresses_by_priority for a pre-sorted Vec<MultiAddr>.
Sourcepub fn addresses_by_priority(&self) -> Vec<MultiAddr>
pub fn addresses_by_priority(&self) -> Vec<MultiAddr>
Addresses sorted by [AddressType] priority: Relay first, then
Direct, Unverified, and Lan. Within each tier the original insertion
order is preserved (stable sort).
Use this instead of raw addresses whenever the caller needs to
dial or pass addresses to a consumer that will try them in order
(e.g., send_message, reconnect_and_send).
Sourcepub fn merge_from(&mut self, other: DHTNode)
pub fn merge_from(&mut self, other: DHTNode)
Merge another DHTNode’s typed addresses into this one.
Each incoming (addr, ty) pair is added if the address is not
already present; if it is present, the type is upgraded when the
incoming tag has strictly higher priority (e.g. an existing
Unverified is promoted to Relay when a Relay-tagged duplicate
arrives). The final list is sorted by [AddressType::priority]
and capped at the incoming node’s entry count plus the existing
entries — no arbitrary truncation.
Intended for the iterative FIND_NODE path in
[DhtNetworkManager::find_closest_nodes_network]: different
responders may have different views of the same peer (one saw
only a connection-observed listen port, another received the
peer’s PublishAddressSet with a Relay entry), and merging all
of them gives the caller the union — so select_dial_candidates
can pick the best tier rather than being locked into whichever
response happened to arrive first.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DHTNode
impl<'de> Deserialize<'de> for DHTNode
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DHTNode, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DHTNode, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for DHTNode
impl Serialize for DHTNode
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for DHTNode
impl RefUnwindSafe for DHTNode
impl Send for DHTNode
impl Sync for DHTNode
impl Unpin for DHTNode
impl UnsafeUnpin for DHTNode
impl UnwindSafe for DHTNode
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
impl<'de, T> BorrowedRpcObject<'de> for T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more