|
15 | 15 |
|
16 | 16 | module LeiosProtocol.Config where |
17 | 17 |
|
18 | | -import Data.Aeson (Options (allNullaryToStringTag), defaultOptions, genericToJSON) |
| 18 | +import Data.Aeson (Options (allNullaryToStringTag), defaultOptions, genericToEncoding, genericToJSON) |
19 | 19 | import Data.Aeson.Encoding (pairs) |
20 | 20 | import Data.Aeson.Types (Encoding, FromJSON (..), KeyValue ((.=)), Options (constructorTagModifier), Parser, ToJSON (..), Value (..), genericParseJSON, object, typeMismatch, withObject, (.:)) |
21 | 21 | import Data.Default (Default (..)) |
@@ -52,8 +52,16 @@ data DiffusionStrategy |
52 | 52 | OldestFirst |
53 | 53 | deriving (Show, Eq, Generic) |
54 | 54 |
|
| 55 | +data RelayStrategy |
| 56 | + = RequestFromFirst |
| 57 | + | RequestFromAll |
| 58 | + deriving (Show, Eq, Generic) |
| 59 | + |
55 | 60 | data Config = Config |
56 | | - { leiosStageLengthSlots :: Word |
| 61 | + { relayStrategy :: RelayStrategy |
| 62 | + , tcpCongestionControl :: Bool |
| 63 | + , multiplexMiniProtocols :: Bool |
| 64 | + , leiosStageLengthSlots :: Word |
57 | 65 | , leiosStageActiveVotingSlots :: Word |
58 | 66 | , leiosVoteSendRecvStages :: Bool |
59 | 67 | , txGenerationDistribution :: Distribution |
@@ -113,7 +121,10 @@ instance Default Config where |
113 | 121 | def :: Config |
114 | 122 | def = |
115 | 123 | Config |
116 | | - { leiosStageLengthSlots = 20 |
| 124 | + { relayStrategy = RequestFromFirst |
| 125 | + , tcpCongestionControl = True |
| 126 | + , multiplexMiniProtocols = True |
| 127 | + , leiosStageLengthSlots = 20 |
117 | 128 | , leiosStageActiveVotingSlots = 1 |
118 | 129 | , leiosVoteSendRecvStages = False |
119 | 130 | , txGenerationDistribution = Exp{lambda = 0.85, scale = Just 1000} |
@@ -251,6 +262,9 @@ instance ToJSON (OmitDefault Config) where |
251 | 262 |
|
252 | 263 | instance FromJSON Config where |
253 | 264 | parseJSON = withObject "Config" $ \obj -> do |
| 265 | + relayStrategy <- parseFieldOrDefault @Config @"relayStrategy" obj |
| 266 | + tcpCongestionControl <- parseFieldOrDefault @Config @"tcpCongestionControl" obj |
| 267 | + multiplexMiniProtocols <- parseFieldOrDefault @Config @"multiplexMiniProtocols" obj |
254 | 268 | leiosStageLengthSlots <- parseFieldOrDefault @Config @"leiosStageLengthSlots" obj |
255 | 269 | leiosStageActiveVotingSlots <- parseFieldOrDefault @Config @"leiosStageActiveVotingSlots" obj |
256 | 270 | leiosVoteSendRecvStages <- parseFieldOrDefault @Config @"leiosVoteSendRecvStages" obj |
@@ -350,21 +364,26 @@ instance FromJSON Distribution where |
350 | 364 | | otherwise -> do |
351 | 365 | typeMismatch "Distribution" (Object o) |
352 | 366 |
|
| 367 | +defaultEnumOptions :: Options |
| 368 | +defaultEnumOptions = |
| 369 | + defaultOptions |
| 370 | + { constructorTagModifier = camelToKebab |
| 371 | + , allNullaryToStringTag = True |
| 372 | + } |
| 373 | + |
353 | 374 | instance FromJSON DiffusionStrategy where |
354 | | - parseJSON = |
355 | | - genericParseJSON |
356 | | - defaultOptions |
357 | | - { constructorTagModifier = camelToKebab |
358 | | - , allNullaryToStringTag = True |
359 | | - } |
| 375 | + parseJSON = genericParseJSON defaultEnumOptions |
360 | 376 |
|
361 | 377 | instance ToJSON DiffusionStrategy where |
362 | | - toJSON = |
363 | | - genericToJSON |
364 | | - defaultOptions |
365 | | - { constructorTagModifier = camelToKebab |
366 | | - , allNullaryToStringTag = True |
367 | | - } |
| 378 | + toJSON = genericToJSON defaultEnumOptions |
| 379 | + toEncoding = genericToEncoding defaultEnumOptions |
| 380 | + |
| 381 | +instance FromJSON RelayStrategy where |
| 382 | + parseJSON = genericParseJSON defaultEnumOptions |
| 383 | + |
| 384 | +instance ToJSON RelayStrategy where |
| 385 | + toJSON = genericToJSON defaultEnumOptions |
| 386 | + toEncoding = genericToEncoding defaultEnumOptions |
368 | 387 |
|
369 | 388 | -- | Create a 'Config' from a file. |
370 | 389 | readConfigEither :: FilePath -> IO (Either ParseException Config) |
|
0 commit comments