summaryrefslogtreecommitdiffhomepage
path: root/Log.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-18 14:43:16 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-18 14:43:16 -0400
commit713521318289919cc481bf15f28a4a06554485dc (patch)
tree8f4359a808165487ebf92b8e53080c406bced93a /Log.hs
parent9102a47c6c68039a288a6ee8f43fe14b034ce356 (diff)
downloaddebug-me-713521318289919cc481bf15f28a4a06554485dc.tar.gz
memory DOS prevention
Prevent DOS of user side by limiting the size of the BackLog that is maintained. This should not cause problems in even high latency environments, and should prevent memory use > 16 mb. The developer side does not keep much data, other than a list of the Hashes of things it has recently sent, so is not susceptable to memory DOS. This commit was sponsored by Brock Spratlen on Patreon.
Diffstat (limited to 'Log.hs')
-rw-r--r--Log.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/Log.hs b/Log.hs
index 90f1b53..8690f27 100644
--- a/Log.hs
+++ b/Log.hs
@@ -4,6 +4,7 @@ module Log where
import Types
import Hash
+import Memory
import GHC.Generics (Generic)
import Data.Aeson
@@ -28,6 +29,9 @@ data ActivityLog = ActivityLog
}
deriving (Show, Generic)
+instance DataSize ActivityLog where
+ dataSize l = dataSize (loggedActivity l) + dataSize (loggedHash l) + 2
+
instance ToJSON (ActivityLog)
instance FromJSON (ActivityLog)
@@ -36,6 +40,10 @@ data SomeActivity
| ActivityEntered (Activity Entered)
deriving (Show, Generic)
+instance DataSize SomeActivity where
+ dataSize (ActivitySeen a) = dataSize a
+ dataSize (ActivityEntered a) = dataSize a
+
instance ToJSON SomeActivity where
toJSON = genericToJSON sumOptions
toEncoding = genericToEncoding sumOptions