diff --git a/package.json b/package.json index 595cd7b..3ad5b9c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/", "docs": "./node_modules/.bin/apidoc -i src/routes/v4 -o docs", "test:temp1": "export NETWORK=mainnet && export TEST=integration && mocha --exit --timeout 25000 -g '#hydrateUtxos-' test/v4/integration/", - "test:temp2": "mocha test/v4/rate-limit2-unit.js" + "test:temp2": "mocha -g '#rate-routelimit' --timeout 30000 test/v4/" }, "engines": { "node": ">=10.15.1" diff --git a/src/middleware/route-ratelimit.js b/src/middleware/route-ratelimit.js index a6f1f38..10f0587 100644 --- a/src/middleware/route-ratelimit.js +++ b/src/middleware/route-ratelimit.js @@ -154,6 +154,7 @@ class RateLimits { res, defaultJwt ) + // console.log(`hasExceededRateLimit: `, hasExceededRateLimit) if (!hasExceededRateLimit) { // Rate limits have not been exceeded. Processing can continue. @@ -195,6 +196,7 @@ class RateLimits { res, req.locals.jwtToken ) + // console.log('hasExceededRateLimit: ', hasExceededRateLimit) if (!hasExceededRateLimit) { // Rate limits have not been exceeded. Processing can continue. @@ -220,8 +222,12 @@ class RateLimits { async trackRateLimits (req, res, jwtToken) { // Anonymous rate limits are used by default. let pointsToConsume = ANON_LIMITS + // console.log('pointsToConsume: ', pointsToConsume) + let key = req.ip // Use the IP address as the key, by default. + // console.log('jwtToken: ', jwtToken) + try { // Decode the JWT token if it exists if (jwtToken) { @@ -239,6 +245,10 @@ class RateLimits { // The 429 error response is handled by the catch(). await _this.rateLimiter.consume(key, pointsToConsume) + // Debugging + // const rateLimitData = await _this.rateLimiter.consume(key, pointsToConsume) + // console.log(`rateLimitData: `, rateLimitData) + res.locals.pointsToConsume = pointsToConsume // Feedback for tests. // Signal that the user has not exceeded their rate limits. diff --git a/start-dev-example.sh b/start-dev-example.sh index 803aa75..d4a2adb 100755 --- a/start-dev-example.sh +++ b/start-dev-example.sh @@ -48,12 +48,12 @@ export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword # that originate froma domain on the whitelist. export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash -# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON. +# Rate Limits. Numbers are divided into 1000. e.g. 10000 / 500 = 20 RPM for ANON. # Requests use the ANON rate limit if they fail to pass in a JWT token. # ANON = 20 requests per minute (RPM) -export ANON_RATE_LIMIT=50 -# 10 = 100 RPM -export WHITELIST_RATE_LIMIT=10 +export ANON_RATE_LIMIT=500 +# 10 = 1000 RPM +export WHITELIST_RATE_LIMIT=100 # Set logging parameters #1m means no more than 1 megabyte