mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
fix(rate-limits): Adding artifical delay to anon requests
This commit is contained in:
+3
-3
@@ -18,9 +18,9 @@
|
|||||||
"lint": "standard --env mocha --fix",
|
"lint": "standard --env mocha --fix",
|
||||||
"test-v4": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v4/",
|
"test-v4": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v4/",
|
||||||
"test-v5": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v5/",
|
"test-v5": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v5/",
|
||||||
"test:integration": "mocha test/v4/integration",
|
"test:integration": "mocha test/v5/integration",
|
||||||
"test:integration:slpdb": "mocha --timeout 25000 -g '#validate2Single' test/v4/integration/slp*.js",
|
"test:integration:slpdb": "mocha --timeout 25000 -g '#validate2Single' test/v5/integration/slp*.js",
|
||||||
"test:integration:nft": "mocha --timeout 25000 -g '#nft' test/v4/integration/nft.js",
|
"test:integration:nft": "mocha --timeout 25000 -g '#nft' test/v5/integration/nft.js",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/",
|
"coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/",
|
||||||
"docs": "./node_modules/.bin/apidoc -i src/routes/v5 -o docs",
|
"docs": "./node_modules/.bin/apidoc -i src/routes/v5 -o docs",
|
||||||
|
|||||||
@@ -213,6 +213,10 @@ class RateLimits {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sleep (ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms))
|
||||||
|
}
|
||||||
|
|
||||||
// A wrapper for Redis-based rate limiter.
|
// A wrapper for Redis-based rate limiter.
|
||||||
// Will return false if the user has not exceeded the rate limit. Otherwise
|
// Will return false if the user has not exceeded the rate limit. Otherwise
|
||||||
// it will return the 'res' object with an error status and message, which
|
// it will return the 'res' object with an error status and message, which
|
||||||
@@ -267,6 +271,11 @@ class RateLimits {
|
|||||||
|
|
||||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||||
|
|
||||||
|
// Add artificial delay to slow down freeloaders.
|
||||||
|
if (pointsToConsume === ANON_LIMITS) {
|
||||||
|
await this.sleep(500)
|
||||||
|
}
|
||||||
|
|
||||||
// Signal that the user has not exceeded their rate limits.
|
// Signal that the user has not exceeded their rate limits.
|
||||||
return false
|
return false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user