Merge cc into dd (#317)
* Fix ETH fee fetching (#303) * v7.3.3 (#304) * Throttle clock skew and fetch logs * PR Fixes * Reduce throttle time * Remove old endpoint * Fix standard styles and improve readability * Simplify throttling * Small fixes * Bump version
This commit is contained in:
parent
2e675f738f
commit
1153c6af6a
3 changed files with 28 additions and 17 deletions
|
|
@ -26,10 +26,14 @@ const argv = require('minimist')(process.argv.slice(2))
|
|||
|
||||
const CLOCK_SKEW = 60 * 1000
|
||||
const REQUEST_TTL = 3 * 60 * 1000
|
||||
const THROTTLE_LOGS_QUERY = 30 * 1000
|
||||
const THROTTLE_CLOCK_SKEW = 60 * 1000
|
||||
|
||||
const pids = {}
|
||||
const reboots = {}
|
||||
const restartServicesMap = {}
|
||||
const canGetLastSeenMap = {}
|
||||
const canLogClockSkewMap = {}
|
||||
|
||||
const devMode = argv.dev || options.http
|
||||
|
||||
|
|
@ -167,13 +171,6 @@ function stateChange (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
function deviceEvent (req, res, next) {
|
||||
const pi = plugins(req.settings, req.deviceId)
|
||||
pi.logEvent(req.body)
|
||||
.then(() => respond(req, res))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
function verifyUser (req, res, next) {
|
||||
const pi = plugins(req.settings, req.deviceId)
|
||||
pi.verifyUser(req.body)
|
||||
|
|
@ -245,11 +242,21 @@ function updateCustomer (req, res, next) {
|
|||
}
|
||||
|
||||
function getLastSeen (req, res, next) {
|
||||
return logs.getLastSeen(req.deviceId)
|
||||
const deviceId = req.deviceId
|
||||
const timestamp = Date.now()
|
||||
const shouldTrigger = !canGetLastSeenMap[deviceId] ||
|
||||
timestamp - canGetLastSeenMap[deviceId] >= THROTTLE_LOGS_QUERY
|
||||
|
||||
if (shouldTrigger) {
|
||||
canGetLastSeenMap[deviceId] = timestamp
|
||||
return logs.getLastSeen(deviceId)
|
||||
.then(r => res.json(r))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
return res.status(408).json({})
|
||||
}
|
||||
|
||||
function updateLogs (req, res, next) {
|
||||
return logs.update(req.deviceId, req.body.logs)
|
||||
.then(status => res.json({ success: status }))
|
||||
|
|
@ -310,9 +317,15 @@ function httpError (msg, code) {
|
|||
|
||||
function filterOldRequests (req, res, next) {
|
||||
const deviceTime = req.deviceTime
|
||||
const delta = Date.now() - Date.parse(deviceTime)
|
||||
const deviceId = req.deviceId
|
||||
const timestamp = Date.now()
|
||||
const delta = timestamp - Date.parse(deviceTime)
|
||||
|
||||
if (delta > CLOCK_SKEW) {
|
||||
const shouldTrigger = !canLogClockSkewMap[deviceId] ||
|
||||
timestamp - canLogClockSkewMap[deviceId] >= THROTTLE_CLOCK_SKEW
|
||||
|
||||
if (delta > CLOCK_SKEW && shouldTrigger) {
|
||||
canLogClockSkewMap[deviceId] = timestamp
|
||||
logger.error('Clock skew with lamassu-machine[%s] too high [%ss], adjust lamassu-machine clock',
|
||||
req.deviceName, (delta / 1000).toFixed(2))
|
||||
}
|
||||
|
|
@ -337,8 +350,7 @@ function authorize (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
const skip = (req, res) => _.includes(req.path, ['/poll', '/state', '/logs']) &&
|
||||
res.statusCode === 200
|
||||
const skip = (req, res) => _.includes(req.path, ['/poll', '/state', '/logs']) && _.includes(res.statusCode, [200, 408])
|
||||
|
||||
const configRequiredRoutes = [
|
||||
'/poll',
|
||||
|
|
@ -367,7 +379,6 @@ app.use(filterOldRequests)
|
|||
app.get('/poll', poll)
|
||||
app.post('/state', stateChange)
|
||||
|
||||
app.post('/event', deviceEvent)
|
||||
app.post('/verify_user', verifyUser)
|
||||
app.post('/verify_transaction', verifyTx)
|
||||
|
||||
|
|
|
|||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "lamassu-server",
|
||||
"version": "7.3.2",
|
||||
"version": "7.3.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "lamassu-server",
|
||||
"description": "bitcoin atm client server protocol module",
|
||||
"keywords": [],
|
||||
"version": "7.3.2",
|
||||
"version": "7.4.0",
|
||||
"license": "Unlicense",
|
||||
"author": "Lamassu (https://lamassu.is)",
|
||||
"dependencies": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue