From 757daaf669c3b45fe952f922af502ee7197e3d30 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 13 Sep 2016 11:42:55 -0400 Subject: 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. --- HTTP/RateLimit.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'HTTP') 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 -- cgit v1.2.3