summaryrefslogtreecommitdiffhomepage
path: root/HTTP/RateLimit.hs
diff options
context:
space:
mode:
Diffstat (limited to 'HTTP/RateLimit.hs')
-rw-r--r--HTTP/RateLimit.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/HTTP/RateLimit.hs b/HTTP/RateLimit.hs
index 81e3ed2..54eb8d2 100644
--- a/HTTP/RateLimit.hs
+++ b/HTTP/RateLimit.hs
@@ -8,6 +8,7 @@ module HTTP.RateLimit where
import Types.Cost
import HTTP
import HTTP.ProofOfWork
+import Tunables
import Servant
import Control.Concurrent.STM
import Control.Concurrent.TokenBucket
@@ -92,12 +93,21 @@ bloomMaxSize = 1000000
-- split into multiple chunks. However, setting this too high lets clients
-- cheaply store lots of data, so keep the objectSize in mind.
burstSize :: Word64
-burstSize = 4 -- allow 128 kb of data to be stored/retrieved w/o proof of work
+burstSize = 4 -- allow 4 objects to be stored/retrieved w/o proof of work
-- | Rate that the bucket is filled.
fillRate :: Word64
fillRate = 60000000 -- 1 token per minute
+-- | How much data could be stored, in bytes per second, assuming all
+-- buckets in the rate limiter are kept drained, and all requests are
+-- stores.
+maximumStorageRate :: RateLimiter -> IO Int
+maximumStorageRate ratelimiter = do
+ let storesize = maximum knownObjectSizes
+ bs <- liftIO $ atomically $ readTMVar (buckets ratelimiter)
+ return $ (length bs * storesize * 1000000) `div` fromIntegral fillRate
+
-- A request is tried in each bucket in turn which its proof of work allows
-- access to. If all accessible token buckets are empty, generate a
-- new ProofOfWorkRequirement for the client.