-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap UnversionedProtocol for HydraVersionedProtocol
- Loading branch information
1 parent
ffb0b1c
commit 180199a
Showing
6 changed files
with
227 additions
and
44 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
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
75 changes: 75 additions & 0 deletions
75
hydra-node/src/Hydra/Network/Ouroboros/VersionedProtocol.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,75 @@ | ||
module Hydra.Network.Ouroboros.VersionedProtocol where | ||
|
||
import Hydra.Prelude | ||
|
||
import Codec.CBOR.Term qualified as CBOR | ||
import Data.Text qualified as T | ||
import Hydra.Network (Host (..)) | ||
import Network.TypedProtocol.Pipelined () | ||
import Ouroboros.Network.CodecCBORTerm (CodecCBORTerm (..)) | ||
import Ouroboros.Network.Protocol.Handshake.Codec (VersionDataCodec, cborTermVersionDataCodec) | ||
import Ouroboros.Network.Protocol.Handshake.Version (Accept (..), Acceptable, Queryable, acceptableVersion, queryVersion) | ||
|
||
hydraVersionedProtocolCodec :: CodecCBORTerm (String, Maybe Int) HydraVersionedProtocolNumber | ||
hydraVersionedProtocolCodec = CodecCBORTerm{encodeTerm, decodeTerm} | ||
where | ||
encodeTerm :: HydraVersionedProtocolNumber -> CBOR.Term | ||
encodeTerm x = CBOR.TInt $ hydraVersionedProtocolNumber x | ||
|
||
decodeTerm :: CBOR.Term -> Either (String, Maybe Int) HydraVersionedProtocolNumber | ||
decodeTerm (CBOR.TInt x) = Right $ MkHydraVersionedProtocolNumber x | ||
decodeTerm _ = Left ("unknown tag", Nothing) | ||
|
||
type HydraVersionedProtocolNumber :: Type | ||
newtype HydraVersionedProtocolNumber = MkHydraVersionedProtocolNumber {hydraVersionedProtocolNumber :: Int} | ||
deriving stock (Eq, Show, Generic, Ord) | ||
|
||
type HydraVersionedProtocolData :: Type | ||
data HydraVersionedProtocolData = MkHydraVersionedProtocolData | ||
deriving stock (Eq, Show, Generic, Ord) | ||
|
||
instance Acceptable HydraVersionedProtocolData where | ||
acceptableVersion | ||
MkHydraVersionedProtocolData | ||
MkHydraVersionedProtocolData = Accept MkHydraVersionedProtocolData | ||
|
||
instance Queryable HydraVersionedProtocolData where | ||
queryVersion MkHydraVersionedProtocolData = False | ||
|
||
hydraVersionedProtocolDataCodec :: | ||
VersionDataCodec | ||
CBOR.Term | ||
HydraVersionedProtocolNumber | ||
HydraVersionedProtocolData | ||
hydraVersionedProtocolDataCodec = | ||
cborTermVersionDataCodec | ||
(const CodecCBORTerm{encodeTerm, decodeTerm}) | ||
where | ||
encodeTerm :: HydraVersionedProtocolData -> CBOR.Term | ||
encodeTerm MkHydraVersionedProtocolData = CBOR.TNull | ||
|
||
decodeTerm :: CBOR.Term -> Either Text HydraVersionedProtocolData | ||
decodeTerm CBOR.TNull = Right MkHydraVersionedProtocolData | ||
decodeTerm t = Left $ T.pack $ "unexpected term: " ++ show t | ||
|
||
type HydraNetworkConfig :: Type | ||
data HydraNetworkConfig = HydraNetworkConfig | ||
{ protocolVersion :: HydraVersionedProtocolNumber | ||
, localHost :: Host | ||
, remoteHosts :: [Host] | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
|
||
type KnownHydraVersions :: Type | ||
data KnownHydraVersions | ||
= KnownHydraVersions {fromKnownHydraVersions :: [HydraVersionedProtocolNumber]} | ||
| NoKnownHydraVersions | ||
deriving stock (Eq, Show, Generic) | ||
|
||
type HydraHandshakeRefused :: Type | ||
data HydraHandshakeRefused = HydraHandshakeRefused | ||
{ remoteHost :: Host | ||
, ourVersion :: HydraVersionedProtocolNumber | ||
, theirVersions :: KnownHydraVersions | ||
} | ||
deriving stock (Eq, Show, Generic) |
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
Oops, something went wrong.