pub fn ssh_address(&self) -> Option<SocketAddr> {
        use itertools::Itertools;

        // Order e1 & e2 by most recent timestamp
        let recency = |e1: &TargetAddrEntry, e2: &TargetAddrEntry| e2.timestamp.cmp(&e1.timestamp);

        // Order by link-local first, then by recency
        let link_local_recency = |e1: &TargetAddrEntry, e2: &TargetAddrEntry| match (
            e1.addr.ip().is_link_local_addr(),
            e2.addr.ip().is_link_local_addr(),
        ) {
            (true, true) | (false, false) => recency(e1, e2),
            (true, false) => Ordering::Less,
            (false, true) => Ordering::Greater,
        };

        let manual_link_local_recency = |e1: &TargetAddrEntry, e2: &TargetAddrEntry| {
            match (&e1.addr_type, &e2.addr_type) {
                // Note: for manually added addresses, they are ordered strictly
                // by recency, not link-local first.
                (TargetAddrType::Manual, TargetAddrType::Manual) => recency(e1, e2),
                (TargetAddrType::Manual, TargetAddrType::Ssh) => Ordering::Less,
                (TargetAddrType::Ssh, TargetAddrType::Manual) => Ordering::Greater,
                (TargetAddrType::Ssh, TargetAddrType::Ssh) => link_local_recency(e1, e2),
                _ => Ordering::Less, // Should not get here due to filtering in next line.
            }
        };

        let target_addr = self
            .addrs
            .borrow()
            .iter()
            .filter(|t| match t.addr_type {
                TargetAddrType::Manual | TargetAddrType::Ssh => true,
                _ => false,
            })
            .sorted_by(|e1, e2| manual_link_local_recency(e1, e2))
            .next()
            .map(|e| e.addr);

        target_addr.map(|target_addr| {
            let mut socket_addr: SocketAddr = target_addr.into();
            socket_addr.set_port(self.ssh_port().unwrap_or(DEFAULT_SSH_PORT));
            socket_addr
        })
    }
/// ssh_address returns the SocketAddr of the next SSH address to connect to for this target.
///
/// The sort algorithm for SSH address priority is in order of:
/// - Manual addresses first
///   - By recency of observation
/// - Other addresses
///   - By link-local first
///   - By most recently observed
///
/// The host-pipe connection mechanism will requests addresses from this function on each
/// connection attempt.
ssh_address returns the SocketAddr of the next SSH address to connect to for this target.
The sort algorithm for SSH address priority is in order of:
Manual addresses first
By recency of observation
Other addresses
By link-local first
By most recently observed

The host-pipe connection mechanism will requests addresses from this function on each
connection attempt.
ssh_address returns the SocketAddr of the next SSH address to connect to for this target . The sort algorithm for SSH address priority is in order of : Manual addresses first By recency of observation Other addresses By link - local first By most recently observed The host - pipe connection mechanism will requests addresses from this function on each connection attempt .
pub fn ssh_address(&self) -> Option<SocketAddr> {
        use itertools::Itertools;
        // Order e1 & e2 by most recent timestamp
        let recency = |e1: &TargetAddrEntry, e2: &TargetAddrEntry| e2.timestamp.cmp(&e1.timestamp);
        // Order by link-local first, then by recency
        let link_local_recency = |e1: &TargetAddrEntry, e2: &TargetAddrEntry| match (
            e1.addr.ip().is_link_local_addr(),
            e2.addr.ip().is_link_local_addr(),
        ) {
            (true, true) | (false, false) => recency(e1, e2),
            (true, false) => Ordering::Less,
            (false, true) => Ordering::Greater,
        };
        let manual_link_local_recency = |e1: &TargetAddrEntry, e2: &TargetAddrEntry| {
            match (&e1.addr_type, &e2.addr_type) {
                // Note: for manually added addresses, they are ordered strictly
                // by recency, not link-local first.
                (TargetAddrType::Manual, TargetAddrType::Manual) => recency(e1, e2),
                (TargetAddrType::Manual, TargetAddrType::Ssh) => Ordering::Less,
                (TargetAddrType::Ssh, TargetAddrType::Manual) => Ordering::Greater,
                (TargetAddrType::Ssh, TargetAddrType::Ssh) => link_local_recency(e1, e2),
                _ => Ordering::Less, // Should not get here due to filtering in next line.
            }
        };
        let target_addr = self
            .addrs
            .borrow()
            .iter()
            .filter(|t| match t.addr_type {
                TargetAddrType::Manual | TargetAddrType::Ssh => true,
                _ => false,
            })
            .sorted_by(|e1, e2| manual_link_local_recency(e1, e2))
            .next()
            .map(|e| e.addr);
        target_addr.map(|target_addr| {
            let mut socket_addr: SocketAddr = target_addr.into();
            socket_addr.set_port(self.ssh_port().unwrap_or(DEFAULT_SSH_PORT));
            socket_addr
        })
    }
pub fn ssh_address ( & self ) -> Option < SocketAddr > { use itertools :: Itertools ; // Order e1 & e2 by most recent timestamp let recency = | e1 : & TargetAddrEntry , e2 : & TargetAddrEntry | e2 . timestamp . cmp ( & e1 . timestamp ) ; // Order by link-local first, then by recency let link_local_recency = | e1 : & TargetAddrEntry , e2 : & TargetAddrEntry | match ( e1 . addr . ip ( ) . is_link_local_addr ( ) , e2 . addr . ip ( ) . is_link_local_addr ( ) , ) { ( true , true ) | ( false , false ) => recency ( e1 , e2 ) , ( true , false ) => Ordering :: Less , ( false , true ) => Ordering :: Greater , } ; let manual_link_local_recency = | e1 : & TargetAddrEntry , e2 : & TargetAddrEntry | { match ( & e1 . addr_type , & e2 . addr_type ) { // Note: for manually added addresses, they are ordered strictly // by recency, not link-local first. ( TargetAddrType :: Manual , TargetAddrType :: Manual ) => recency ( e1 , e2 ) , ( TargetAddrType :: Manual , TargetAddrType :: Ssh ) => Ordering :: Less , ( TargetAddrType :: Ssh , TargetAddrType :: Manual ) => Ordering :: Greater , ( TargetAddrType :: Ssh , TargetAddrType :: Ssh ) => link_local_recency ( e1 , e2 ) , _ => Ordering :: Less , // Should not get here due to filtering in next line. } } ; let target_addr = self . addrs . borrow ( ) . iter ( ) . filter ( | t | match t . addr_type { TargetAddrType :: Manual | TargetAddrType :: Ssh => true , _ => false , } ) . sorted_by ( | e1 , e2 | manual_link_local_recency ( e1 , e2 ) ) . next ( ) . map ( | e | e . addr ) ; target_addr . map ( | target_addr | { let mut socket_addr : SocketAddr = target_addr . into ( ) ; socket_addr . set_port ( self . ssh_port ( ) . unwrap_or ( DEFAULT_SSH_PORT ) ) ; socket_addr } ) }
ssh_address returns the SocketAddr of the next SSH address to connect to for this target.
ssh_address returns the SocketAddr of the next SSH address to connect to for this target .
&self
&self