Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
ouroboros-network-api
independent of `ouroboros-network-framew…
…ork` This way `ouroboros-network-protocols` does not contain `ouroboros-network-framework` as its transitive dependency.
- Loading branch information
Showing
11 changed files
with
152 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
ouroboros-network-api/src/Ouroboros/Network/Protocol/Limits.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE QuantifiedConstraints #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Ouroboros.Network.Protocol.Limits where | ||
|
||
import Control.Exception | ||
import Control.Monad.Class.MonadTime | ||
|
||
import Network.TypedProtocol.Core | ||
|
||
import Ouroboros.Network.Util.ShowProxy | ||
|
||
|
||
data ProtocolSizeLimits ps bytes = ProtocolSizeLimits { | ||
sizeLimitForState :: forall (pr :: PeerRole) (st :: ps). | ||
PeerHasAgency pr st -> Word, | ||
|
||
dataSize :: bytes -> Word | ||
} | ||
|
||
data ProtocolTimeLimits ps = ProtocolTimeLimits { | ||
timeLimitForState :: forall (pr :: PeerRole) (st :: ps). | ||
PeerHasAgency pr st -> Maybe DiffTime | ||
} | ||
|
||
data ProtocolLimitFailure where | ||
ExceededSizeLimit :: forall (pr :: PeerRole) ps (st :: ps). | ||
( forall (st' :: ps). Show (ClientHasAgency st') | ||
, forall (st' :: ps). Show (ServerHasAgency st') | ||
, ShowProxy ps | ||
) | ||
=> PeerHasAgency pr st | ||
-> ProtocolLimitFailure | ||
ExceededTimeLimit :: forall (pr :: PeerRole) ps (st :: ps). | ||
( forall (st' :: ps). Show (ClientHasAgency st') | ||
, forall (st' :: ps). Show (ServerHasAgency st') | ||
, ShowProxy ps | ||
) | ||
=> PeerHasAgency pr st | ||
-> ProtocolLimitFailure | ||
|
||
instance Show ProtocolLimitFailure where | ||
show (ExceededSizeLimit (stok :: PeerHasAgency pr (st :: ps))) = | ||
concat | ||
[ "ExceededSizeLimit (" | ||
, showProxy (Proxy :: Proxy ps) | ||
, ") (" | ||
, show stok | ||
, ")" | ||
] | ||
show (ExceededTimeLimit (stok :: PeerHasAgency pr (st :: ps))) = | ||
concat | ||
[ "ExceededTimeLimit (" | ||
, showProxy (Proxy :: Proxy ps) | ||
, ") (" | ||
, show stok | ||
, ")" | ||
] | ||
|
||
instance Exception ProtocolLimitFailure where | ||
|
||
|
||
-- TODO: better limits | ||
|
||
largeByteLimit :: Word | ||
largeByteLimit = 2500000 | ||
|
||
smallByteLimit :: Word | ||
smallByteLimit = 0xffff | ||
|
||
shortWait :: Maybe DiffTime | ||
shortWait = Just 10 | ||
|
||
longWait :: Maybe DiffTime | ||
longWait = Just 60 | ||
|
||
waitForever :: Maybe DiffTime | ||
waitForever = Nothing | ||
|
64 changes: 64 additions & 0 deletions
64
ouroboros-network-api/src/Ouroboros/Network/Protocol/Type.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE QuantifiedConstraints #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Ouroboros.Network.Protocol.Type where | ||
|
||
import Control.Exception | ||
import Control.Monad.Class.MonadTime | ||
|
||
import Network.TypedProtocol.Core | ||
|
||
import Ouroboros.Network.Util.ShowProxy | ||
|
||
|
||
data ProtocolSizeLimits ps bytes = ProtocolSizeLimits { | ||
sizeLimitForState :: forall (pr :: PeerRole) (st :: ps). | ||
PeerHasAgency pr st -> Word, | ||
|
||
dataSize :: bytes -> Word | ||
} | ||
|
||
data ProtocolTimeLimits ps = ProtocolTimeLimits { | ||
timeLimitForState :: forall (pr :: PeerRole) (st :: ps). | ||
PeerHasAgency pr st -> Maybe DiffTime | ||
} | ||
|
||
data ProtocolLimitFailure where | ||
ExceededSizeLimit :: forall (pr :: PeerRole) ps (st :: ps). | ||
( forall (st' :: ps). Show (ClientHasAgency st') | ||
, forall (st' :: ps). Show (ServerHasAgency st') | ||
, ShowProxy ps | ||
) | ||
=> PeerHasAgency pr st | ||
-> ProtocolLimitFailure | ||
ExceededTimeLimit :: forall (pr :: PeerRole) ps (st :: ps). | ||
( forall (st' :: ps). Show (ClientHasAgency st') | ||
, forall (st' :: ps). Show (ServerHasAgency st') | ||
, ShowProxy ps | ||
) | ||
=> PeerHasAgency pr st | ||
-> ProtocolLimitFailure | ||
|
||
instance Show ProtocolLimitFailure where | ||
show (ExceededSizeLimit (stok :: PeerHasAgency pr (st :: ps))) = | ||
concat | ||
[ "ExceededSizeLimit (" | ||
, showProxy (Proxy :: Proxy ps) | ||
, ") (" | ||
, show stok | ||
, ")" | ||
] | ||
show (ExceededTimeLimit (stok :: PeerHasAgency pr (st :: ps))) = | ||
concat | ||
[ "ExceededTimeLimit (" | ||
, showProxy (Proxy :: Proxy ps) | ||
, ") (" | ||
, show stok | ||
, ")" | ||
] | ||
|
||
instance Exception ProtocolLimitFailure where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
ouroboros-network-framework/src/Ouroboros/Network/Protocol/Limits.hs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters