From cec6c458063d3e97437c404c641f3c357fc8f4fe Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Tue, 5 Jan 2021 19:46:51 +0100 Subject: [PATCH 1/4] updated rpki-validator --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e05decf..2c47e57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5145,11 +5145,11 @@ } }, "rpki-validator": { - "version": "2.2.11", - "resolved": "https://registry.npmjs.org/rpki-validator/-/rpki-validator-2.2.11.tgz", - "integrity": "sha512-mrvIJJ2hmtLI4P0uKaZCsOUCR0M1glMFmzf3o/t047D5T2y4T33ho7ay5GrUdatn2E6BcaT1JLhBw82+HX9QBQ==", + "version": "2.2.12", + "resolved": "https://registry.npmjs.org/rpki-validator/-/rpki-validator-2.2.12.tgz", + "integrity": "sha512-sv6MWMVmEKceha/hZdgZjghIQanI09e3j71r8pTowqAHGpq3FyRqv/WgztvfA3u5TOlCklBybifB0kz/xKW0+Q==", "requires": { - "axios": "^0.21.0", + "axios": "^0.21.1", "brembo": "^2.0.4", "ip-sub": "^1.0.19", "radix-trie-js": "^1.0.5" diff --git a/package.json b/package.json index 77b4717..6ed00d7 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "nodemailer": "^6.4.16", "path": "^0.12.7", "restify": "^8.5.1", - "rpki-validator": "^2.2.11", + "rpki-validator": "^2.2.12", "semver": "^7.3.4", "syslog-client": "^1.1.1", "ws": "^7.4.0", From 0fbf1782cc1b64dcafdcb390347a0c48f8125b82 Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Thu, 7 Jan 2021 17:13:20 +0100 Subject: [PATCH 2/4] performance improvement, validate prefixes only during translate function --- src/inputs/input.js | 2 +- src/monitors/monitorHijack.js | 3 +-- src/monitors/monitorNewPrefix.js | 2 +- src/monitors/monitorVisibility.js | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/inputs/input.js b/src/inputs/input.js index c0f8677..aa0892f 100644 --- a/src/inputs/input.js +++ b/src/inputs/input.js @@ -121,7 +121,7 @@ export default class Input { getMoreSpecificMatch = (prefix, includeIgnoredMorespecifics) => { for (let p of this.prefixes) { - if (ipUtils.isEqualPrefix(p.prefix, prefix)) { + if (ipUtils._isEqualPrefix(p.prefix, prefix)) { return p; } else { diff --git a/src/monitors/monitorHijack.js b/src/monitors/monitorHijack.js index 30ce52b..544d539 100644 --- a/src/monitors/monitorHijack.js +++ b/src/monitors/monitorHijack.js @@ -57,7 +57,7 @@ export default class MonitorHijack extends Monitor { const message = alerts[0].matchedMessage; const asnText = matchedRule.asn; - return (ipUtils.isEqualPrefix(message.prefix, matchedRule.prefix)) ? + return (ipUtils._isEqualPrefix(message.prefix, matchedRule.prefix)) ? `The prefix ${matchedRule.prefix} (${matchedRule.description}) is announced by ${message.originAS} instead of ${asnText}` : `A new prefix ${message.prefix} is announced by ${message.originAS}. ` + `It should be instead ${matchedRule.prefix} (${matchedRule.description}) announced by ${asnText}`; @@ -82,7 +82,6 @@ export default class MonitorHijack extends Monitor { monitor = (message) => new Promise((resolve, reject) => { - const messagePrefix = message.prefix; const matchedRule = this.getMoreSpecificMatch(messagePrefix, false); diff --git a/src/monitors/monitorNewPrefix.js b/src/monitors/monitorNewPrefix.js index e053a62..1e341e3 100644 --- a/src/monitors/monitorNewPrefix.js +++ b/src/monitors/monitorNewPrefix.js @@ -70,7 +70,7 @@ export default class MonitorNewPrefix extends Monitor { if (matchedRule && !matchedRule.ignore && matchedRule.asn.includes(message.originAS) && - !ipUtils.isEqualPrefix(matchedRule.prefix, messagePrefix)) { + !ipUtils._isEqualPrefix(matchedRule.prefix, messagePrefix)) { this.publishAlert(message.originAS.getId() + "-" + message.prefix, matchedRule.asn.getId(), diff --git a/src/monitors/monitorVisibility.js b/src/monitors/monitorVisibility.js index 0b3c74e..2b9271a 100644 --- a/src/monitors/monitorVisibility.js +++ b/src/monitors/monitorVisibility.js @@ -77,7 +77,7 @@ export default class MonitorVisibility extends Monitor { const messagePrefix = message.prefix; const matchedRule = this.getMoreSpecificMatch(messagePrefix, false); - if (matchedRule && !matchedRule.ignore && ipUtils.isEqualPrefix(matchedRule.prefix, messagePrefix)) { + if (matchedRule && !matchedRule.ignore && ipUtils._isEqualPrefix(matchedRule.prefix, messagePrefix)) { let key = matchedRule.prefix; From f2b64e1a74086a410849fd0967e3ea0725cfbaa3 Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Thu, 7 Jan 2021 17:14:05 +0100 Subject: [PATCH 3/4] performance improvement, switch argument position to avoid nested functions --- src/connectors/connectorTest.js | 2 +- src/consumer.js | 5 +---- src/reports/report.js | 2 +- src/utils/WebSocket.js | 2 +- src/utils/pubSub.js | 5 ++--- tests/1_config.js | 2 +- tests/2_alerting.js | 12 ++++++------ tests/proxy_tests/tests.js | 2 +- tests/rpki_tests/tests.default.js | 2 +- tests/rpki_tests/tests.external-missing-roas.js | 2 +- tests/rpki_tests/tests.external-roas.js | 2 +- tests/rpki_tests/tests.external.js | 2 +- 12 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/connectors/connectorTest.js b/src/connectors/connectorTest.js index c7b5c7a..dae39cd 100644 --- a/src/connectors/connectorTest.js +++ b/src/connectors/connectorTest.js @@ -38,7 +38,7 @@ export default class ConnectorTest extends Connector{ constructor(name, params, env) { super(name, params, env); - this.pubSub.subscribe("test-type", (type, message) => { + this.pubSub.subscribe("test-type", (message, type) => { clearInterval(this.timer); this.subscribe({type: message}); }); diff --git a/src/consumer.js b/src/consumer.js index 32b706d..5f14c9c 100644 --- a/src/consumer.js +++ b/src/consumer.js @@ -55,10 +55,7 @@ export default class Consumer { }); } process.on('message', this.dispatch); - env.pubSub.subscribe('data', (type, data) => { - this.dispatch(data); - }); - + env.pubSub.subscribe('data', this.dispatch); }; dispatch = (buffer) => { diff --git a/src/reports/report.js b/src/reports/report.js index 583bc56..228f285 100644 --- a/src/reports/report.js +++ b/src/reports/report.js @@ -46,7 +46,7 @@ export default class Report { this.params = params; for (let channel of channels){ - env.pubSub.subscribe(channel, (message, content) => { + env.pubSub.subscribe(channel, (content, message) => { return this.report(message, content); }); } diff --git a/src/utils/WebSocket.js b/src/utils/WebSocket.js index 7661f87..1360ae5 100644 --- a/src/utils/WebSocket.js +++ b/src/utils/WebSocket.js @@ -101,5 +101,5 @@ export default class WebSocket { }; - on = (event, callback) => this.pubsub.subscribe(event, (_, data) => callback(data)); + on = (event, callback) => this.pubsub.subscribe(event, callback); } \ No newline at end of file diff --git a/src/utils/pubSub.js b/src/utils/pubSub.js index 70d2a46..f6a74cf 100644 --- a/src/utils/pubSub.js +++ b/src/utils/pubSub.js @@ -9,10 +9,9 @@ export default class PubSub { }; publish(channel, content) { - const callbacks = this.callbacks[channel] || []; - for (let clb of callbacks) { + for (let clb of this.callbacks[channel] || []) { new Promise(function(resolve, reject){ - clb(channel, content); + clb(content, channel); resolve(true); }) .catch(console.log); diff --git a/tests/1_config.js b/tests/1_config.js index d777c32..82cc1a5 100644 --- a/tests/1_config.js +++ b/tests/1_config.js @@ -210,7 +210,7 @@ describe("Core functions", function() { const worker = require("../index"); const pubSub = worker.pubSub; - pubSub.subscribe("software-update", function (type, message) { + pubSub.subscribe("software-update", function (message, type) { expect(type).to.equal("software-update"); done(); }); diff --git a/tests/2_alerting.js b/tests/2_alerting.js index 8824648..1b96071 100644 --- a/tests/2_alerting.js +++ b/tests/2_alerting.js @@ -69,7 +69,7 @@ describe("Alerting", function () { }; let visibilityTestCompleted = false; - pubSub.subscribe("visibility", (type, message) => { + pubSub.subscribe("visibility", (message, type) => { try { if (!visibilityTestCompleted) { message = JSON.parse(JSON.stringify(message)); @@ -189,7 +189,7 @@ describe("Alerting", function () { } }; let hijackTestCompleted = false - pubSub.subscribe("hijack", (type, message) => { + pubSub.subscribe("hijack", (message, type) => { try { if (!hijackTestCompleted) { message = JSON.parse(JSON.stringify(message)); @@ -336,7 +336,7 @@ describe("Alerting", function () { }; let newprefixTestCompleted = false; - pubSub.subscribe("newprefix", (type, message) => { + pubSub.subscribe("newprefix", (message, type) => { try { if (!newprefixTestCompleted) { message = JSON.parse(JSON.stringify(message)); @@ -462,7 +462,7 @@ describe("Alerting", function () { }; let pathTestCompleted = false; - pubSub.subscribe("path", (type, message) => { + pubSub.subscribe("path", (message, type) => { try { if (!pathTestCompleted) { message = JSON.parse(JSON.stringify(message)); @@ -515,7 +515,7 @@ describe("Alerting", function () { }; let misconfigurationTestCompleted = false; - pubSub.subscribe("misconfiguration", (type, message) => { + pubSub.subscribe("misconfiguration", (message, type) => { if (!misconfigurationTestCompleted) { try { @@ -559,7 +559,7 @@ describe("Alerting", function () { } }, 15000); - pubSub.subscribe("visibility", function (type, message) { + pubSub.subscribe("visibility", function (message, type) { notReceived = false; }); pubSub.publish("test-type", "fade-off"); diff --git a/tests/proxy_tests/tests.js b/tests/proxy_tests/tests.js index 1309f3e..123c388 100644 --- a/tests/proxy_tests/tests.js +++ b/tests/proxy_tests/tests.js @@ -49,7 +49,7 @@ describe("Composition", function() { describe("Software updates check", function () { it("new version detected with proxy", function (done) { - pubSub.subscribe("software-update", function (type, message) { + pubSub.subscribe("software-update", function (message, type) { expect(type).to.equal("software-update"); done(); }); diff --git a/tests/rpki_tests/tests.default.js b/tests/rpki_tests/tests.default.js index 6c84876..e243ba8 100644 --- a/tests/rpki_tests/tests.default.js +++ b/tests/rpki_tests/tests.default.js @@ -70,7 +70,7 @@ describe("RPKI monitoring 1", function() { let rpkiTestCompleted = false; let started = false; - pubSub.subscribe("rpki", function (type, message) { + pubSub.subscribe("rpki", function (message, type) { try { if (started && !rpkiTestCompleted) { message = JSON.parse(JSON.stringify(message)); diff --git a/tests/rpki_tests/tests.external-missing-roas.js b/tests/rpki_tests/tests.external-missing-roas.js index 8d31f1a..391fc3b 100644 --- a/tests/rpki_tests/tests.external-missing-roas.js +++ b/tests/rpki_tests/tests.external-missing-roas.js @@ -63,7 +63,7 @@ describe("RPKI monitoring 3", function() { let rpkiTestCompletedExternal = false; let started = false; - pubSub.subscribe("rpki", function (type, message) { + pubSub.subscribe("rpki", function (message, type) { try { if (started && !rpkiTestCompletedExternal) { message = JSON.parse(JSON.stringify(message)); diff --git a/tests/rpki_tests/tests.external-roas.js b/tests/rpki_tests/tests.external-roas.js index 4477032..b49f911 100644 --- a/tests/rpki_tests/tests.external-roas.js +++ b/tests/rpki_tests/tests.external-roas.js @@ -67,7 +67,7 @@ describe("RPKI monitoring 4", function() { }; let rpkiTestCompletedExternal = false; - pubSub.subscribe("rpki", function (type, message) { + pubSub.subscribe("rpki", function (message, type) { try { if (!rpkiTestCompletedExternal) { diff --git a/tests/rpki_tests/tests.external.js b/tests/rpki_tests/tests.external.js index de82968..c4213c2 100644 --- a/tests/rpki_tests/tests.external.js +++ b/tests/rpki_tests/tests.external.js @@ -64,7 +64,7 @@ describe("RPKI monitoring 2", function() { let rpkiTestCompletedExternal = false; let started = false; - pubSub.subscribe("rpki", function (type, message) { + pubSub.subscribe("rpki", function (message, type) { try { if (started && !rpkiTestCompletedExternal) { message = JSON.parse(JSON.stringify(message)); From 25f9833c16f3c1f184b37d60eacd6444ce0d6496 Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Thu, 7 Jan 2021 18:48:07 +0100 Subject: [PATCH 4/4] updated friends file --- docs/friends.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/friends.md b/docs/friends.md index 9bb9c43..51c6248 100644 --- a/docs/friends.md +++ b/docs/friends.md @@ -11,3 +11,7 @@ Please, let me know so I can add your company name here. * MTLNOG * EBOX (AS1403) * Cloudflare (AS13335) +* Vocus (AS4826 & AS9443) +* HEAnet (AS1213) +* Tech Futures (AS394256) +* Fastly (AS54113)