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