Skip to main content

DHTNode

Struct DHTNode 

Source
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: f64

Implementations§

Source§

impl DHTNode

Source

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>.

Source

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).

Source

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 Clone for DHTNode

Source§

fn clone(&self) -> DHTNode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DHTNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for DHTNode

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<DHTNode, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for DHTNode

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'de, T> BorrowedRpcObject<'de> for T
where T: RpcBorrow<'de> + RpcSend,

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<'de, T> RpcBorrow<'de> for T
where T: Deserialize<'de> + Debug + Send + Sync + Unpin,

Source§

impl<T> RpcObject for T
where T: RpcSend + RpcRecv,

Source§

impl<T> RpcRecv for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,

Source§

impl<T> RpcSend for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more