Skip to content

Commit

Permalink
Merge pull request #1873 from OriginTrail/v6/hotfix/resolve-search
Browse files Browse the repository at this point in the history
  • Loading branch information
kotlarmilos authored Mar 31, 2022
2 parents 306ca20 + 77ca172 commit ab7cd82
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
25 changes: 21 additions & 4 deletions modules/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

/**
Expand Down
26 changes: 13 additions & 13 deletions modules/controller/rpc-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -209,7 +209,7 @@ class RpcController {
});

this.app.get(
'/resolve',
constants.SERVICE_API_ROUTES.RESOLVE,
this.rateLimitMiddleware,
this.slowDownMiddleware,
async (req, res, next) => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.' });
}
Expand Down Expand Up @@ -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}`);
}
Expand Down Expand Up @@ -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.' });
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.' });
}
Expand Down Expand Up @@ -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.' });
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion modules/service/query-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "6.0.0-beta.1.33",
"version": "6.0.0-beta.1.33-hotfix.1",
"description": "OTNode v6 Beta 1",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ab7cd82

Please sign in to comment.