From 427233ee5570f6be837fa69bb6e3a932768af0b3 Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Thu, 31 Mar 2022 16:57:49 +0200 Subject: [PATCH 1/2] add fixes to resolve and search routes --- modules/constants.js | 25 +++++++++++++++++++++---- modules/controller/rpc-controller.js | 26 +++++++++++++------------- modules/service/query-service.js | 2 +- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/modules/constants.js b/modules/constants.js index 31fbd0bffa..aac888119f 100644 --- a/modules/constants.js +++ b/modules/constants.js @@ -193,16 +193,33 @@ exports.STRINGIFIED_NETWORK_RESPONSES = { }; /** - * @constant {object} STRINGIFIED_NETWORK_RESPONSES - - * Stringified types of known network responses + * @constant {object} NETWORK_PROTOCOLS - + * Network protocols */ exports.NETWORK_PROTOCOLS = { STORE: '/store/1.0.0', RESOLVE: '/resolve/1.0.0', SEARCH: '/search/1.0.0', - SEARCH_RESULT: '/search/result/1.0.0', + SEARCH_RESULT: '/search/1.0.0/result', SEARCH_ASSERTIONS: '/search/assertions/1.0.0', - SEARCH_ASSERTIONS_RESULT: '/search/assertions/result/1.0.0', + SEARCH_ASSERTIONS_RESULT: '/search/assertions/1.0.0/result', +}; + +/** + * @constant {object} SERVICE_API_ROUTES + * Service api routes + */ +exports.SERVICE_API_ROUTES = { + PUBLISH: '/publish', + PROVISION: '/provision', + UPDATE: '/update', + RESOLVE: '/resolve', + SEARCH: '/entities::search', + SEARCH_ASSERTIONS: '/assertions::search', + QUERY: '/query', + PROOFS: '/proofs::get', + OPERATION_RESULT: '/:operation/result/:handler_id', + INFO: '/info', }; /** diff --git a/modules/controller/rpc-controller.js b/modules/controller/rpc-controller.js index a8f4895fdc..9b6d53b59a 100644 --- a/modules/controller/rpc-controller.js +++ b/modules/controller/rpc-controller.js @@ -190,15 +190,15 @@ class RpcController { initializeServiceApi() { this.logger.info(`Service API module enabled, server running on port ${this.config.rpcPort}`); - this.app.post('/publish', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.post(constants.SERVICE_API_ROUTES.PUBLISH, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { await this.publish(req, res, next, { isAsset: false }); }); - this.app.post('/provision', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.post(constants.SERVICE_API_ROUTES.PROVISION, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { await this.publish(req, res, next, { isAsset: true, ual: null }); }); - this.app.post('/update', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.post(constants.SERVICE_API_ROUTES.UPDATE, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { if (!req.body.ual) { return next({ code: 400, @@ -209,7 +209,7 @@ class RpcController { }); this.app.get( - constants.NETWORK_PROTOCOLS.STORE, + constants.SERVICE_API_ROUTES.RESOLVE, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { @@ -359,7 +359,7 @@ class RpcController { this.logger.info(`Searching for closest ${this.config.replicationFactor} node(s) for keyword ${id}`); const nodes = await this.networkService.findNodes( id, - constants.NETWORK_PROTOCOLS.STORE, + constants.NETWORK_PROTOCOLS.RESOLVE, this.config.replicationFactor, ); if (nodes.length < this.config.replicationFactor) { @@ -463,7 +463,7 @@ class RpcController { }, ); - this.app.get('/assertions::search', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.get(constants.SERVICE_API_ROUTES.SEARCH_ASSERTIONS, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { if (!req.query.query || req.params.search !== 'search') { return next({ code: 400, message: 'Params query is necessary.' }); } @@ -519,7 +519,7 @@ class RpcController { ); this.logger.info(`Searching for closest ${this.config.replicationFactor} node(s) for keyword ${query}`); - let nodes = await this.networkService.findNodes(query, '/assertions::search', this.config.replicationFactor); + let nodes = await this.networkService.findNodes(query, constants.NETWORK_PROTOCOLS.SEARCH_ASSERTIONS, this.config.replicationFactor); if (nodes.length < this.config.replicationFactor) { this.logger.warn(`Found only ${nodes.length} node(s) for keyword ${query}`); } @@ -549,7 +549,7 @@ class RpcController { } }); - this.app.get('/entities::search', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.get(constants.SERVICE_API_ROUTES.SEARCH, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { if (!req.query.query || req.params.search !== 'search') { return next({ code: 400, message: 'Params query or ids are necessary.' }); } @@ -614,7 +614,7 @@ class RpcController { this.logger.info(`Searching for closest ${this.config.replicationFactor} node(s) for keyword ${query}`); nodes = await this.networkService.findNodes( query, - '/entities::search', + constants.NETWORK_PROTOCOLS.SEARCH, this.config.replicationFactor, ); if (nodes.length < this.config.replicationFactor) { @@ -662,7 +662,7 @@ class RpcController { } }); - this.app.post('/query', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.post(constants.SERVICE_API_ROUTES.QUERY, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { if (!req.body.query || !req.query.type) { return next({ code: 400, message: 'Params query and type are necessary.' }); } @@ -735,7 +735,7 @@ class RpcController { } }); - this.app.post('/proofs::get', this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { + this.app.post(constants.SERVICE_API_ROUTES.PROOFS, this.rateLimitMiddleware, this.slowDownMiddleware, async (req, res, next) => { if (!req.body.nquads) { return next({ code: 400, message: 'Params query and type are necessary.' }); } @@ -809,7 +809,7 @@ class RpcController { } }); - this.app.get('/:operation/result/:handler_id', async (req, res, next) => { + this.app.get(constants.SERVICE_API_ROUTES.OPERATION_RESULT, async (req, res, next) => { if (!['provision', 'update', 'publish', 'resolve', 'query', 'entities:search', 'assertions:search', 'proofs:get'].includes(req.params.operation)) { return next({ code: 400, @@ -958,7 +958,7 @@ class RpcController { } }); - this.app.get('/info', async (req, res, next) => { + this.app.get(constants.SERVICE_API_ROUTES.INFO, async (req, res, next) => { try { const { version } = pjson; diff --git a/modules/service/query-service.js b/modules/service/query-service.js index bd88484670..19d98f8795 100644 --- a/modules/service/query-service.js +++ b/modules/service/query-service.js @@ -18,7 +18,7 @@ class QueryService { }, constants.RESOLVE_MAX_TIME_MILLIS); const result = await this.networkService.sendMessage( - constants.NETWORK_PROTOCOLS.STORE, + constants.NETWORK_PROTOCOLS.RESOLVE, id, node, ); From 8c1ecb94917576d6b8b5e86dc5e1c727690b04ec Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Thu, 31 Mar 2022 18:14:27 +0200 Subject: [PATCH 2/2] bump hotfix version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9e07c9cae5..2c1e697215 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.0-beta.1.32", + "version": "6.0.0-beta.1.33-hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.0-beta.1.32", + "version": "6.0.0-beta.1.33-hotfix.1", "license": "ISC", "dependencies": { "app-root-path": "^3.0.0", diff --git a/package.json b/package.json index 2c284514a0..7e3602c2f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.0-beta.1.32", + "version": "6.0.0-beta.1.33-hotfix.1", "description": "OTNode v6 Beta 1", "main": "index.js", "scripts": {