module Ouroboros.Consensus.Node.ExitPolicy (
    NodeToNodeInitiatorResult (..)
  , returnPolicy
    -- * Re-exports
  , ReturnPolicy
  ) where

import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client as CSClient
import           Ouroboros.Network.ExitPolicy


-- | Result of any of the `node-to-node` mini-protocols.  We ignore all but
-- `chain-sync` results.
--
data NodeToNodeInitiatorResult =
    ChainSyncInitiatorResult !CSClient.ChainSyncClientResult
  | NoInitiatorResult


returnPolicy :: ReturnPolicy NodeToNodeInitiatorResult
returnPolicy :: ReturnPolicy NodeToNodeInitiatorResult
returnPolicy NodeToNodeInitiatorResult
NoInitiatorResult = DiffTime -> RepromoteDelay
RepromoteDelay DiffTime
10
returnPolicy (ChainSyncInitiatorResult ChainSyncClientResult
result) = case ChainSyncClientResult
result of
  -- TODO: it would be nice to have additional context to predict when we will
  -- be ready to reconnect.
  CSClient.ForkTooDeep      Point blk
_ Our (Tip blk)
_ourTip Their (Tip blk)
_theirTip -> DiffTime -> RepromoteDelay
RepromoteDelay DiffTime
120
  CSClient.NoMoreIntersection Our (Tip blk)
_ourTip Their (Tip blk)
_theirTip -> DiffTime -> RepromoteDelay
RepromoteDelay DiffTime
120
  CSClient.RolledBackPastIntersection
                            Point blk
_ Our (Tip blk)
_ourTip Their (Tip blk)
_theirTip -> DiffTime -> RepromoteDelay
RepromoteDelay DiffTime
180
  -- the outbound-governor asked for hot to warm demotion; it's up to the
  -- governor to decide to promote the peer to hot.
  ChainSyncClientResult
CSClient.AskedToTerminate                     -> DiffTime -> RepromoteDelay
RepromoteDelay DiffTime
10