From 9369b82633169f215b5fc20fc2d3ed1ae905b14c Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Mon, 20 Jan 2020 17:56:43 +0100 Subject: [PATCH] added subscription optimisation to avoid server side filtering --- src/inputs/input.js | 16 +++++++++++++++- src/inputs/inputYml.js | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/inputs/input.js b/src/inputs/input.js index c20c627..595de98 100644 --- a/src/inputs/input.js +++ b/src/inputs/input.js @@ -55,7 +55,21 @@ export default class Input { return false; }; + sanitizePrefixList = () => { + this.prefixes.forEach(item => { + if (item.prefix.includes(':')){ + item.prefix = ipUtils.expandIPv6(item.prefix); + } + }); + + if ([...new Set(this.prefixes.map(i => i.prefix))].length !== this.prefixes.length) { + throw new Error("The prefix list contains duplicates"); + } + }; + getMonitoredLessSpecifics = () => { + this.sanitizePrefixList(); + if (!this.prefixes.length) { return []; } @@ -68,7 +82,6 @@ export default class Input { lessSpecifics.push(prefixes[prefixes.length - 1]); - for (let p1 of prefixes.slice(0, -1)) { if (!this._isAlreadyContained(p1.prefix, lessSpecifics)){ lessSpecifics.push(p1); @@ -87,6 +100,7 @@ export default class Input { }; getMoreSpecificMatch = (prefix) => { + this.sanitizePrefixList(); for (let p of this.prefixes) { if (p.prefix === prefix) { diff --git a/src/inputs/inputYml.js b/src/inputs/inputYml.js index d36b824..5ce54be 100644 --- a/src/inputs/inputYml.js +++ b/src/inputs/inputYml.js @@ -34,7 +34,7 @@ import yaml from "js-yaml"; import fs from "fs"; import Input from "./input"; import ipUtils from "ip-sub"; -import { AS, Path } from "../model"; +import { AS } from "../model"; export default class InputYml extends Input {