From fba49cf93dedae21cbe884db8c0124c0d3c88730 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 14 Oct 2021 14:13:44 +0200 Subject: Add .is_up() on connection state --- src/peering/fullmesh.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs index c521590..ea753e1 100644 --- a/src/peering/fullmesh.rs +++ b/src/peering/fullmesh.rs @@ -74,6 +74,13 @@ pub struct PeerInfo { pub med_ping: Option, } +impl PeerInfo { + /// Returns true if we can currently send requests to this peer + pub fn is_up(&self) -> bool { + self.state.is_up() + } +} + /// PeerConnState: possible states for our tentative connections to given peer /// This structure is only interested in recording connection info for outgoing /// TCP connections @@ -96,6 +103,13 @@ pub enum PeerConnState { Abandonned, } +impl PeerConnState { + /// Returns true if we can currently send requests to this peer + pub fn is_up(&self) -> bool { + matches!(self, Self::Ourself | Self::Connected) + } +} + struct KnownHosts { list: HashMap, hash: hash::Digest, -- cgit v1.2.3