{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE GADTs               #-}
{-# LANGUAGE NamedFieldPuns      #-}
{-# LANGUAGE PolyKinds           #-}
{-# LANGUAGE RankNTypes          #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Ouroboros.Network.Protocol.PeerSharing.Codec where

import Control.Monad.Class.MonadST
import Control.Monad.Class.MonadTime.SI (DiffTime)

import Data.ByteString.Lazy (ByteString)

import Codec.CBOR.Decoding qualified as CBOR
import Codec.CBOR.Encoding qualified as CBOR
import Codec.CBOR.Read qualified as CBOR
import Codec.Serialise.Class qualified as CBOR

import Network.TypedProtocol.Codec.CBOR

import Ouroboros.Network.Protocol.Limits
import Ouroboros.Network.Protocol.PeerSharing.Type

codecPeerSharing :: forall m peerAddress.
                    MonadST m
                 => (peerAddress -> CBOR.Encoding)
                 -> (forall s . CBOR.Decoder s peerAddress)
                 -> Codec (PeerSharing peerAddress)
                         CBOR.DeserialiseFailure
                         m
                         ByteString
codecPeerSharing :: forall (m :: * -> *) peerAddress.
MonadST m =>
(peerAddress -> Encoding)
-> (forall s. Decoder s peerAddress)
-> Codec (PeerSharing peerAddress) DeserialiseFailure m ByteString
codecPeerSharing peerAddress -> Encoding
encodeAddress forall s. Decoder s peerAddress
decodeAddress = (forall (st :: PeerSharing peerAddress)
        (st' :: PeerSharing peerAddress).
 (StateTokenI st, ActiveState st) =>
 Message (PeerSharing peerAddress) st st' -> Encoding)
-> (forall (st :: PeerSharing peerAddress) s.
    ActiveState st =>
    StateToken st -> Decoder s (SomeMessage st))
-> Codec (PeerSharing peerAddress) DeserialiseFailure m ByteString
forall ps (m :: * -> *).
MonadST m =>
(forall (st :: ps) (st' :: ps).
 (StateTokenI st, ActiveState st) =>
 Message ps st st' -> Encoding)
-> (forall (st :: ps) s.
    ActiveState st =>
    StateToken st -> Decoder s (SomeMessage st))
-> Codec ps DeserialiseFailure m ByteString
mkCodecCborLazyBS Message (PeerSharing peerAddress) st st' -> Encoding
forall (st :: PeerSharing peerAddress)
       (st' :: PeerSharing peerAddress).
Message (PeerSharing peerAddress) st st' -> Encoding
forall (st :: PeerSharing peerAddress)
       (st' :: PeerSharing peerAddress).
(StateTokenI st, ActiveState st) =>
Message (PeerSharing peerAddress) st st' -> Encoding
encodeMsg StateToken st -> Decoder s (SomeMessage st)
forall (st :: PeerSharing peerAddress) s.
ActiveState st =>
StateToken st -> Decoder s (SomeMessage st)
decodeMsg
  where
    encodeMsg :: Message (PeerSharing peerAddress) st st'
              -> CBOR.Encoding
    encodeMsg :: forall (st :: PeerSharing peerAddress)
       (st' :: PeerSharing peerAddress).
Message (PeerSharing peerAddress) st st' -> Encoding
encodeMsg (MsgShareRequest PeerSharingAmount
amount) =
         Word -> Encoding
CBOR.encodeListLen Word
2
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
0
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PeerSharingAmount -> Encoding
forall a. Serialise a => a -> Encoding
CBOR.encode PeerSharingAmount
amount
    encodeMsg (MsgSharePeers [peerAddress1]
peers) =
         Word -> Encoding
CBOR.encodeListLen Word
2
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
1
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (peerAddress -> Encoding) -> [peerAddress] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
encodeListWith peerAddress -> Encoding
encodeAddress [peerAddress]
[peerAddress1]
peers
    encodeMsg Message (PeerSharing peerAddress) st st'
R:MessagePeerSharingfromto (*) peerAddress st st'
MsgDone =
         Word -> Encoding
CBOR.encodeListLen Word
1
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
2

    decodeMsg :: forall (st :: PeerSharing peerAddress) s.
                 ActiveState st
              => StateToken st
              -> CBOR.Decoder s (SomeMessage st)
    decodeMsg :: forall (st :: PeerSharing peerAddress) s.
ActiveState st =>
StateToken st -> Decoder s (SomeMessage st)
decodeMsg StateToken st
stok = do
      _ <- Decoder s Int
forall s. Decoder s Int
CBOR.decodeListLen
      key <- CBOR.decodeWord
      case (stok, key) of
        (SingPeerSharing st
SingIdle, Word
0) -> Message (PeerSharing peerAddress) st 'StBusy -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage (Message (PeerSharing peerAddress) st 'StBusy -> SomeMessage st)
-> (PeerSharingAmount
    -> Message (PeerSharing peerAddress) st 'StBusy)
-> PeerSharingAmount
-> SomeMessage st
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSharingAmount -> Message (PeerSharing peerAddress) st 'StBusy
PeerSharingAmount
-> Message (PeerSharing peerAddress) 'StIdle 'StBusy
forall {k} (peerAddress :: k).
PeerSharingAmount
-> Message (PeerSharing peerAddress) 'StIdle 'StBusy
MsgShareRequest
                         (PeerSharingAmount -> SomeMessage st)
-> Decoder s PeerSharingAmount -> Decoder s (SomeMessage st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s PeerSharingAmount
forall s. Decoder s PeerSharingAmount
forall a s. Serialise a => Decoder s a
CBOR.decode
        (SingPeerSharing st
SingBusy, Word
1) -> Message (PeerSharing peerAddress) st 'StIdle -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage (Message (PeerSharing peerAddress) st 'StIdle -> SomeMessage st)
-> ([peerAddress] -> Message (PeerSharing peerAddress) st 'StIdle)
-> [peerAddress]
-> SomeMessage st
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [peerAddress] -> Message (PeerSharing peerAddress) st 'StIdle
[peerAddress] -> Message (PeerSharing peerAddress) 'StBusy 'StIdle
forall peerAddress1.
[peerAddress1]
-> Message (PeerSharing peerAddress1) 'StBusy 'StIdle
MsgSharePeers
                         ([peerAddress] -> SomeMessage st)
-> Decoder s [peerAddress] -> Decoder s (SomeMessage st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s peerAddress -> Decoder s [peerAddress]
forall s a. Decoder s a -> Decoder s [a]
decodeListWith Decoder s peerAddress
forall s. Decoder s peerAddress
decodeAddress
        (SingPeerSharing st
SingIdle, Word
2) -> SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeMessage st -> Decoder s (SomeMessage st))
-> SomeMessage st -> Decoder s (SomeMessage st)
forall a b. (a -> b) -> a -> b
$ Message (PeerSharing peerAddress) st 'StDone -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (PeerSharing peerAddress) st 'StDone
Message (PeerSharing peerAddress) 'StIdle 'StDone
forall {k} (peerAddress :: k).
Message (PeerSharing peerAddress) 'StIdle 'StDone
MsgDone

        (SingPeerSharing st
SingIdle, Word
_) ->
          String -> Decoder s (SomeMessage st)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"codecPeerSharing.StIdle: unexpected key: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show Word
key)
        (SingPeerSharing st
SingBusy, Word
_) ->
          String -> Decoder s (SomeMessage st)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"codecPeerSharing.StBusy: unexpected key: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show Word
key)

        (a :: SingPeerSharing st
a@SingPeerSharing st
SingDone, Word
_) -> StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken 'StDone
SingPeerSharing st
a

    -- Definition as in Codec.Serialise.defaultEncodeList but indexed by an
    -- external encoder
    encodeListWith :: (a -> CBOR.Encoding) -> [a] -> CBOR.Encoding
    encodeListWith :: forall a. (a -> Encoding) -> [a] -> Encoding
encodeListWith a -> Encoding
_   [] = Word -> Encoding
CBOR.encodeListLen Word
0
    encodeListWith a -> Encoding
enc [a]
xs = Encoding
CBOR.encodeListLenIndef
                         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (a -> Encoding -> Encoding) -> Encoding -> [a] -> Encoding
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a
x Encoding
r -> a -> Encoding
enc a
x Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
r) Encoding
CBOR.encodeBreak [a]
xs

    -- Definition as in Codec.Serialise.defaultDecodeList but indexed by an
    -- external encoder
    decodeListWith :: CBOR.Decoder s a -> CBOR.Decoder s [a]
    decodeListWith :: forall s a. Decoder s a -> Decoder s [a]
decodeListWith Decoder s a
dec= do
        mn <- Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
CBOR.decodeListLenOrIndef
        case mn of
          Maybe Int
Nothing -> ([a] -> a -> [a])
-> [a] -> ([a] -> [a]) -> Decoder s a -> Decoder s [a]
forall r a r' s.
(r -> a -> r) -> r -> (r -> r') -> Decoder s a -> Decoder s r'
CBOR.decodeSequenceLenIndef ((a -> [a] -> [a]) -> [a] -> a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (:)) [] [a] -> [a]
forall a. [a] -> [a]
reverse   Decoder s a
dec
          Just Int
n  -> ([a] -> a -> [a])
-> [a] -> ([a] -> [a]) -> Int -> Decoder s a -> Decoder s [a]
forall r a r' s.
(r -> a -> r)
-> r -> (r -> r') -> Int -> Decoder s a -> Decoder s r'
CBOR.decodeSequenceLenN     ((a -> [a] -> [a]) -> [a] -> a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (:)) [] [a] -> [a]
forall a. [a] -> [a]
reverse Int
n Decoder s a
dec

codecPeerSharingId
  :: forall peerAddress m.
     Monad m
  => Codec (PeerSharing peerAddress) CodecFailure m (AnyMessage (PeerSharing peerAddress))
codecPeerSharingId :: forall {k} (peerAddress :: k) (m :: * -> *).
Monad m =>
Codec
  (PeerSharing peerAddress)
  CodecFailure
  m
  (AnyMessage (PeerSharing peerAddress))
codecPeerSharingId = (forall (st :: PeerSharing peerAddress)
        (st' :: PeerSharing peerAddress).
 (StateTokenI st, ActiveState st) =>
 Message (PeerSharing peerAddress) st st'
 -> AnyMessage (PeerSharing peerAddress))
-> (forall (st :: PeerSharing peerAddress).
    ActiveState st =>
    StateToken st
    -> m (DecodeStep
            (AnyMessage (PeerSharing peerAddress))
            CodecFailure
            m
            (SomeMessage st)))
-> Codec
     (PeerSharing peerAddress)
     CodecFailure
     m
     (AnyMessage (PeerSharing peerAddress))
forall ps failure (m :: * -> *) bytes.
(forall (st :: ps) (st' :: ps).
 (StateTokenI st, ActiveState st) =>
 Message ps st st' -> bytes)
-> (forall (st :: ps).
    ActiveState st =>
    StateToken st -> m (DecodeStep bytes failure m (SomeMessage st)))
-> Codec ps failure m bytes
Codec Message (PeerSharing peerAddress) st st'
-> AnyMessage (PeerSharing peerAddress)
forall (st :: PeerSharing peerAddress)
       (st' :: PeerSharing peerAddress).
(StateTokenI st, ActiveState st) =>
Message (PeerSharing peerAddress) st st'
-> AnyMessage (PeerSharing peerAddress)
encodeMsg StateToken st
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
decodeMsg
   where
     encodeMsg :: forall st st'.
                  StateTokenI st
               => ActiveState st
               => Message (PeerSharing peerAddress) st st'
               -> AnyMessage (PeerSharing peerAddress)
     encodeMsg :: forall (st :: PeerSharing peerAddress)
       (st' :: PeerSharing peerAddress).
(StateTokenI st, ActiveState st) =>
Message (PeerSharing peerAddress) st st'
-> AnyMessage (PeerSharing peerAddress)
encodeMsg = Message (PeerSharing peerAddress) st st'
-> AnyMessage (PeerSharing peerAddress)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage

     decodeMsg :: forall (st :: PeerSharing peerAddress).
                  ActiveState st
               => StateToken st
               -> m (DecodeStep (AnyMessage (PeerSharing peerAddress))
                          CodecFailure m (SomeMessage st))
     decodeMsg :: forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
decodeMsg StateToken st
stok = DecodeStep
  (AnyMessage (PeerSharing peerAddress))
  CodecFailure
  m
  (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (DecodeStep
   (AnyMessage (PeerSharing peerAddress))
   CodecFailure
   m
   (SomeMessage st)
 -> m (DecodeStep
         (AnyMessage (PeerSharing peerAddress))
         CodecFailure
         m
         (SomeMessage st)))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
forall a b. (a -> b) -> a -> b
$ (Maybe (AnyMessage (PeerSharing peerAddress))
 -> m (DecodeStep
         (AnyMessage (PeerSharing peerAddress))
         CodecFailure
         m
         (SomeMessage st)))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
(Maybe bytes -> m (DecodeStep bytes failure m a))
-> DecodeStep bytes failure m a
DecodePartial ((Maybe (AnyMessage (PeerSharing peerAddress))
  -> m (DecodeStep
          (AnyMessage (PeerSharing peerAddress))
          CodecFailure
          m
          (SomeMessage st)))
 -> DecodeStep
      (AnyMessage (PeerSharing peerAddress))
      CodecFailure
      m
      (SomeMessage st))
-> (Maybe (AnyMessage (PeerSharing peerAddress))
    -> m (DecodeStep
            (AnyMessage (PeerSharing peerAddress))
            CodecFailure
            m
            (SomeMessage st)))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
forall a b. (a -> b) -> a -> b
$ \Maybe (AnyMessage (PeerSharing peerAddress))
bytes -> DecodeStep
  (AnyMessage (PeerSharing peerAddress))
  CodecFailure
  m
  (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (DecodeStep
   (AnyMessage (PeerSharing peerAddress))
   CodecFailure
   m
   (SomeMessage st)
 -> m (DecodeStep
         (AnyMessage (PeerSharing peerAddress))
         CodecFailure
         m
         (SomeMessage st)))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (PeerSharing peerAddress))
        CodecFailure
        m
        (SomeMessage st))
forall a b. (a -> b) -> a -> b
$
       case (StateToken st
SingPeerSharing st
stok, Maybe (AnyMessage (PeerSharing peerAddress))
bytes) of
         (SingPeerSharing st
SingIdle, Just (AnyMessage msg :: Message (PeerSharing peerAddress) st st'
msg@(MsgShareRequest {})))
             -> SomeMessage st
-> Maybe (AnyMessage (PeerSharing peerAddress))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (PeerSharing peerAddress) st st' -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (PeerSharing peerAddress) st st'
Message (PeerSharing peerAddress) st st'
msg) Maybe (AnyMessage (PeerSharing peerAddress))
forall a. Maybe a
Nothing
         (SingPeerSharing st
SingBusy, Just (AnyMessage msg :: Message (PeerSharing peerAddress) st st'
msg@(MsgSharePeers {})))
             -> SomeMessage st
-> Maybe (AnyMessage (PeerSharing peerAddress))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (PeerSharing peerAddress) st st' -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (PeerSharing peerAddress) st st'
Message (PeerSharing peerAddress) st st'
msg) Maybe (AnyMessage (PeerSharing peerAddress))
forall a. Maybe a
Nothing
         (SingPeerSharing st
SingIdle, Just (AnyMessage msg :: Message (PeerSharing peerAddress) st st'
msg@(Message (PeerSharing peerAddress) st st'
R:MessagePeerSharingfromto k peerAddress st st'
MsgDone)))
             -> SomeMessage st
-> Maybe (AnyMessage (PeerSharing peerAddress))
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (PeerSharing peerAddress) st st' -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (PeerSharing peerAddress) st st'
Message (PeerSharing peerAddress) st st'
msg) Maybe (AnyMessage (PeerSharing peerAddress))
forall a. Maybe a
Nothing
         (SingPeerSharing st
_, Maybe (AnyMessage (PeerSharing peerAddress))
_) -> CodecFailure
-> DecodeStep
     (AnyMessage (PeerSharing peerAddress))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
failure -> DecodeStep bytes failure m a
DecodeFail (String -> CodecFailure
CodecFailure String
"codecPeerSharingId: no matching message")

-- | We assume that a TCP segment size of 1440 bytes with initial window of size
-- 4. This sets upper limit of 5760 bytes on each message of peer sharing
-- protocol, which means request and response should be done in a single RTT
--
maxTransmissionUnit :: Word
maxTransmissionUnit :: Word
maxTransmissionUnit = Word
4 Word -> Word -> Word
forall a. Num a => a -> a -> a
* Word
1440

byteLimitsPeerSharing :: forall peerAddress bytes.
                         (bytes -> Word)
                      -> ProtocolSizeLimits (PeerSharing peerAddress) bytes
byteLimitsPeerSharing :: forall {k} (peerAddress :: k) bytes.
(bytes -> Word)
-> ProtocolSizeLimits (PeerSharing peerAddress) bytes
byteLimitsPeerSharing = (forall (st :: PeerSharing peerAddress).
 ActiveState st =>
 StateToken st -> Word)
-> (bytes -> Word)
-> ProtocolSizeLimits (PeerSharing peerAddress) bytes
forall ps bytes.
(forall (st :: ps). ActiveState st => StateToken st -> Word)
-> (bytes -> Word) -> ProtocolSizeLimits ps bytes
ProtocolSizeLimits StateToken st -> Word
forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st -> Word
sizeLimitForState
  where
    sizeLimitForState :: forall (st :: PeerSharing peerAddress).
                         ActiveState st
                      => StateToken st -> Word
    sizeLimitForState :: forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st -> Word
sizeLimitForState StateToken st
SingPeerSharing st
SingIdle   = Word
maxTransmissionUnit
    sizeLimitForState StateToken st
SingPeerSharing st
SingBusy   = Word
maxTransmissionUnit
    sizeLimitForState a :: StateToken st
a@StateToken st
SingPeerSharing st
SingDone = StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken st
StateToken 'StDone
a


timeLimitsPeerSharing :: forall peerAddress. ProtocolTimeLimits (PeerSharing peerAddress)
timeLimitsPeerSharing :: forall {k} (peerAddress :: k).
ProtocolTimeLimits (PeerSharing peerAddress)
timeLimitsPeerSharing = ProtocolTimeLimits { StateToken st -> Maybe DiffTime
forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st -> Maybe DiffTime
timeLimitForState :: forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st -> Maybe DiffTime
timeLimitForState :: forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st -> Maybe DiffTime
timeLimitForState }
  where
    timeLimitForState :: forall (st :: PeerSharing peerAddress).
                         ActiveState st
                      => StateToken st
                      -> Maybe DiffTime
    timeLimitForState :: forall (st :: PeerSharing peerAddress).
ActiveState st =>
StateToken st -> Maybe DiffTime
timeLimitForState StateToken st
SingPeerSharing st
SingIdle   = Maybe DiffTime
waitForever
    timeLimitForState StateToken st
SingPeerSharing st
SingBusy   = Maybe DiffTime
longWait
    timeLimitForState a :: StateToken st
a@StateToken st
SingPeerSharing st
SingDone = StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken st
StateToken 'StDone
a