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,
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,

View file

@ -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

View file

@ -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