forked from schmittlauch/Hash2Pub
allow messages without payload for ACKing
This commit is contained in:
parent
2b234d65db
commit
c304e2103f
|
@ -18,7 +18,7 @@ Request ::= SEQUENCE {
|
|||
leaveRequestPayload LeaveRequestPayload,
|
||||
stabiliseRequestPayload StabiliseRequestPayload,
|
||||
pingRequestPayload PingRequestPayload
|
||||
}
|
||||
} OPTIONAL -- just for symmetry reasons with response, requests without a payload have no meaning
|
||||
}
|
||||
|
||||
-- idea: different message layouts as a way of distinguishing between
|
||||
|
@ -36,7 +36,7 @@ Response ::= SEQUENCE {
|
|||
leaveResponsePayload LeaveResponsePayload,
|
||||
stabiliseResponsePayload StabiliseResponsePayload,
|
||||
pingResponsePayload PingResponsePayload
|
||||
}
|
||||
} OPTIONAL -- no payload when just ACKing a previous request
|
||||
}
|
||||
|
||||
NodeState ::= SEQUENCE {
|
||||
|
|
|
@ -215,7 +215,7 @@ encodeMessage
|
|||
++ [
|
||||
IntVal parts
|
||||
, IntVal part ]
|
||||
++ encodePayload requestPayload
|
||||
++ maybe [] encodePayload requestPayload
|
||||
++ [End Sequence]
|
||||
encodeMessage
|
||||
(Response responseTo senderID parts part action responsePayload) = [
|
||||
|
@ -225,7 +225,7 @@ encodeMessage
|
|||
, IntVal parts
|
||||
, IntVal part
|
||||
, Enumerated . fromIntegral . fromEnum $ action]
|
||||
++ encodePayload responsePayload
|
||||
++ maybe [] encodePayload responsePayload
|
||||
++ [End Sequence]
|
||||
|
||||
-- ===== parser combinators =====
|
||||
|
@ -258,7 +258,8 @@ parseRequest action = do
|
|||
sender <- parseNodeState
|
||||
parts <- parseInteger
|
||||
part <- parseInteger
|
||||
payload <- case action of
|
||||
hasPayload <- hasNext
|
||||
payload <- if not hasPayload then return Nothing else Just <$> case action of
|
||||
QueryID -> parseQueryIDRequest
|
||||
Join -> parseJoinRequest
|
||||
Leave -> parseLeaveRequest
|
||||
|
@ -273,7 +274,8 @@ parseResponse responseTo = do
|
|||
parts <- parseInteger
|
||||
part <- parseInteger
|
||||
action <- parseEnum :: ParseASN1 Action
|
||||
payload <- case action of
|
||||
hasPayload <- hasNext
|
||||
payload <- if not hasPayload then return Nothing else Just <$> case action of
|
||||
QueryID -> parseQueryIDResponse
|
||||
Join -> parseJoinResponse
|
||||
Leave -> parseLeaveResponse
|
||||
|
|
|
@ -97,7 +97,7 @@ data FediChordMessage =
|
|||
, part :: Integer
|
||||
-- ^ part starts at 0
|
||||
, action :: Action
|
||||
, payload :: ActionPayload
|
||||
, payload :: Maybe ActionPayload
|
||||
}
|
||||
| Response {
|
||||
responseTo :: Integer
|
||||
|
@ -105,7 +105,7 @@ data FediChordMessage =
|
|||
, parts :: Integer
|
||||
, part :: Integer
|
||||
, action :: Action
|
||||
, payload :: ActionPayload
|
||||
, payload :: Maybe ActionPayload
|
||||
} deriving (Show, Eq)
|
||||
|
||||
data ActionPayload =
|
||||
|
|
|
@ -212,8 +212,8 @@ spec = do
|
|||
, action = undefined
|
||||
, payload = undefined
|
||||
}
|
||||
requestWith a pa = requestTemplate {action = a, payload = pa}
|
||||
responseWith a pa = responseTemplate {action = a, payload = pa}
|
||||
requestWith a pa = requestTemplate {action = a, payload = Just pa}
|
||||
responseWith a pa = responseTemplate {action = a, payload = Just pa}
|
||||
|
||||
encodeDecodeAndCheck msg = runParseASN1 parseMessage (encodeMessage msg) `shouldBe` pure msg
|
||||
it "messages are encoded and decoded correctly from and to ASN1" $ do
|
||||
|
|
Loading…
Reference in a new issue