Commit 8306a9cd authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

GuardMgr:: generalize GuardId::from_relay.

parent 24e89a47
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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`].
+3 −3
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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;
        }