Compare commits

..
9 Commits
Author SHA1 Message Date
Chris Troutner 09f0cb6b6e Merge pull request #106 from Permissionless-Software-Foundation/ct-unstable
Improved rate-limits with bch-js v4.15.18
2021-02-27 16:18:38 -08:00
Chris Troutner fb43b3f390 fix(bch-js): Bumping to v4.15.18 2021-02-27 16:17:28 -08:00
Chris Troutner f76f00d235 Adding decatur script to gitignore 2021-02-27 08:13:44 -08:00
Chris Troutner ac96860c27 Merge pull request #105 from Permissionless-Software-Foundation/ct-unstable
feat(v3 hydrateUxos): Deprecating v3 hydrateUtxos to improve system s…
2021-02-24 18:21:47 -08:00
Chris Troutner c51290acf5 feat(v3 hydrateUxos): Deprecating v3 hydrateUtxos to improve system stability 2021-02-24 18:18:23 -08:00
Chris Troutner 2f520dcaec Merge pull request #104 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Bumping to v4.15.8
2021-02-24 18:11:26 -08:00
Chris Troutner e0be1d308a fix(bch-js): Bumping to v4.15.8 2021-02-24 18:09:24 -08:00
Chris Troutner 9cd06630ea Merge pull request #103 from Permissionless-Software-Foundation/ct-unstable
fix(rate limits): Passing JWT token to internal calls
2021-02-24 17:10:17 -08:00
Chris Troutner 6b281e2842 fix(rate limits): Passing JWT token to internal calls 2021-02-24 17:07:24 -08:00
7 changed files with 490 additions and 458 deletions
+1
View File
@@ -29,6 +29,7 @@ test-fullstack-bchn.sh
start-fullstack-abc.sh start-fullstack-abc.sh
start-fullstack-bchn.sh start-fullstack-bchn.sh
start-ss-main.sh start-ss-main.sh
start-decatur-bchn.sh
coverage coverage
start-my-infra start-my-infra
+447 -439
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -29,7 +29,7 @@
"node": ">=10.15.1" "node": ">=10.15.1"
}, },
"dependencies": { "dependencies": {
"@psf/bch-js": "^4.15.7", "@psf/bch-js": "^4.15.18",
"apidoc": "^0.26.0", "apidoc": "^0.26.0",
"axios": "^0.21.1", "axios": "^0.21.1",
"bitcore-lib-cash": "^8.23.1", "bitcore-lib-cash": "^8.23.1",
+22 -13
View File
@@ -113,6 +113,27 @@ class RateLimits {
err err
) )
} }
//
} else if (req.body && req.body.usrObj) {
// Same as above, but this code path is activated from internal calls to
// bch-js, like hydrateUtxo(), which passes the user object from the
// original API call.
try {
decoded = _this.jwt.verify(
req.body.usrObj.jwtToken,
_this.config.apiTokenSecret
)
// console.log(`decoded: ${JSON.stringify(decoded, null, 2)}`)
userId = decoded.id
} catch (err) {
// This handler will be triggered if the JWT token does not match the
// token secret.
wlogger.error(
'Error in route-ratelimit.js trying to decode JWT token in usrObj'
)
}
} else { } else {
wlogger.debug('No JWT token found!') wlogger.debug('No JWT token found!')
} }
@@ -132,19 +153,7 @@ class RateLimits {
// Key will be the JWT ID if it exists, otherwise the IP address of the caller. // Key will be the JWT ID if it exists, otherwise the IP address of the caller.
let key = userId || req.ip let key = userId || req.ip
res.locals.key = key // Feedback for tests. res.locals.key = key // Feedback for tests.
// console.log(`key: ${key}`)
// For internal calls that make a lot of internal calls, like
// hydrateUtxoDetails(), the origin of the caller will be passed in
// via the POST body.
const keyIsLocal =
key.includes('172.17.0.1') || key.includes('127.0.0.1')
if (req.body && req.body.usrObj && keyIsLocal) {
// key = req.body.ip
console.log(
`route-ratelimit usrObj: ${JSON.stringify(req.body.usrObj, null, 2)}`
)
}
console.log(`key: ${key}`)
// const pointsToConsume = userId ? 1 : 30 // const pointsToConsume = userId ? 1 : 30
decoded.resource = resource decoded.resource = resource
+2 -1
View File
@@ -85,7 +85,7 @@ class Slp {
_this.txsByAddressSingle _this.txsByAddressSingle
) )
_this.router.post('/generateSendOpReturn', _this.generateSendOpReturn) _this.router.post('/generateSendOpReturn', _this.generateSendOpReturn)
_this.router.post('/hydrateUtxos', _this.hydrateUtxos) // _this.router.post('/hydrateUtxos', _this.hydrateUtxos)
} }
// DRY error handler. // DRY error handler.
@@ -1621,6 +1621,7 @@ class Slp {
* *
* *
*/ */
async hydrateUtxos (req, res, next) { async hydrateUtxos (req, res, next) {
try { try {
const utxos = req.body.utxos const utxos = req.body.utxos
+14 -2
View File
@@ -92,6 +92,15 @@ class Encryption {
}) })
} }
// Generate a user object that can be passed along with internal calls
// from bch-js.
const usrObj = {
ip: req._remoteAddress,
jwtToken: req.locals.jwtToken,
proLimit: req.locals.proLimit,
apiLevel: req.locals.apiLevel
}
const cashAddr = _this.bchjs.Address.toCashAddress(address) const cashAddr = _this.bchjs.Address.toCashAddress(address)
// Prevent a common user error. Ensure they are using the correct network address. // Prevent a common user error. Ensure they are using the correct network address.
@@ -110,7 +119,7 @@ class Encryption {
cashAddr cashAddr
) )
const rawTxData = await _this.bchjs.Electrumx.transactions(cashAddr) const rawTxData = await _this.bchjs.Electrumx.transactions(cashAddr, usrObj)
// console.log(`rawTxData: ${JSON.stringify(rawTxData, null, 2)}`) // console.log(`rawTxData: ${JSON.stringify(rawTxData, null, 2)}`)
// Extract just the TXIDs // Extract just the TXIDs
@@ -126,9 +135,12 @@ class Encryption {
for (let i = 0; i < txids.length; i++) { for (let i = 0; i < txids.length; i++) {
const thisTx = txids[i] const thisTx = txids[i]
// CT 2/24/21: I might want to convert this to the POST call, to take
// advantage of the usrObj. It does not get passed in a GET call.
const txDetails = await _this.bchjs.RawTransactions.getRawTransaction( const txDetails = await _this.bchjs.RawTransactions.getRawTransaction(
thisTx, thisTx,
true true,
usrObj
) )
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`) // console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
+3 -2
View File
@@ -1980,9 +1980,10 @@ class Slp {
const utxos = req.body.utxos const utxos = req.body.utxos
// console.log('req: ', req) // console.log('req: ', req)
console.log(`req._remoteAddress: ${req._remoteAddress}`) // console.log(`req._remoteAddress: ${req._remoteAddress}`)
// const ip = req._remoteAddress
// Generate a user object that can be passed along with internal calls
// from bch-js.
const usrObj = { const usrObj = {
ip: req._remoteAddress, ip: req._remoteAddress,
jwtToken: req.locals.jwtToken, jwtToken: req.locals.jwtToken,