@@ -43,15 +43,16 @@ module Ouroboros.Network.PeerSelection.State.KnownPeers
4343import Data.List qualified as List
4444import Data.Map.Strict (Map )
4545import Data.Map.Strict qualified as Map
46+ import Data.Maybe.Strict
4647import Data.OrdPSQ (OrdPSQ )
4748import Data.OrdPSQ qualified as PSQ
4849import Data.Set (Set )
4950import Data.Set qualified as Set
5051
52+ import Control.Applicative ((<|>) )
5153import Control.Exception (assert )
5254import Control.Monad.Class.MonadTime.SI
5355
54- import Data.Maybe (fromMaybe )
5556import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise (.. ))
5657import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (.. ))
5758
@@ -114,7 +115,7 @@ data KnownPeerInfo = KnownPeerInfo {
114115 --
115116 -- It is used by the Peer Sharing logic to decide if we should share/ask
116117 -- about/to this peer's address to others.
117- knownPeerSharing :: ! PeerSharing ,
118+ knownPeerSharing :: ! ( StrictMaybe PeerSharing ) ,
118119
119120 -- | Indicates current local Peer Willingness information.
120121 --
@@ -123,7 +124,7 @@ data KnownPeerInfo = KnownPeerInfo {
123124 --
124125 -- It is used by the Peer Sharing logic to decide if we should share
125126 -- about this peer's address to others.
126- knownPeerAdvertise :: ! PeerAdvertise ,
127+ knownPeerAdvertise :: ! ( StrictMaybe PeerAdvertise ) ,
127128
128129 -- | Indicates if the node managed to connect to the peer at some point
129130 -- in time.
@@ -165,14 +166,16 @@ alterKnownPeerInfo (peerSharing, peerAdvertise) peerLookupResult =
165166 KnownPeerInfo {
166167 knownPeerFailCount = 0
167168 , knownPeerTepid = False
168- , knownPeerSharing = fromMaybe PeerSharingDisabled peerSharing
169- , knownPeerAdvertise = fromMaybe DoNotAdvertisePeer peerAdvertise
169+ , knownPeerSharing = maybeToStrictMaybe peerSharing
170+ , knownPeerAdvertise = maybeToStrictMaybe peerAdvertise
170171 , knownSuccessfulConnection = False
171172 }
172173 Just kpi -> Just $
173174 kpi {
174- knownPeerSharing = fromMaybe (knownPeerSharing kpi) peerSharing
175- , knownPeerAdvertise = fromMaybe (knownPeerAdvertise kpi) peerAdvertise
175+ knownPeerSharing = maybeToStrictMaybe peerSharing
176+ <|> knownPeerSharing kpi
177+ , knownPeerAdvertise = maybeToStrictMaybe peerAdvertise
178+ <|> knownPeerAdvertise kpi
176179 }
177180
178181-------------------------------
@@ -437,7 +440,7 @@ canPeerShareRequest :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Bool
437440canPeerShareRequest pa KnownPeers { allPeers } =
438441 case Map. lookup pa allPeers of
439442 Just KnownPeerInfo
440- { knownPeerSharing = PeerSharingEnabled
443+ { knownPeerSharing = SJust PeerSharingEnabled
441444 } -> True
442445 _ -> False
443446
@@ -448,7 +451,7 @@ canSharePeers :: Ord peeraddr => peeraddr -> KnownPeers peeraddr -> Bool
448451canSharePeers pa KnownPeers { allPeers } =
449452 case Map. lookup pa allPeers of
450453 Just KnownPeerInfo
451- { knownPeerAdvertise = DoAdvertisePeer
454+ { knownPeerAdvertise = SJust DoAdvertisePeer
452455 , knownSuccessfulConnection = True
453456 , knownPeerFailCount = 0
454457 } -> True
@@ -473,7 +476,7 @@ getPeerSharingResponsePeers knownPeers =
473476 Map. keysSet
474477 $ Map. filter (\ case
475478 KnownPeerInfo
476- { knownPeerAdvertise = DoAdvertisePeer
479+ { knownPeerAdvertise = SJust DoAdvertisePeer
477480 , knownSuccessfulConnection = True
478481 , knownPeerFailCount = 0
479482 } -> True
0 commit comments