Skip to content

Commit

Permalink
3.3.4-rc7
Browse files Browse the repository at this point in the history
- include config disable_rate_limit
- minor package upgrades
- date parser fix
  • Loading branch information
igorls committed Sep 6, 2021
1 parent 81ae93b commit 80bd4ad
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 223 deletions.
24 changes: 17 additions & 7 deletions api/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ import fastifyRateLimit from 'fastify-rate-limit';
import fastify_eosjs from "./plugins/fastify-eosjs";

export function registerPlugins(server: Fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>, params: any) {
server.register(fastifyElasticsearch, params.fastify_elasticsearch);
server.register(fastifySwagger, params.fastify_swagger);
server.register(fastifyCors);
server.register(fastifyFormbody);
server.register(fastifyRedis, params.fastify_redis);
server.register(fastifyRateLimit, params.fastify_rate_limit);
server.register(fastify_eosjs, params.fastify_eosjs);
server.register(fastifyElasticsearch, params.fastify_elasticsearch);

if (params.fastify_swagger) {
server.register(fastifySwagger, params.fastify_swagger);
}

server.register(fastifyCors);

server.register(fastifyFormbody);

server.register(fastifyRedis, params.fastify_redis);

if (params.fastify_rate_limit) {
server.register(fastifyRateLimit, params.fastify_rate_limit);
}

server.register(fastify_eosjs, params.fastify_eosjs);
}
52 changes: 28 additions & 24 deletions api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {createWriteStream, existsSync, mkdirSync} from "fs";
import {SocketManager} from "./socketManager";
import {HyperionModuleLoader} from "../modules/loader";
import {extendedActions} from "./routes/v2-history/get_actions/definitions";
import {Socket, io} from "socket.io-client";
import {io, Socket} from "socket.io-client";

class HyperionApiServer {

Expand Down Expand Up @@ -93,38 +93,42 @@ class HyperionApiServer {

const ioRedisClient = new IORedis(this.manager.conn.redis);

let rateLimiterWhitelist = ['127.0.0.1'];

if (this.conf.api.rate_limit_allow && this.conf.api.rate_limit_allow.length > 0) {
const tempSet = new Set<string>(['127.0.0.1', ...this.conf.api.rate_limit_allow]);
rateLimiterWhitelist = [...tempSet];
}
const pluginParams = {
fastify_elasticsearch: {
client: this.manager.elasticsearchClient
},
fastify_redis: this.manager.conn.redis,
fastify_eosjs: this.manager,
} as any;

let rateLimiterRPM = 1000;
if (this.conf.api.rate_limit_rpm) {
rateLimiterRPM = this.conf.api.rate_limit_rpm;
if(!this.conf.api.disable_rate_limit) {
let rateLimiterWhitelist = ['127.0.0.1'];
if (this.conf.api.rate_limit_allow && this.conf.api.rate_limit_allow.length > 0) {
const tempSet = new Set<string>(['127.0.0.1', ...this.conf.api.rate_limit_allow]);
rateLimiterWhitelist = [...tempSet];
}
let rateLimiterRPM = 1000;
if (this.conf.api.rate_limit_rpm) {
rateLimiterRPM = this.conf.api.rate_limit_rpm;
}
pluginParams.fastify_rate_limit = {
max: rateLimiterRPM,
allowList: rateLimiterWhitelist,
timeWindow: '1 minute',
redis: ioRedisClient
}
}

const api_rate_limit = {
max: rateLimiterRPM,
allowList: rateLimiterWhitelist,
timeWindow: '1 minute',
redis: ioRedisClient
};

if (this.conf.features.streaming.enable) {
this.activateStreaming();
}

const docsConfig = generateOpenApiConfig(this.manager.config);
if(docsConfig) {
pluginParams.fastify_swagger = docsConfig;
}

registerPlugins(this.fastify, {
fastify_elasticsearch: {client: this.manager.elasticsearchClient},
fastify_swagger: docsConfig,
fastify_rate_limit: api_rate_limit,
fastify_redis: this.manager.conn.redis,
fastify_eosjs: this.manager,
});
registerPlugins(this.fastify, pluginParams);

this.addGenericTypeParsing();
}
Expand Down
1 change: 1 addition & 0 deletions chains/example.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"chain_api_error_log": false,
"custom_core_token": "",
"enable_export_action": false,
"disable_rate_limit": false,
"rate_limit_rpm": 1000,
"rate_limit_allow": [],
"disable_tx_cache": false,
Expand Down
1 change: 1 addition & 0 deletions interfaces/hyperionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface ApiLimits {
}

interface ApiConfigs {
disable_rate_limit?: boolean;
disable_tx_cache?: boolean;
tx_cache_expiration_sec?: number | string;
rate_limit_rpm?: number;
Expand Down
Loading

0 comments on commit 80bd4ad

Please sign in to comment.