module Ouroboros.Network.PeerSelection.Types
  ( PeerSource (..)
  , PeerStatus (..)
  ) where

-- | Where did this peer come from? Policy functions can choose to treat
-- peers differently depending on where we found them from.
--
data PeerSource = PeerSourceLocalRoot
                | PeerSourcePublicRoot
                | PeerSourcePeerShare
  deriving (PeerSource -> PeerSource -> Bool
(PeerSource -> PeerSource -> Bool)
-> (PeerSource -> PeerSource -> Bool) -> Eq PeerSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerSource -> PeerSource -> Bool
== :: PeerSource -> PeerSource -> Bool
$c/= :: PeerSource -> PeerSource -> Bool
/= :: PeerSource -> PeerSource -> Bool
Eq, Eq PeerSource
Eq PeerSource =>
(PeerSource -> PeerSource -> Ordering)
-> (PeerSource -> PeerSource -> Bool)
-> (PeerSource -> PeerSource -> Bool)
-> (PeerSource -> PeerSource -> Bool)
-> (PeerSource -> PeerSource -> Bool)
-> (PeerSource -> PeerSource -> PeerSource)
-> (PeerSource -> PeerSource -> PeerSource)
-> Ord PeerSource
PeerSource -> PeerSource -> Bool
PeerSource -> PeerSource -> Ordering
PeerSource -> PeerSource -> PeerSource
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PeerSource -> PeerSource -> Ordering
compare :: PeerSource -> PeerSource -> Ordering
$c< :: PeerSource -> PeerSource -> Bool
< :: PeerSource -> PeerSource -> Bool
$c<= :: PeerSource -> PeerSource -> Bool
<= :: PeerSource -> PeerSource -> Bool
$c> :: PeerSource -> PeerSource -> Bool
> :: PeerSource -> PeerSource -> Bool
$c>= :: PeerSource -> PeerSource -> Bool
>= :: PeerSource -> PeerSource -> Bool
$cmax :: PeerSource -> PeerSource -> PeerSource
max :: PeerSource -> PeerSource -> PeerSource
$cmin :: PeerSource -> PeerSource -> PeerSource
min :: PeerSource -> PeerSource -> PeerSource
Ord, Int -> PeerSource -> ShowS
[PeerSource] -> ShowS
PeerSource -> String
(Int -> PeerSource -> ShowS)
-> (PeerSource -> String)
-> ([PeerSource] -> ShowS)
-> Show PeerSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerSource -> ShowS
showsPrec :: Int -> PeerSource -> ShowS
$cshow :: PeerSource -> String
show :: PeerSource -> String
$cshowList :: [PeerSource] -> ShowS
showList :: [PeerSource] -> ShowS
Show, Int -> PeerSource
PeerSource -> Int
PeerSource -> [PeerSource]
PeerSource -> PeerSource
PeerSource -> PeerSource -> [PeerSource]
PeerSource -> PeerSource -> PeerSource -> [PeerSource]
(PeerSource -> PeerSource)
-> (PeerSource -> PeerSource)
-> (Int -> PeerSource)
-> (PeerSource -> Int)
-> (PeerSource -> [PeerSource])
-> (PeerSource -> PeerSource -> [PeerSource])
-> (PeerSource -> PeerSource -> [PeerSource])
-> (PeerSource -> PeerSource -> PeerSource -> [PeerSource])
-> Enum PeerSource
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: PeerSource -> PeerSource
succ :: PeerSource -> PeerSource
$cpred :: PeerSource -> PeerSource
pred :: PeerSource -> PeerSource
$ctoEnum :: Int -> PeerSource
toEnum :: Int -> PeerSource
$cfromEnum :: PeerSource -> Int
fromEnum :: PeerSource -> Int
$cenumFrom :: PeerSource -> [PeerSource]
enumFrom :: PeerSource -> [PeerSource]
$cenumFromThen :: PeerSource -> PeerSource -> [PeerSource]
enumFromThen :: PeerSource -> PeerSource -> [PeerSource]
$cenumFromTo :: PeerSource -> PeerSource -> [PeerSource]
enumFromTo :: PeerSource -> PeerSource -> [PeerSource]
$cenumFromThenTo :: PeerSource -> PeerSource -> PeerSource -> [PeerSource]
enumFromThenTo :: PeerSource -> PeerSource -> PeerSource -> [PeerSource]
Enum)

data PeerStatus =
       PeerCold
     -- ^ Peer is in true cold which means no connection to exists
     -- and the outbound governor is safe to promote it.
     | PeerCooling
     -- ^ Peer is in cold state but its connection still lingers.
     -- I.e. it is still in progress to be fully demoted.
     --
     -- Note:
     -- The `PeerCooling -> PeerCold` state transition is an `outbound-governor`
     -- reflection of the connection-manager's `TerminatingSt -> TerminatedSt`
     -- state transition (our version of tcp's `TimeWait`).  It is only
     -- triggered in case of a clean connection shutdown, not in the case of
     -- errors.
     --
     | PeerWarm
     | PeerHot
  deriving (PeerStatus -> PeerStatus -> Bool
(PeerStatus -> PeerStatus -> Bool)
-> (PeerStatus -> PeerStatus -> Bool) -> Eq PeerStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerStatus -> PeerStatus -> Bool
== :: PeerStatus -> PeerStatus -> Bool
$c/= :: PeerStatus -> PeerStatus -> Bool
/= :: PeerStatus -> PeerStatus -> Bool
Eq, Eq PeerStatus
Eq PeerStatus =>
(PeerStatus -> PeerStatus -> Ordering)
-> (PeerStatus -> PeerStatus -> Bool)
-> (PeerStatus -> PeerStatus -> Bool)
-> (PeerStatus -> PeerStatus -> Bool)
-> (PeerStatus -> PeerStatus -> Bool)
-> (PeerStatus -> PeerStatus -> PeerStatus)
-> (PeerStatus -> PeerStatus -> PeerStatus)
-> Ord PeerStatus
PeerStatus -> PeerStatus -> Bool
PeerStatus -> PeerStatus -> Ordering
PeerStatus -> PeerStatus -> PeerStatus
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PeerStatus -> PeerStatus -> Ordering
compare :: PeerStatus -> PeerStatus -> Ordering
$c< :: PeerStatus -> PeerStatus -> Bool
< :: PeerStatus -> PeerStatus -> Bool
$c<= :: PeerStatus -> PeerStatus -> Bool
<= :: PeerStatus -> PeerStatus -> Bool
$c> :: PeerStatus -> PeerStatus -> Bool
> :: PeerStatus -> PeerStatus -> Bool
$c>= :: PeerStatus -> PeerStatus -> Bool
>= :: PeerStatus -> PeerStatus -> Bool
$cmax :: PeerStatus -> PeerStatus -> PeerStatus
max :: PeerStatus -> PeerStatus -> PeerStatus
$cmin :: PeerStatus -> PeerStatus -> PeerStatus
min :: PeerStatus -> PeerStatus -> PeerStatus
Ord, Int -> PeerStatus -> ShowS
[PeerStatus] -> ShowS
PeerStatus -> String
(Int -> PeerStatus -> ShowS)
-> (PeerStatus -> String)
-> ([PeerStatus] -> ShowS)
-> Show PeerStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerStatus -> ShowS
showsPrec :: Int -> PeerStatus -> ShowS
$cshow :: PeerStatus -> String
show :: PeerStatus -> String
$cshowList :: [PeerStatus] -> ShowS
showList :: [PeerStatus] -> ShowS
Show)