Struct tor_netdir::NetDir
source · [−]pub struct NetDir { /* private fields */ }
Expand description
A view of the Tor directory, suitable for use in building circuits.
Abstractly, a NetDir
is a set of usable public Relay
s,
each of which has its own properties, identity, and correct weighted
probability for use under different circumstances.
A NetDir
is constructed by making a PartialNetDir
from a
consensus document, and then adding enough microdescriptors to
that PartialNetDir
so that it can be used to build paths.
(Thus, if you have a NetDir, it is definitely adequate to build
paths.)
Implementations
sourceimpl NetDir
impl NetDir
sourcepub fn replace_overridden_parameters(&mut self, new_replacement: &NetParams<i32>)
pub fn replace_overridden_parameters(&mut self, new_replacement: &NetParams<i32>)
Replace the overridden parameters in this netdir with new_replacement
.
After this function is done, the netdir’s parameters will be those in
the consensus, overridden by settings from new_replacement
. Any
settings in the old replacement parameters will be discarded.
sourcepub fn all_relays(&self) -> impl Iterator<Item = UncheckedRelay<'_>>
pub fn all_relays(&self) -> impl Iterator<Item = UncheckedRelay<'_>>
Return an iterator over all Relay objects, including invalid ones that we can’t use.
sourcepub fn relays(&self) -> impl Iterator<Item = Relay<'_>>
pub fn relays(&self) -> impl Iterator<Item = Relay<'_>>
Return an iterator over all usable Relays.
sourcepub fn by_id(&self, id: &Ed25519Identity) -> Option<Relay<'_>>
pub fn by_id(&self, id: &Ed25519Identity) -> Option<Relay<'_>>
Return a relay matching a given Ed25519 identity, if we have a usable relay with that key.
(Does not return unusable relays.)
Note that if a microdescriptor is subsequently added for a relay with this ID, the ID may become usable.
sourcepub fn by_id_pair(
&self,
ed_id: &Ed25519Identity,
rsa_id: &RsaIdentity
) -> Option<Relay<'_>>
pub fn by_id_pair(
&self,
ed_id: &Ed25519Identity,
rsa_id: &RsaIdentity
) -> Option<Relay<'_>>
Return a relay matching a given Ed25519 identity and RSA identity, if we have a usable relay with both keys.
(Does not return unusable relays.)
Note that if a microdescriptor is subsequently added for a relay with this ID, the ID may become usable.
sourcepub fn by_chantarget(&self, chan_target: &impl ChanTarget) -> Option<Relay<'_>>
pub fn by_chantarget(&self, chan_target: &impl ChanTarget) -> Option<Relay<'_>>
Return the usable relay matching a given ChanTarget
’s
identities, if any.
(Does not return unusable relays.)
sourcepub fn id_pair_listed(
&self,
ed_id: &Ed25519Identity,
rsa_id: &RsaIdentity
) -> Option<bool>
pub fn id_pair_listed(
&self,
ed_id: &Ed25519Identity,
rsa_id: &RsaIdentity
) -> Option<bool>
Return a boolean if this consensus definitely has (or does not have) a relay matching both the given Ed25519 and RSA identity.
If we can’t yet tell for sure, return None.
Once function has returned Some(b)
, it will always return that
value for the same ed_id
and rsa_id
on this NetDir
. A None
answer may later become Some(b)
if a microdescriptor arrives.
sourcepub fn missing_descriptor_for(&self, rsa_id: &RsaIdentity) -> bool
pub fn missing_descriptor_for(&self, rsa_id: &RsaIdentity) -> bool
Return true if we are currently missing a micro descriptor for the given RSA identity.
A descriptor is missing
only if it is listed in the consensus,
but we don’t have it downloaded.
sourcepub fn by_rsa_id_unchecked(
&self,
rsa_id: &RsaIdentity
) -> Option<UncheckedRelay<'_>>
pub fn by_rsa_id_unchecked(
&self,
rsa_id: &RsaIdentity
) -> Option<UncheckedRelay<'_>>
Return a (possibly unusable) relay with a given RSA identity.
sourcepub fn by_rsa_id(&self, rsa_id: &RsaIdentity) -> Option<Relay<'_>>
pub fn by_rsa_id(&self, rsa_id: &RsaIdentity) -> Option<Relay<'_>>
Return the relay with a given RSA identity, if we have one and it is usable.
sourcepub fn rsa_id_is_listed(&self, rsa_id: &RsaIdentity) -> bool
pub fn rsa_id_is_listed(&self, rsa_id: &RsaIdentity) -> bool
Return true if rsa_id
is listed in this directory, even if it
isn’t currently usable.
sourcepub fn params(&self) -> &NetParameters
pub fn params(&self) -> &NetParameters
Return the parameters from the consensus, clamped to the correct ranges, with defaults filled in.
NOTE: that unsupported parameters aren’t returned here; only those
values configured in the params
module are available.
sourcepub fn pick_relay<'a, R, P>(
&'a self,
rng: &mut R,
role: WeightRole,
usable: P
) -> Option<Relay<'a>> where
R: Rng,
P: FnMut(&Relay<'a>) -> bool,
pub fn pick_relay<'a, R, P>(
&'a self,
rng: &mut R,
role: WeightRole,
usable: P
) -> Option<Relay<'a>> where
R: Rng,
P: FnMut(&Relay<'a>) -> bool,
Choose a relay at random.
Each relay is chosen with probability proportional to its weight
in the role role
, and is only selected if the predicate usable
returns true for it.
This function returns None if (and only if) there are no relays
with nonzero weight where usable
returned true.
sourcepub fn pick_n_relays<'a, R, P>(
&'a self,
rng: &mut R,
n: usize,
role: WeightRole,
usable: P
) -> Vec<Relay<'a>> where
R: Rng,
P: FnMut(&Relay<'a>) -> bool,
pub fn pick_n_relays<'a, R, P>(
&'a self,
rng: &mut R,
n: usize,
role: WeightRole,
usable: P
) -> Vec<Relay<'a>> where
R: Rng,
P: FnMut(&Relay<'a>) -> bool,
Choose n
relay at random.
Each relay is chosen with probability proportional to its weight
in the role role
, and is only selected if the predicate usable
returns true for it.
Relays are chosen without replacement: no relay will be
returned twice. Therefore, the resulting vector may be smaller
than n
if we happen to have fewer than n
appropriate relays.
This function returns an empty vector if (and only if) there
are no relays with nonzero weight where usable
returned
true.
sourcepub fn relay_weight<'a>(
&'a self,
relay: &Relay<'a>,
role: WeightRole
) -> RelayWeight
pub fn relay_weight<'a>(
&'a self,
relay: &Relay<'a>,
role: WeightRole
) -> RelayWeight
Compute the weight with which relay
will be selected for a given
role
.
sourcepub fn total_weight<P>(&self, role: WeightRole, usable: P) -> RelayWeight where
P: Fn(&UncheckedRelay<'_>) -> bool,
pub fn total_weight<P>(&self, role: WeightRole, usable: P) -> RelayWeight where
P: Fn(&UncheckedRelay<'_>) -> bool,
Compute the total weight with which any relay matching usable
will be selected for a given role
.
Note: because this function is used to assess the total
properties of the consensus, the usable
predicate takes a
RouterStatus
rather than a Relay
.
sourcepub fn weight_by_rsa_id(
&self,
rsa_id: &RsaIdentity,
role: WeightRole
) -> Option<RelayWeight>
pub fn weight_by_rsa_id(
&self,
rsa_id: &RsaIdentity,
role: WeightRole
) -> Option<RelayWeight>
Compute the weight with which a relay with ID rsa_id
would be
selected for a given role
.
Note that weight returned by this function assumes that the relay with that ID is actually usable; if it isn’t usable, then other weight-related functions will call its weight zero.
sourcepub fn known_family_members<'a>(
&'a self,
relay: &'a Relay<'a>
) -> impl Iterator<Item = Relay<'a>>
pub fn known_family_members<'a>(
&'a self,
relay: &'a Relay<'a>
) -> impl Iterator<Item = Relay<'a>>
Return all relays in this NetDir known to be in the same family as
relay
.
This list of members will not necessarily include relay
itself.
Limitations
Two relays only belong to the same family if each relay claims to share a family with the other. But if we are missing a microdescriptor for one of the relays listed by this relay, we cannot know whether it acknowledges family membership with this relay or not. Therefore, this function can omit family members for which there is not (as yet) any Relay object.
Trait Implementations
sourceimpl MdReceiver for NetDir
impl MdReceiver for NetDir
sourcefn missing_microdescs(&self) -> Box<dyn Iterator<Item = &MdDigest> + '_>
fn missing_microdescs(&self) -> Box<dyn Iterator<Item = &MdDigest> + '_>
Return an iterator over the digests for all of the microdescriptors that this netdir is missing. Read more
sourcefn add_microdesc(&mut self, md: Microdesc) -> bool
fn add_microdesc(&mut self, md: Microdesc) -> bool
Add a microdescriptor to this netdir, if it was wanted. Read more
Auto Trait Implementations
impl RefUnwindSafe for NetDir
impl Send for NetDir
impl Sync for NetDir
impl Unpin for NetDir
impl UnwindSafe for NetDir
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more