excessive vault request squelching
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
"author": "",
|
||||
"license": "unlicensed",
|
||||
"dependencies": {
|
||||
"@isaacs/ttlcache": "^1.4.1",
|
||||
"@maxmind/geoip2-node": "^5.0.0",
|
||||
"@socket.io/redis-adapter": "^8.2.1",
|
||||
"dotenv": "^16.3.1",
|
||||
|
||||
7
vault.js
7
vault.js
@@ -5,6 +5,7 @@ import {sendVaultOrders} from "./order.js";
|
||||
import {approveWallet} from "./approval.js";
|
||||
import {sql} from "./db.js";
|
||||
import {clientIP} from "./misc.js";
|
||||
import TTLCache from "@isaacs/ttlcache";
|
||||
|
||||
|
||||
export function vaultAddress(chainId, owner, num=0) {
|
||||
@@ -64,7 +65,13 @@ export async function loginAddress(socket, chainId, address) {
|
||||
}
|
||||
}
|
||||
|
||||
const requestVaultCooldown = new TTLCache({ttl:5 * 1000, checkAgeOnGet: true})
|
||||
|
||||
export async function requestVault(socket, chainId, owner, num) {
|
||||
const key = [chainId, owner, num].join('|')
|
||||
if (requestVaultCooldown.has(key))
|
||||
return
|
||||
requestVaultCooldown.set(key, true)
|
||||
const ipAddress = clientIP(socket)
|
||||
const time = new Date().toISOString();
|
||||
const query = `insert into vaultcreationrequest (chain, owner, num, time, ipaddr) values (${chainId}, '${owner}', ${num}, '${time}', '${ipAddress}') ON CONFLICT DO NOTHING`;
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
dependencies:
|
||||
minipass "^7.0.4"
|
||||
|
||||
"@isaacs/ttlcache@^1.4.1":
|
||||
version "1.4.1"
|
||||
resolved "https://registry.yarnpkg.com/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz#21fb23db34e9b6220c6ba023a0118a2dd3461ea2"
|
||||
integrity sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA==
|
||||
|
||||
"@maxmind/geoip2-node@^5.0.0":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@maxmind/geoip2-node/-/geoip2-node-5.0.0.tgz#56d5760ede1d9197ed401e2c8165d9a63853db3e"
|
||||
|
||||
Reference in New Issue
Block a user