From fcc2328a3bf49eb5310413058cc9ebaf8e7819f8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 4 Dec 2019 18:04:30 +0100 Subject: [PATCH] WIP netiquette --- docker/{tag-config => netiquette}/.gitignore | 0 docker/{tag-config => netiquette}/README.md | 2 ++ docker/{tag-config => netiquette}/index.mjs | 11 +++++++---- docker/{tag-config => netiquette}/package-lock.json | 0 docker/{tag-config => netiquette}/package.json | 2 +- .../{tag-config => netiquette}/src/catalog/consul.mjs | 0 docker/netiquette/src/catalog/control_loop.mjs | 10 ++++++++++ .../src/injector/iptables.mjs | 0 .../{tag-config => netiquette}/src/injector/upnp.mjs | 0 docker/{tag-config => netiquette}/src/io/files.mjs | 0 docker/{tag-config => netiquette}/src/io/run.mjs | 0 docker/{tag-config => netiquette}/static.iptables | 0 docker/{tag-config => netiquette}/test/io.mjs | 0 docker/{tag-config => netiquette}/test/iptables.mjs | 0 docker/{tag-config => netiquette}/test/runner.mjs | 0 15 files changed, 20 insertions(+), 5 deletions(-) rename docker/{tag-config => netiquette}/.gitignore (100%) rename docker/{tag-config => netiquette}/README.md (95%) rename docker/{tag-config => netiquette}/index.mjs (72%) rename docker/{tag-config => netiquette}/package-lock.json (100%) rename docker/{tag-config => netiquette}/package.json (93%) rename docker/{tag-config => netiquette}/src/catalog/consul.mjs (100%) create mode 100644 docker/netiquette/src/catalog/control_loop.mjs rename docker/{tag-config => netiquette}/src/injector/iptables.mjs (100%) rename docker/{tag-config => netiquette}/src/injector/upnp.mjs (100%) rename docker/{tag-config => netiquette}/src/io/files.mjs (100%) rename docker/{tag-config => netiquette}/src/io/run.mjs (100%) rename docker/{tag-config => netiquette}/static.iptables (100%) rename docker/{tag-config => netiquette}/test/io.mjs (100%) rename docker/{tag-config => netiquette}/test/iptables.mjs (100%) rename docker/{tag-config => netiquette}/test/runner.mjs (100%) diff --git a/docker/tag-config/.gitignore b/docker/netiquette/.gitignore similarity index 100% rename from docker/tag-config/.gitignore rename to docker/netiquette/.gitignore diff --git a/docker/tag-config/README.md b/docker/netiquette/README.md similarity index 95% rename from docker/tag-config/README.md rename to docker/netiquette/README.md index 0746388..e4c2f27 100644 --- a/docker/tag-config/README.md +++ b/docker/netiquette/README.md @@ -1,3 +1,5 @@ +# netiquette + ``` npm install npm test diff --git a/docker/tag-config/index.mjs b/docker/netiquette/index.mjs similarity index 72% rename from docker/tag-config/index.mjs rename to docker/netiquette/index.mjs index a5b51fc..6aca6e4 100644 --- a/docker/tag-config/index.mjs +++ b/docker/netiquette/index.mjs @@ -3,6 +3,7 @@ import consul from 'consul' import { exec } from './src/io/run.mjs' import { readFile } from './src/io/files.mjs' +import ctlg_control_loop from './src/catalog/control_loop.mjs' import ctlg_consul from './src/catalog/consul.mjs' import inj_iptables from './src/injector/iptables.mjs' @@ -24,9 +25,8 @@ function* notifications_aggregator(injectors) { for(let idx = 0; true; idx++) { yield async (tag_list) => { states[idx] = tag_list - await Promise.all( - injectors.map(notify => - notify(states.reduce((acc, tag) => [...acc, ...tag], [])))) + const merged = states.reduce((acc, tag) => [...acc, ...tag], []) + await Promise.all(injectors.map(notify => notify(merged))) } } } @@ -37,12 +37,15 @@ const main = async () => { // Initialize all injectors const injectors = [ - await inj_iptables(args.ipt_base, readFile, exec, console.log) + await inj_iptables(args.ipt_base, readFile, exec, console.log), + // await inj_upnp ] // Initialize all catalogs and map them to the injectors const aggr = notifications_aggregator(injectors) const catalogs = [ + // this catalog is used to defeat deriving config due to single resource updated async. by multiple prog or by external program not tracked by catalogs + await ctlg_control_loop(setInterval, 60000, aggr.next().value), await ctlg_consul(args.node, consul(), console.log, aggr.next().value) ] diff --git a/docker/tag-config/package-lock.json b/docker/netiquette/package-lock.json similarity index 100% rename from docker/tag-config/package-lock.json rename to docker/netiquette/package-lock.json diff --git a/docker/tag-config/package.json b/docker/netiquette/package.json similarity index 93% rename from docker/tag-config/package.json rename to docker/netiquette/package.json index 892fb87..02fa0b3 100644 --- a/docker/tag-config/package.json +++ b/docker/netiquette/package.json @@ -1,5 +1,5 @@ { - "name": "consul-to-igd", + "name": "netiquette", "version": "1.0.0", "description": "", "main": "index.mjs", diff --git a/docker/tag-config/src/catalog/consul.mjs b/docker/netiquette/src/catalog/consul.mjs similarity index 100% rename from docker/tag-config/src/catalog/consul.mjs rename to docker/netiquette/src/catalog/consul.mjs diff --git a/docker/netiquette/src/catalog/control_loop.mjs b/docker/netiquette/src/catalog/control_loop.mjs new file mode 100644 index 0000000..56ad6f5 --- /dev/null +++ b/docker/netiquette/src/catalog/control_loop.mjs @@ -0,0 +1,10 @@ +'use strict' + +let l +export default l = async (timer, interval, notify) => { + timer(() => { + notify([]) + console.log(`[control_loop] actuation (triggered every ${interval} ms)`) + }, interval) + console.log("[control_loop] initialized") +} diff --git a/docker/tag-config/src/injector/iptables.mjs b/docker/netiquette/src/injector/iptables.mjs similarity index 100% rename from docker/tag-config/src/injector/iptables.mjs rename to docker/netiquette/src/injector/iptables.mjs diff --git a/docker/tag-config/src/injector/upnp.mjs b/docker/netiquette/src/injector/upnp.mjs similarity index 100% rename from docker/tag-config/src/injector/upnp.mjs rename to docker/netiquette/src/injector/upnp.mjs diff --git a/docker/tag-config/src/io/files.mjs b/docker/netiquette/src/io/files.mjs similarity index 100% rename from docker/tag-config/src/io/files.mjs rename to docker/netiquette/src/io/files.mjs diff --git a/docker/tag-config/src/io/run.mjs b/docker/netiquette/src/io/run.mjs similarity index 100% rename from docker/tag-config/src/io/run.mjs rename to docker/netiquette/src/io/run.mjs diff --git a/docker/tag-config/static.iptables b/docker/netiquette/static.iptables similarity index 100% rename from docker/tag-config/static.iptables rename to docker/netiquette/static.iptables diff --git a/docker/tag-config/test/io.mjs b/docker/netiquette/test/io.mjs similarity index 100% rename from docker/tag-config/test/io.mjs rename to docker/netiquette/test/io.mjs diff --git a/docker/tag-config/test/iptables.mjs b/docker/netiquette/test/iptables.mjs similarity index 100% rename from docker/tag-config/test/iptables.mjs rename to docker/netiquette/test/iptables.mjs diff --git a/docker/tag-config/test/runner.mjs b/docker/netiquette/test/runner.mjs similarity index 100% rename from docker/tag-config/test/runner.mjs rename to docker/netiquette/test/runner.mjs