diff --git a/Hash2Pub/FediChord.asn1 b/Hash2Pub/FediChord.asn1 index 97b6242..315013f 100644 --- a/Hash2Pub/FediChord.asn1 +++ b/Hash2Pub/FediChord.asn1 @@ -10,8 +10,8 @@ Request ::= SEQUENCE { action Action, requestID INTEGER, sender NodeState, - parts INTEGER, -- number of message parts - part INTEGER, -- part number of this message, starts at 1 + parts INTEGER (0..150), -- number of message parts + part INTEGER (0..150), -- part number of this message, starts at 1 actionPayload CHOICE { queryIDRequestPayload QueryIDRequestPayload, joinRequestPayload JoinRequestPayload, @@ -27,8 +27,8 @@ Request ::= SEQUENCE { Response ::= SEQUENCE { responseTo INTEGER, senderID NodeID, - parts INTEGER, - part INTEGER, + parts INTEGER (0..150), + part INTEGER (0..150), action Action, actionPayload CHOICE { queryIDResponsePayload QueryIDResponsePayload, diff --git a/Hash2Pub/src/Hash2Pub/ASN1Coding.hs b/Hash2Pub/src/Hash2Pub/ASN1Coding.hs index 2c463b9..7bafda5 100644 --- a/Hash2Pub/src/Hash2Pub/ASN1Coding.hs +++ b/Hash2Pub/src/Hash2Pub/ASN1Coding.hs @@ -103,7 +103,6 @@ serialiseMessage maxBytesLength msg = actionPayload = payload msg encodedMsgs i = map (encodeASN1' DER . encodeMessage) $ messageParts i maxMsgLength msgs = maximum $ map BS.length msgs - maximumParts = 150 -- | Deserialise a ASN.1 DER encoded bytesstring of a single 'FediChordMessage'. deserialiseMessage :: BS.ByteString diff --git a/Hash2Pub/src/Hash2Pub/DHTProtocol.hs b/Hash2Pub/src/Hash2Pub/DHTProtocol.hs index e3ba67d..5953dab 100644 --- a/Hash2Pub/src/Hash2Pub/DHTProtocol.hs +++ b/Hash2Pub/src/Hash2Pub/DHTProtocol.hs @@ -11,6 +11,7 @@ module Hash2Pub.DHTProtocol , Action(..) , ActionPayload(..) , FediChordMessage(..) + , maximumParts ) where @@ -136,6 +137,11 @@ data ActionPayload = } deriving (Show, Eq) +-- | global limit of parts per message used when (de)serialising messages. +-- Used to limit the impact of DOS attempts with partial messages. +maximumParts :: Num a => a +maximumParts = 150 + -- | dedicated data type for cache entries sent to or received from the network, -- as these have to be considered as unvalidated. Also helps with separation of trust. data RemoteCacheEntry = RemoteCacheEntry NodeState POSIXTime