fn maybe_ping<T, F>(
        &mut self,
        now: Instant,
        node: (Pubkey, SocketAddr),
        mut pingf: F,
    ) -> Option<Ping<T>>
    where
        T: Serialize,
        F: FnMut() -> Option<Ping<T>>,
    {
        // Rate limit consecutive pings sent to a remote node.
        let delay = self.ttl / 64;
        match self.pings.peek(&node) {
            Some(t) if now.saturating_duration_since(*t) < delay => None,
            _ => {
                let ping = pingf()?;
                let hash = hash::hash(&serialize(&ping.token).ok()?);
                self.pings.put(node, now);
                self.pending_cache.put(hash, node);
                Some(ping)
            }
        }
    }
/// Checks if the remote node has been pinged recently. If not, calls the
/// given function to generates a new ping message, records current
/// timestamp and hash of ping token, and returns the ping message.
Checks if the remote node has been pinged recently. If not, calls the
given function to generates a new ping message, records current
timestamp and hash of ping token, and returns the ping message.
Checks if the remote node has been pinged recently . If not calls the given function to generates a new ping message records current timestamp and hash of ping token and returns the ping message .
fn maybe_ping<T, F>(
        &mut self,
        now: Instant,
        node: (Pubkey, SocketAddr),
        mut pingf: F,
    ) -> Option<Ping<T>>
    where
        T: Serialize,
        F: FnMut() -> Option<Ping<T>>,
    {
        // Rate limit consecutive pings sent to a remote node.
        let delay = self.ttl / 64;
        match self.pings.peek(&node) {
            Some(t) if now.saturating_duration_since(*t) < delay => None,
            _ => {
                let ping = pingf()?;
                let hash = hash::hash(&serialize(&ping.token).ok()?);
                self.pings.put(node, now);
                self.pending_cache.put(hash, node);
                Some(ping)
            }
        }
    }
fn maybe_ping < T , F > ( & mut self , now : Instant , node : ( Pubkey , SocketAddr ) , mut pingf : F , ) -> Option < Ping < T > > where T : Serialize , F : FnMut ( ) -> Option < Ping < T > > , { // Rate limit consecutive pings sent to a remote node. let delay = self . ttl / 64 ; match self . pings . peek ( & node ) { Some ( t ) if now . saturating_duration_since ( * t ) < delay => None , _ => { let ping = pingf ( ) ? ; let hash = hash :: hash ( & serialize ( & ping . token ) . ok ( ) ? ) ; self . pings . put ( node , now ) ; self . pending_cache . put ( hash , node ) ; Some ( ping ) } } }
Checks if the remote node has been pinged recently.
Checks if the remote node has been pinged recently .
&mut self
now
Instant
node
(Pubkey, SocketAddr)
pingf
F