WIP netiquette

This commit is contained in:
Quentin 2019-12-04 18:04:30 +01:00
parent 0b3eb8ec1b
commit fcc2328a3b
15 changed files with 20 additions and 5 deletions

View file

@ -1,3 +1,5 @@
# netiquette
``` ```
npm install npm install
npm test npm test

View file

@ -3,6 +3,7 @@ import consul from 'consul'
import { exec } from './src/io/run.mjs' import { exec } from './src/io/run.mjs'
import { readFile } from './src/io/files.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 ctlg_consul from './src/catalog/consul.mjs'
import inj_iptables from './src/injector/iptables.mjs' import inj_iptables from './src/injector/iptables.mjs'
@ -24,9 +25,8 @@ function* notifications_aggregator(injectors) {
for(let idx = 0; true; idx++) { for(let idx = 0; true; idx++) {
yield async (tag_list) => { yield async (tag_list) => {
states[idx] = tag_list states[idx] = tag_list
await Promise.all( const merged = states.reduce((acc, tag) => [...acc, ...tag], [])
injectors.map(notify => await Promise.all(injectors.map(notify => notify(merged)))
notify(states.reduce((acc, tag) => [...acc, ...tag], []))))
} }
} }
} }
@ -37,12 +37,15 @@ const main = async () => {
// Initialize all injectors // Initialize all injectors
const 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 // Initialize all catalogs and map them to the injectors
const aggr = notifications_aggregator(injectors) const aggr = notifications_aggregator(injectors)
const catalogs = [ 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) await ctlg_consul(args.node, consul(), console.log, aggr.next().value)
] ]

View file

@ -1,5 +1,5 @@
{ {
"name": "consul-to-igd", "name": "netiquette",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.mjs", "main": "index.mjs",

View file

@ -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")
}