summaryrefslogtreecommitdiffhomepage
path: root/HTTP
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-13 11:37:23 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-13 11:37:23 -0400
commit0a9ad7c1a65184725885fea3d6a09929dc9307de (patch)
treed45c240f0ab735c4069975147a1a9a9ce00b054f /HTTP
parent42c00f3f1839e315ce70065723d8569321d7299e (diff)
downloadkeysafe-0a9ad7c1a65184725885fea3d6a09929dc9307de.tar.gz
maximumStorageRate calculation
Diffstat (limited to 'HTTP')
-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.