<commit_before>debug = require('debug')('meshblu:getThrottles')
Limitus = require 'limitus'
limiter = new Limitus()

config = require '../config'

config.rateLimits ?= {};
windowRate = 1000

createThrottle = (name, rate) ->
  debug 'createThrottle', name, rate
  limiter.rule name, max: rate, interval: windowRate
  rateLimit: (id="", callback=->) =>
    debug 'rateLimit', name, id
    limiter.drop(name, id, callback)

module.exports =
  connection: createThrottle 'connection', config.rateLimits.connection
  query:      createThrottle 'query', config.rateLimits.query
  message:    createThrottle 'message', config.rateLimits.message
  data:       createThrottle 'data', config.rateLimits.data
  whoami:     createThrottle 'whoami', config.rateLimits.whoami
  unthrottledIps : config.rateLimits.unthrottledIps<commit_msg>Switch to interval rate limiting<commit_after>debug = require('debug')('meshblu:getThrottles')
Limitus = require 'limitus'
limiter = new Limitus()

config = require '../config'

config.rateLimits ?= {};
windowRate = 1000

createThrottle = (name, rate) ->
  debug 'createThrottle', name, rate
  limiter.rule name, max: rate, interval: windowRate, mode: 'interval'
  rateLimit: (id="", callback=->) =>
    debug 'rateLimit', name, id
    limiter.drop(name, id, callback)

module.exports =
  connection: createThrottle 'connection', config.rateLimits.connection
  query:      createThrottle 'query', config.rateLimits.query
  message:    createThrottle 'message', config.rateLimits.message
  data:       createThrottle 'data', config.rateLimits.data
  whoami:     createThrottle 'whoami', config.rateLimits.whoami
  unthrottledIps : config.rateLimits.unthrottledIps
{'fraction_non_alphanumeric': 0.12448132780082988, 'fraction_numerical': 0.004742145820983995, 'mean_word_length': 4.881533101045296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6114615', 'n_tokens_mistral': 553, 'n_tokens_neox': 558, 'n_words': 125}