ouroboros-network
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.PeerSelection.State.KnownPeers

Synopsis

Types

data KnownPeers peeraddr Source #

The set of known peers. To a first approximation it can be thought of as a Set of peeraddr.

It has one special feature:

  • It tracks the subset of peers that we are happy to publish in reply to peer share requests to our node. It supports random sampling from this set.

Instances

Instances details
Show peeraddr => Show (KnownPeers peeraddr) Source # 
Instance details

Defined in Ouroboros.Network.PeerSelection.State.KnownPeers

Methods

showsPrec :: Int -> KnownPeers peeraddr -> ShowS #

show :: KnownPeers peeraddr -> String #

showList :: [KnownPeers peeraddr] -> ShowS #

Ord peeraddr => Eq (KnownPeers peeraddr) Source # 
Instance details

Defined in Ouroboros.Network.PeerSelection.State.KnownPeers

Methods

(==) :: KnownPeers peeraddr -> KnownPeers peeraddr -> Bool #

(/=) :: KnownPeers peeraddr -> KnownPeers peeraddr -> Bool #

data KnownPeerInfo Source #

Constructors

KnownPeerInfo 

Fields

  • knownPeerFailCount :: !Int

    The current number of consecutive connection attempt failures. This is reset as soon as there is a successful connection.

    It is used to implement the exponential backoff strategy and may also be used by policies to select peers to forget.

  • knownPeerTepid :: !Bool

    Indicates if the peer was hot but then got demoted.

    It is set on the hot to warm promotion and reset on cold to warm, thus it can be present for warm or cold peers. It's purpose is to provide information to demotion policies.

    It is also used as useful information for the Peer Selection Governor when deciding which peers to share when Peer Sharing.

  • knownPeerSharing :: !PeerSharing

    Indicates current remote Peer Willingness information.

    If a connection with this address hasn't been established we won't have any information about this particular flag

    It is used by the Peer Sharing logic to decide if we should share/ask about/to this peer's address to others.

  • knownPeerAdvertise :: !PeerAdvertise

    Indicates current local Peer Willingness information.

    If this address didn't come from a local configuration then this value is set to DoAdvertise by default.

    It is used by the Peer Sharing logic to decide if we should share about this peer's address to others.

  • knownSuccessfulConnection :: !Bool

    Indicates if the node managed to connect to the peer at some point in time.

    This differs from the tepid flag in a way that this flag will be set/enabled if we established a successful connection with this peer. It won't be unset after this.

invariant :: Ord peeraddr => KnownPeers peeraddr -> Bool Source #

allPeers :: KnownPeers peeraddr -> Map peeraddr KnownPeerInfo Source #

All the known peers.

KnownPeerInfo operations

Basic container operations

empty :: KnownPeers peeraddr Source #

size :: KnownPeers peeraddr -> Int Source #

insert :: Ord peeraddr => Map peeraddr (Maybe PeerSharing, Maybe PeerAdvertise) -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

This inserts a map of peers with its respective peer sharing, peer advertise and ledger flags into the known peers set.

Please note that if in the map there's an entry for a peer already present in the known peers set, then its values will only be overwritten if they are a Just. Otherwise the current information will be preserved. On the other hand if there's an entry for a peer that isn't a member of the known peer set, the Nothing values will default to PeerSharingDisabled, DoNotAdvertisePeer and IsNotLedgerPeer, respectively, unless a Just value is used.

alter :: Ord peeraddr => (Maybe KnownPeerInfo -> Maybe KnownPeerInfo) -> Set peeraddr -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

delete :: Ord peeraddr => Set peeraddr -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

toSet :: KnownPeers peeraddr -> Set peeraddr Source #

O(n)

member :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Bool Source #

Special operations

setCurrentTime :: Ord peeraddr => Time -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

incrementFailCount :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> (Int, KnownPeers peeraddr) Source #

resetFailCount :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

lookupFailCount :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Maybe Int Source #

lookupTepidFlag :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Maybe Bool Source #

setTepidFlag :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

clearTepidFlag :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

setSuccessfulConnectionFlag :: Ord peeraddr => Set peeraddr -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

Tracking when we can (re)connect

minConnectTime Source #

Arguments

:: Ord peeraddr 
=> KnownPeers peeraddr 
-> (peeraddr -> Bool)

a predicate which describes the peers to take into account

-> Maybe Time 

setConnectTimes :: Ord peeraddr => Map peeraddr Time -> KnownPeers peeraddr -> KnownPeers peeraddr Source #

availableToConnect :: KnownPeers peeraddr -> Set peeraddr Source #

The subset of known peers that we would be allowed to try to establish a connection to now. This is because we have not connected with them before or because any failure backoff time has expired.

Selecting peers to ask

canPeerShareRequest :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Bool Source #

getPeerSharingRequestPeers :: Ord peeraddr => Set peeraddr -> KnownPeers peeraddr -> Set peeraddr Source #

Filter peers available for Peer Sharing requests, according to their PeerSharing information

Selecting peers to share

canSharePeers :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Bool Source #

getPeerSharingResponsePeers :: KnownPeers peeraddr -> Set peeraddr Source #

Filter peers available for Peer Sharing replies, according to their PeerAdvertise information