FediChordMessage: last part has falg instead of parts number in each msg
Motivation: Including the number of parts in each message part requires the total number of parts to be known in advance, making dynamic responses based on the received data difficult
This commit is contained in:
parent
fea9660f80
commit
f8d444d5b6
|
@ -4,14 +4,16 @@ NodeID ::= INTEGER (0..115792089237316195423570985008687907853269984665640564039
|
||||||
|
|
||||||
Domain ::= VisibleString
|
Domain ::= VisibleString
|
||||||
|
|
||||||
|
Partnum ::= INTEGER (0..150)
|
||||||
|
|
||||||
Action ::= ENUMERATED {queryID, join, leave, stabilise, ping}
|
Action ::= ENUMERATED {queryID, join, leave, stabilise, ping}
|
||||||
|
|
||||||
Request ::= SEQUENCE {
|
Request ::= SEQUENCE {
|
||||||
action Action,
|
action Action,
|
||||||
requestID INTEGER (0..4294967295), -- arbitrarily restricting to an unsigned 32bit integer
|
requestID INTEGER (0..4294967295), -- arbitrarily restricting to an unsigned 32bit integer
|
||||||
sender NodeState,
|
sender NodeState,
|
||||||
parts INTEGER (1..150), -- number of message parts
|
part Partnum, -- part number of this message, starts at 1
|
||||||
part INTEGER (1..150), -- part number of this message, starts at 1
|
finalPart BOOLEAN, -- flag indicating this `part` to be the last of this reuest
|
||||||
actionPayload CHOICE {
|
actionPayload CHOICE {
|
||||||
queryIDRequestPayload QueryIDRequestPayload,
|
queryIDRequestPayload QueryIDRequestPayload,
|
||||||
joinRequestPayload JoinRequestPayload,
|
joinRequestPayload JoinRequestPayload,
|
||||||
|
@ -27,8 +29,8 @@ Request ::= SEQUENCE {
|
||||||
Response ::= SEQUENCE {
|
Response ::= SEQUENCE {
|
||||||
responseTo INTEGER (0..4294967295), -- arbitrarily restricting to an unsigned 32bit integer
|
responseTo INTEGER (0..4294967295), -- arbitrarily restricting to an unsigned 32bit integer
|
||||||
senderID NodeID,
|
senderID NodeID,
|
||||||
parts INTEGER (0..150),
|
part Partnum,
|
||||||
part INTEGER (0..150),
|
finalPart BOOLEAN, -- flag indicating this `part` to be the last of this response
|
||||||
action Action,
|
action Action,
|
||||||
actionPayload CHOICE {
|
actionPayload CHOICE {
|
||||||
queryIDResponsePayload QueryIDResponsePayload,
|
queryIDResponsePayload QueryIDResponsePayload,
|
||||||
|
|
|
@ -103,7 +103,7 @@ serialiseMessage maxBytesLength msg =
|
||||||
modifyMessage i (partNum, pl) pls = (partNum, msg {
|
modifyMessage i (partNum, pl) pls = (partNum, msg {
|
||||||
part = partNum
|
part = partNum
|
||||||
, payload = Just pl
|
, payload = Just pl
|
||||||
, parts = fromIntegral i
|
, isFinalPart = partNum == fromIntegral i
|
||||||
}):pls
|
}):pls
|
||||||
-- part starts at 1
|
-- part starts at 1
|
||||||
payloadParts :: Int -> Maybe [(Integer, ActionPayload)]
|
payloadParts :: Int -> Maybe [(Integer, ActionPayload)]
|
||||||
|
@ -216,23 +216,22 @@ encodeQueryResult FORWARD{} = Enumerated 1
|
||||||
encodeMessage :: FediChordMessage -- ^ the 'FediChordMessage to be encoded
|
encodeMessage :: FediChordMessage -- ^ the 'FediChordMessage to be encoded
|
||||||
-> [ASN1]
|
-> [ASN1]
|
||||||
encodeMessage
|
encodeMessage
|
||||||
(Request requestID sender parts part action requestPayload) =
|
(Request requestID sender part isFinalPart action requestPayload) =
|
||||||
Start Sequence
|
Start Sequence
|
||||||
: (Enumerated . fromIntegral . fromEnum $ action)
|
: (Enumerated . fromIntegral . fromEnum $ action)
|
||||||
: IntVal requestID
|
: IntVal requestID
|
||||||
: encodeNodeState sender
|
: encodeNodeState sender
|
||||||
<> [
|
<> [IntVal part
|
||||||
IntVal parts
|
, Boolean isFinalPart]
|
||||||
, IntVal part ]
|
|
||||||
<> maybe [] encodePayload requestPayload
|
<> maybe [] encodePayload requestPayload
|
||||||
<> [End Sequence]
|
<> [End Sequence]
|
||||||
encodeMessage
|
encodeMessage
|
||||||
(Response responseTo senderID parts part action responsePayload) = [
|
(Response responseTo senderID part isFinalPart action responsePayload) = [
|
||||||
Start Sequence
|
Start Sequence
|
||||||
, IntVal responseTo
|
, IntVal responseTo
|
||||||
, IntVal . getNodeID $ senderID
|
, IntVal . getNodeID $ senderID
|
||||||
, IntVal parts
|
|
||||||
, IntVal part
|
, IntVal part
|
||||||
|
, Boolean isFinalPart
|
||||||
, Enumerated . fromIntegral . fromEnum $ action]
|
, Enumerated . fromIntegral . fromEnum $ action]
|
||||||
<> maybe [] encodePayload responsePayload
|
<> maybe [] encodePayload responsePayload
|
||||||
<> [End Sequence]
|
<> [End Sequence]
|
||||||
|
@ -265,8 +264,8 @@ parseRequest :: Action -> ParseASN1 FediChordMessage
|
||||||
parseRequest action = do
|
parseRequest action = do
|
||||||
requestID <- parseInteger
|
requestID <- parseInteger
|
||||||
sender <- parseNodeState
|
sender <- parseNodeState
|
||||||
parts <- parseInteger
|
|
||||||
part <- parseInteger
|
part <- parseInteger
|
||||||
|
isFinalPart <- parseBool
|
||||||
hasPayload <- hasNext
|
hasPayload <- hasNext
|
||||||
payload <- if not hasPayload then pure Nothing else Just <$> case action of
|
payload <- if not hasPayload then pure Nothing else Just <$> case action of
|
||||||
QueryID -> parseQueryIDRequest
|
QueryID -> parseQueryIDRequest
|
||||||
|
@ -275,13 +274,13 @@ parseRequest action = do
|
||||||
Stabilise -> parseStabiliseRequest
|
Stabilise -> parseStabiliseRequest
|
||||||
Ping -> parsePingRequest
|
Ping -> parsePingRequest
|
||||||
|
|
||||||
pure $ Request requestID sender parts part action payload
|
pure $ Request requestID sender part isFinalPart action payload
|
||||||
|
|
||||||
parseResponse :: Integer -> ParseASN1 FediChordMessage
|
parseResponse :: Integer -> ParseASN1 FediChordMessage
|
||||||
parseResponse responseTo = do
|
parseResponse responseTo = do
|
||||||
senderID <- fromInteger <$> parseInteger :: ParseASN1 NodeID
|
senderID <- fromInteger <$> parseInteger :: ParseASN1 NodeID
|
||||||
parts <- parseInteger
|
|
||||||
part <- parseInteger
|
part <- parseInteger
|
||||||
|
isFinalPart <- parseBool
|
||||||
action <- parseEnum :: ParseASN1 Action
|
action <- parseEnum :: ParseASN1 Action
|
||||||
hasPayload <- hasNext
|
hasPayload <- hasNext
|
||||||
payload <- if not hasPayload then pure Nothing else Just <$> case action of
|
payload <- if not hasPayload then pure Nothing else Just <$> case action of
|
||||||
|
@ -291,7 +290,14 @@ parseResponse responseTo = do
|
||||||
Stabilise -> parseStabiliseResponse
|
Stabilise -> parseStabiliseResponse
|
||||||
Ping -> parsePingResponse
|
Ping -> parsePingResponse
|
||||||
|
|
||||||
pure $ Response responseTo senderID parts part action payload
|
pure $ Response responseTo senderID part isFinalPart action payload
|
||||||
|
|
||||||
|
parseBool :: ParseASN1 Bool
|
||||||
|
parseBool = do
|
||||||
|
i <- getNext
|
||||||
|
case i of
|
||||||
|
Boolean parsed -> pure parsed
|
||||||
|
x -> throwParseError $ "Expected Boolean but got " <> show x
|
||||||
|
|
||||||
parseInteger :: ParseASN1 Integer
|
parseInteger :: ParseASN1 Integer
|
||||||
parseInteger = do
|
parseInteger = do
|
||||||
|
|
|
@ -21,8 +21,8 @@ data Action = QueryID
|
||||||
data FediChordMessage = Request
|
data FediChordMessage = Request
|
||||||
{ requestID :: Integer
|
{ requestID :: Integer
|
||||||
, sender :: RemoteNodeState
|
, sender :: RemoteNodeState
|
||||||
, parts :: Integer
|
|
||||||
, part :: Integer
|
, part :: Integer
|
||||||
|
, isFinalPart :: Bool
|
||||||
-- ^ part starts at 1
|
-- ^ part starts at 1
|
||||||
, action :: Action
|
, action :: Action
|
||||||
, payload :: Maybe ActionPayload
|
, payload :: Maybe ActionPayload
|
||||||
|
@ -30,8 +30,8 @@ data FediChordMessage = Request
|
||||||
| Response
|
| Response
|
||||||
{ responseTo :: Integer
|
{ responseTo :: Integer
|
||||||
, senderID :: NodeID
|
, senderID :: NodeID
|
||||||
, parts :: Integer
|
|
||||||
, part :: Integer
|
, part :: Integer
|
||||||
|
, isFinalPart :: Bool
|
||||||
, action :: Action
|
, action :: Action
|
||||||
, payload :: Maybe ActionPayload
|
, payload :: Maybe ActionPayload
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue