create ratelimiter plugin
This commit is contained in:
parent
0ff490dbf3
commit
461fda09be
@ -89,6 +89,7 @@ INSIGHT_DB # Path where to store insight's internal DB. (defaults to
|
|||||||
INSIGHT_SAFE_CONFIRMATIONS=6 # Nr. of confirmation needed to start caching transaction information
|
INSIGHT_SAFE_CONFIRMATIONS=6 # Nr. of confirmation needed to start caching transaction information
|
||||||
INSIGHT_IGNORE_CACHE # True to ignore cache of spents in transaction, with more than INSIGHT_SAFE_CONFIRMATIONS confirmations. This is useful for tracking double spents for old transactions.
|
INSIGHT_IGNORE_CACHE # True to ignore cache of spents in transaction, with more than INSIGHT_SAFE_CONFIRMATIONS confirmations. This is useful for tracking double spents for old transactions.
|
||||||
ENABLE_MAILBOX # if "true" will enable mailbox plugin
|
ENABLE_MAILBOX # if "true" will enable mailbox plugin
|
||||||
|
ENABLE_RATELIMITER # if "true" will enable the ratelimiter plugin
|
||||||
LOGGER_LEVEL # defaults to 'info', can be 'debug','verbose','error', etc.
|
LOGGER_LEVEL # defaults to 'info', can be 'debug','verbose','error', etc.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@ -77,6 +77,7 @@ var bitcoindConf = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var enableMailbox = process.env.ENABLE_MAILBOX === 'true';
|
var enableMailbox = process.env.ENABLE_MAILBOX === 'true';
|
||||||
|
var enableRatelimiter = process.env.ENABLE_RATELIMITER === 'true';
|
||||||
var loggerLevel = process.env.LOGGER_LEVEL || 'info';
|
var loggerLevel = process.env.LOGGER_LEVEL || 'info';
|
||||||
|
|
||||||
if (!fs.existsSync(db)) {
|
if (!fs.existsSync(db)) {
|
||||||
@ -91,6 +92,7 @@ if (!fs.existsSync(db)) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
enableMailbox: enableMailbox,
|
enableMailbox: enableMailbox,
|
||||||
|
enableRatelimiter: enableRatelimiter,
|
||||||
loggerLevel: loggerLevel,
|
loggerLevel: loggerLevel,
|
||||||
version: version,
|
version: version,
|
||||||
root: rootPath,
|
root: rootPath,
|
||||||
|
|||||||
28
insight.js
28
insight.js
@ -4,15 +4,13 @@
|
|||||||
//Set the node enviornment variable if not set before
|
//Set the node enviornment variable if not set before
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
/**
|
var fs = require('fs');
|
||||||
* Module dependencies.
|
var PeerSync = require('./lib/PeerSync');
|
||||||
*/
|
var HistoricSync = require('./lib/HistoricSync');
|
||||||
var express = require('express'),
|
|
||||||
fs = require('fs'),
|
var express = require('express');
|
||||||
PeerSync = require('./lib/PeerSync'),
|
var connect = require('connect');
|
||||||
HistoricSync = require('./lib/HistoricSync');
|
|
||||||
|
|
||||||
//Initializing system variables
|
|
||||||
var config = require('./config/config');
|
var config = require('./config/config');
|
||||||
|
|
||||||
// text title
|
// text title
|
||||||
@ -54,14 +52,12 @@ console.log(
|
|||||||
config.bitcoind.dataDir + (config.network === 'testnet' ? '*' : ''), (config.network === 'testnet' ? '* (/testnet3 is added automatically)' : '')
|
config.bitcoind.dataDir + (config.network === 'testnet' ? '*' : ''), (config.network === 'testnet' ? '* (/testnet3 is added automatically)' : '')
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* express app
|
|
||||||
*/
|
// create express app
|
||||||
var expressApp = express();
|
var expressApp = express();
|
||||||
|
|
||||||
/**
|
// Bootstrap models
|
||||||
* Bootstrap models
|
|
||||||
*/
|
|
||||||
var models_path = __dirname + '/app/models';
|
var models_path = __dirname + '/app/models';
|
||||||
var walk = function(path) {
|
var walk = function(path) {
|
||||||
fs.readdirSync(path).forEach(function(file) {
|
fs.readdirSync(path).forEach(function(file) {
|
||||||
@ -127,6 +123,10 @@ if (config.enableMailbox) {
|
|||||||
require('./plugins/mailbox').init(ios, config.mailbox);
|
require('./plugins/mailbox').init(ios, config.mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.enableRatelimiter) {
|
||||||
|
require('./plugins/ratelimiter').init(expressApp, config.ratelimiter);
|
||||||
|
}
|
||||||
|
|
||||||
//Start the app by listening on <port>
|
//Start the app by listening on <port>
|
||||||
server.listen(config.port, function() {
|
server.listen(config.port, function() {
|
||||||
console.log('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
console.log('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
||||||
|
|||||||
@ -58,6 +58,8 @@
|
|||||||
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
||||||
"buffertools": "*",
|
"buffertools": "*",
|
||||||
"commander": "*",
|
"commander": "*",
|
||||||
|
"connect": "^2.25.7",
|
||||||
|
"connect-ratelimit": "0.0.6",
|
||||||
"express": "~3.4.7",
|
"express": "~3.4.7",
|
||||||
"glob": "*",
|
"glob": "*",
|
||||||
"leveldown": "*",
|
"leveldown": "*",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ var preconditions = require('preconditions').singleton();
|
|||||||
|
|
||||||
var io;
|
var io;
|
||||||
module.exports.init = function(ext_io, config) {
|
module.exports.init = function(ext_io, config) {
|
||||||
|
logger.info('Using mailbox plugin');
|
||||||
preconditions.checkArgument(ext_io);
|
preconditions.checkArgument(ext_io);
|
||||||
io = ext_io;
|
io = ext_io;
|
||||||
io.sockets.on('connection', function(socket) {
|
io.sockets.on('connection', function(socket) {
|
||||||
|
|||||||
10
plugins/ratelimiter.js
Normal file
10
plugins/ratelimiter.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
var logger = require('../lib/logger').logger;
|
||||||
|
var preconditions = require('preconditions').singleton();
|
||||||
|
|
||||||
|
var limiter = require('connect-ratelimit');
|
||||||
|
|
||||||
|
module.exports.init = function(app, config) {
|
||||||
|
preconditions.checkArgument(app);
|
||||||
|
logger.info('Using ratelimiter plugin');
|
||||||
|
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user