move limit of message parts to a global constant

This commit is contained in:
Trolli Schmittlauch 2020-05-11 12:43:02 +02:00
parent 6ed441403d
commit e5db06a680
3 changed files with 10 additions and 5 deletions

View file

@ -10,8 +10,8 @@ Request ::= SEQUENCE {
action Action, action Action,
requestID INTEGER, requestID INTEGER,
sender NodeState, sender NodeState,
parts INTEGER, -- number of message parts parts INTEGER (0..150), -- number of message parts
part INTEGER, -- part number of this message, starts at 1 part INTEGER (0..150), -- part number of this message, starts at 1
actionPayload CHOICE { actionPayload CHOICE {
queryIDRequestPayload QueryIDRequestPayload, queryIDRequestPayload QueryIDRequestPayload,
joinRequestPayload JoinRequestPayload, joinRequestPayload JoinRequestPayload,
@ -27,8 +27,8 @@ Request ::= SEQUENCE {
Response ::= SEQUENCE { Response ::= SEQUENCE {
responseTo INTEGER, responseTo INTEGER,
senderID NodeID, senderID NodeID,
parts INTEGER, parts INTEGER (0..150),
part INTEGER, part INTEGER (0..150),
action Action, action Action,
actionPayload CHOICE { actionPayload CHOICE {
queryIDResponsePayload QueryIDResponsePayload, queryIDResponsePayload QueryIDResponsePayload,

View file

@ -103,7 +103,6 @@ serialiseMessage maxBytesLength msg =
actionPayload = payload msg actionPayload = payload msg
encodedMsgs i = map (encodeASN1' DER . encodeMessage) $ messageParts i encodedMsgs i = map (encodeASN1' DER . encodeMessage) $ messageParts i
maxMsgLength msgs = maximum $ map BS.length msgs maxMsgLength msgs = maximum $ map BS.length msgs
maximumParts = 150
-- | Deserialise a ASN.1 DER encoded bytesstring of a single 'FediChordMessage'. -- | Deserialise a ASN.1 DER encoded bytesstring of a single 'FediChordMessage'.
deserialiseMessage :: BS.ByteString deserialiseMessage :: BS.ByteString

View file

@ -11,6 +11,7 @@ module Hash2Pub.DHTProtocol
, Action(..) , Action(..)
, ActionPayload(..) , ActionPayload(..)
, FediChordMessage(..) , FediChordMessage(..)
, maximumParts
) )
where where
@ -136,6 +137,11 @@ data ActionPayload =
} }
deriving (Show, Eq) 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, -- | 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. -- as these have to be considered as unvalidated. Also helps with separation of trust.
data RemoteCacheEntry = RemoteCacheEntry NodeState POSIXTime data RemoteCacheEntry = RemoteCacheEntry NodeState POSIXTime