A Leveldb-backed tokenthrottle implementation. See http://npm.im/tokenthrottle
A LevelDb-backed implementation of tokenthrottle
Simply wraps tokenthrottle with a Level back-end.
If you want to use it with multiple processes/servers, provide it a multilevel connection.
// Create a level clientvar db = require"level"/throttle// Create a throttle with 100 access limit per second.var throttle = require"tokenthrottle-level"rate: 100 db// in some_function that you want to rate limitthrottlerateLimitid/* ... handle err ... */if limitedreturn resnext"Rate limit exceeded, please slow down.";else/* ... do work ... */
// multilevel server code...// In your multilevel server, make sure you have the same sublevel that will be used// either the default "levelThrottle" or the `prefix` you specify.// Then you must create a manifest for the clients so they know they may use it.var sub = subleveldbsublevel"levelThrottle"var settings = require"level-manifest"db// save your settings somewhere// client code...// Create a multilevel clientvar multilevel = require"multilevel"var net = require"net"var db = multilevelclientsettingsvar con = netconnect3000conpipedbcreateRpcStreampipecon// Create a throttle with 100 access limit per second.var throttle = require"tokenthrottle-level"rate: 100 db// in some_function that you want to rate limitthrottlerateLimitid/* ... handle err ... */if limitedreturn resnext"Rate limit exceeded, please slow down.";else/* ... do work ... */
Accepts all of the same options as tokenthrottle, with one extra:
(The MIT License)
Copyright (c) Bryce B. Baril firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.