GuardMgr:: generalize GuardId::from_relay.
This commit is contained in:
parent
24e89a470f
commit
8306a9cdcf
|
@ -194,7 +194,11 @@ impl Guard {
|
|||
params.lifetime_unconfirmed / 10,
|
||||
);
|
||||
|
||||
Self::new(GuardId::from_relay(relay), relay.addrs().into(), added_at)
|
||||
Self::new(
|
||||
GuardId::from_chan_target(relay),
|
||||
relay.addrs().into(),
|
||||
added_at,
|
||||
)
|
||||
}
|
||||
|
||||
/// Return a new, manually constructed [`Guard`].
|
||||
|
|
|
@ -936,9 +936,9 @@ impl GuardId {
|
|||
Self { ed25519, rsa }
|
||||
}
|
||||
|
||||
/// Extract a GuardId from a Relay object.
|
||||
pub(crate) fn from_relay(relay: &tor_netdir::Relay<'_>) -> Self {
|
||||
Self::new(*relay.id(), *relay.rsa_id())
|
||||
/// Extract a GuardId from a ChanTarget object.
|
||||
pub fn from_chan_target<T: tor_linkspec::ChanTarget>(target: &T) -> Self {
|
||||
GuardId::new(*target.ed_identity(), *target.rsa_identity())
|
||||
}
|
||||
|
||||
/// Return the relay in `netdir` that corresponds to this ID, if there
|
||||
|
|
|
@ -235,7 +235,7 @@ impl GuardSet {
|
|||
fn contains_relay(&self, relay: &Relay<'_>) -> bool {
|
||||
// Note: Could implement Borrow instead, but I don't think it'll
|
||||
// matter.
|
||||
let id = GuardId::from_relay(relay);
|
||||
let id = GuardId::from_chan_target(relay);
|
||||
self.guards.contains_key(&id)
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ impl GuardSet {
|
|||
///
|
||||
/// Does nothing if it is already a guard.
|
||||
fn add_guard(&mut self, relay: &Relay<'_>, now: SystemTime, params: &GuardParams) {
|
||||
let id = GuardId::from_relay(relay);
|
||||
let id = GuardId::from_chan_target(relay);
|
||||
if self.guards.contains_key(&id) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue