summaryrefslogtreecommitdiffhomepage
path: root/HTTP
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-13 11:42:55 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-13 11:42:55 -0400
commit757daaf669c3b45fe952f922af502ee7197e3d30 (patch)
tree0db0845a13522661afc8d0bb8dc46732043a57ce /HTTP
parent0a9ad7c1a65184725885fea3d6a09929dc9307de (diff)
downloadkeysafe-757daaf669c3b45fe952f922af502ee7197e3d30.tar.gz
use half as many token buckets
(down from 7 to 4) This decreases the possible maximumStorageRate by half, down from 18 gb/month to 10 gb/month.
Diffstat (limited to 'HTTP')
-rw-r--r--HTTP/RateLimit.hs10
1 files changed, 5 insertions, 5 deletions
diff --git a/HTTP/RateLimit.hs b/HTTP/RateLimit.hs
index 54eb8d2..e88d617 100644
--- a/HTTP/RateLimit.hs
+++ b/HTTP/RateLimit.hs
@@ -48,7 +48,7 @@ data Bucket = Bucket
newRateLimiter :: IO RateLimiter
newRateLimiter = RateLimiter
- <$> (newTMVarIO =<< mkbuckets maxProofOfWork [])
+ <$> (newTMVarIO =<< mkbuckets (sdiv maxProofOfWork 2) [])
<*> mkBloomFilter
<*> mkBloomFilter
<*> mkBloomFilter
@@ -57,21 +57,21 @@ newRateLimiter = RateLimiter
<*> newTokenBucket
where
-- The last bucket takes half of maxProofOfWork to access, and
- -- each earlier bucket halves that time, down to the first bucket,
+ -- each earlier bucket quarters that time, down to the first bucket,
-- which needs no proof of work. This ensures that in the edge case
-- where a client keeps getting bumped up to more and more expensive
-- buckets, it doesn't need to do more than maxProofOfWork total work.
- mkbuckets (Seconds n) bs
+ mkbuckets s@(Seconds n) bs
| n <= 0 = return bs
| otherwise = do
- let s = Seconds (n `div` 2)
let mkreq = mkProofOfWorkRequirement s
b <- Bucket
<$> newTokenBucket
<*> pure mkreq
case mkreq of
Nothing -> return (b:bs)
- Just _ -> mkbuckets s (b:bs)
+ Just _ -> mkbuckets (sdiv s 4) (b:bs)
+ sdiv (Seconds n) d = Seconds (n `div` d)
mkBloomFilter :: IO BloomFilter
mkBloomFilter = do