diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-09-12 22:59:03 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-09-12 22:59:03 -0400 |
commit | e333a779338ff8bccdc4225fc953d6f4f0226db0 (patch) | |
tree | c07f1165ba101c2b10e914170fb07628e1d08d3a /HTTP/RateLimit.hs | |
parent | 13c408d2295597540f0b2dfb6f7b86e739876c90 (diff) | |
download | keysafe-e333a779338ff8bccdc4225fc953d6f4f0226db0.tar.gz |
add proof of work to countobjects
In this case, an empty string is hashed to generate the PoW.
Diffstat (limited to 'HTTP/RateLimit.hs')
-rw-r--r-- | HTTP/RateLimit.hs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/HTTP/RateLimit.hs b/HTTP/RateLimit.hs index 9153664..737f7dc 100644 --- a/HTTP/RateLimit.hs +++ b/HTTP/RateLimit.hs @@ -5,7 +5,6 @@ module HTTP.RateLimit where -import Types import Types.Cost import HTTP import HTTP.ProofOfWork @@ -107,8 +106,8 @@ fillRate = 60000000 -- 1 token per minute -- If all buckets are tried and are empty, we must be very overloaded. -- In this case, the request is still processed, since the client has done -- quite a lot of work. -rateLimit :: RateLimiter -> Maybe ProofOfWork -> StorableObjectIdent -> Handler a -> Handler (POWGuarded a) -rateLimit ratelimiter mpow i a = do +rateLimit :: POWIdent p => RateLimiter -> Maybe ProofOfWork -> p -> Handler a -> Handler (POWGuarded a) +rateLimit ratelimiter mpow p a = do validsalt <- liftIO $ checkValidSalt ratelimiter mpow bs <- liftIO $ atomically $ readTMVar (buckets ratelimiter) if validsalt @@ -123,7 +122,7 @@ rateLimit ratelimiter mpow i a = do Just mkreq -> case mpow of Nothing -> assignWork ratelimiter (b:bs) Just pow@(ProofOfWork _ salt) -> - if isValidProofOfWork pow (mkreq salt) i + if isValidProofOfWork pow (mkreq salt) p then checkbucket b bs else assignWork ratelimiter (b:bs) checkbucket b bs = do |