encode Ping as ASN.1

This commit is contained in:
Trolli Schmittlauch 2020-04-30 13:37:46 +02:00
parent 1968b5f883
commit 187d164200
2 changed files with 23 additions and 4 deletions

View file

@ -16,7 +16,8 @@ Request ::= SEQUENCE {
queryIDSendPayload QueryIDSendPayload,
joinSendPayload JoinSendPayload,
leaveSendPayload LeaveSendPayload,
stabiliseSendPayload StabiliseSendPayload
stabiliseSendPayload StabiliseSendPayload,
pingSendPayload PingSendPayload
}
}
@ -30,7 +31,8 @@ Response ::= SEQUENCE {
queryIDReceivePayload QueryIDReceivePayload,
joinReceivePayload JoinReceivePayload,
leaveReceivePayload LeaveReceivePayload,
stabiliseReceivePayload StabiliseReceivePayload
stabiliseReceivePayload StabiliseReceivePayload,
pingReceivePayload PingReceivePayload
}
}
@ -87,5 +89,11 @@ LeaveSendPayload ::= SEQUENCE {
LeaveReceivePayload ::= NULL -- just a confirmation
PingSendPayload ::= NULL -- do not include a node/ vserver ID, so that
-- the node has to respond with all active ones
-- learning all active vserver IDs handled by the server at once
PingReceivePayload ::= SEQUENCE OF NodeState
END

View file

@ -28,6 +28,8 @@ data Action =
-- probably should be taken care of by the callers of this, as the ASN.1
-- encoding functions are layer-4 agnostic
-- ===== encoding functions =====
encodeNodeState :: NodeState -> [ASN1]
encodeNodeState ns = [
Start Sequence
@ -82,7 +84,7 @@ encodeQueryIDReceivePayload resp =
FOUND _ -> []
FORWARD entrySet ->
Start Sequence
: mconcat (map encodeCacheEntry . Set.elems $ entrySet)
: concatMap encodeCacheEntry . Set.elems $ entrySet
++ [End Sequence]
++ [End Sequence]
@ -105,7 +107,7 @@ encodeJoinReceivePayload succ' pred' ncache =
++ map (IntVal . getNodeID) pred'
++ [End Sequence
, Start Sequence]
++ mconcat (map encodeCacheEntry ncache)
++ concatMap encodeCacheEntry ncache
++ [End Sequence
, End Sequence]
@ -131,3 +133,12 @@ encodeResponse responseTo senderID parts part action payload = [
, IntVal part
, Enumerated . fromIntegral . fromEnum $ action]
++ payload
encodePingSendPayload :: [ASN1]
encodePingSendPayload = Null
encodePingReceivePayload :: [NodeState] -> [ASN1]
encodePingReceivePayload nss =
Start Sequence
: concatMap encodeNodeState nss
++ [End Sequence]