forked from Deuxfleurs/infrastructure
WIP netiquette
This commit is contained in:
parent
0b3eb8ec1b
commit
fcc2328a3b
15 changed files with 20 additions and 5 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
# netiquette
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install
|
npm install
|
||||||
npm test
|
npm test
|
|
@ -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)
|
||||||
]
|
]
|
||||||
|
|
|
@ -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",
|
10
docker/netiquette/src/catalog/control_loop.mjs
Normal file
10
docker/netiquette/src/catalog/control_loop.mjs
Normal 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")
|
||||||
|
}
|
Loading…
Reference in a new issue