feature: surveillance GDEV via WebSocket
This commit is contained in:
28
app.yml
28
app.yml
@@ -1,16 +1,20 @@
|
||||
connectionTimeout: 10000 # 10"
|
||||
waitingDelay: 5000 # 5"
|
||||
recallDelay: 60000
|
||||
websocketServers:
|
||||
- name: cgeek V2S
|
||||
address: wss://gdev.cgeek.fr
|
||||
|
||||
ws2pServers:
|
||||
- address: ws://g1-test.cgeek.fr:22001
|
||||
expectedPubkey: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj
|
||||
salt: test
|
||||
passwd: test
|
||||
currency: g1-test # Ensure we connect to the correct currency
|
||||
# - address: ws://g1-test.cgeek.fr:22001
|
||||
# expectedPubkey: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj
|
||||
# salt: test
|
||||
# passwd: test
|
||||
# currency: g1-test # Ensure we connect to the correct currency
|
||||
|
||||
bmaServers:
|
||||
- address: https://g1-test.cgeek.fr
|
||||
frequency: 60000 # 1'
|
||||
# - address: https://g1-test.cgeek.fr
|
||||
# frequency: 60000 # 1'
|
||||
# - address: http://remuniter.cgeek.fr:16120
|
||||
# frequency: 60000 # 1'
|
||||
# maxLate: 14400000 # 4h'
|
||||
@@ -26,10 +30,10 @@ webDiffServers:
|
||||
# frequency: 60000
|
||||
|
||||
headServers:
|
||||
- address: https://g1.cgeek.fr
|
||||
frequency: 60000 # 1'
|
||||
maxLateBlocks: 3
|
||||
observedPubkey: A5LQXCkx8b6rzppfqdqeHbKPDGmKZtRcqwxP4BSeag5r
|
||||
# - address: https://g1.cgeek.fr
|
||||
# frequency: 60000 # 1'
|
||||
# maxLateBlocks: 3
|
||||
# observedPubkey: A5LQXCkx8b6rzppfqdqeHbKPDGmKZtRcqwxP4BSeag5r
|
||||
|
||||
wwMeta:
|
||||
# - address: https://wot-wizard.duniter.org
|
||||
@@ -41,7 +45,7 @@ memberships:
|
||||
# - {address: https://g1.cgeek.fr, currency: ğ1, frequency: 86400, mustRemain: 7776000, pubkey: 2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ, memberAlias: cgeek}
|
||||
# - {address: https://g1.cgeek.fr, currency: ğ1, frequency: 86400, mustRemain: 7776000, pubkey: 4GdKJq2LqV1rrCkixUoSpg4w5Abz41knU4h9eov2R3QU, memberAlias: Audrey35}
|
||||
# Tous les 1j ==> 1 mois de prévenance
|
||||
- {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 2592000, pubkey: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj, memberAlias: cgeek}
|
||||
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 2592000, pubkey: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj, memberAlias: cgeek}
|
||||
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 2592000, pubkey: 39YyHCMQNmXY7NkPCXXfzpV1vYct4GBxwgfyd4d72HmB, memberAlias: cgeek-4}
|
||||
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 7776000, pubkey: 36UhAqrkDx11ifN7WaBM6Q5bMUJxhKb1wJnnPFnkLkCF, memberAlias: cgeek-2} # Compte révoqué
|
||||
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 7776000, pubkey: 81jPYhcyruwKJ9Dy4Vz7MtmxiSdeESuJcvjPotxbCTgS, memberAlias: cgeek-3} # Compte révoqué
|
||||
|
||||
15593
package-lock.json
generated
Normal file
15593
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prepublish": "tsc",
|
||||
"build:w": "tsc --watch",
|
||||
"build": "tsc && NODE_ENV=production webpack --config webpack.prod.js",
|
||||
"build:front": "NODE_ENV=production webpack --config webpack.prod.js",
|
||||
"start": "webpack-dev-server --config webpack.dev.js --open",
|
||||
@@ -25,7 +26,8 @@
|
||||
"nodemailer": "^6.2.1",
|
||||
"pug": "^2.0.4",
|
||||
"typescript": "^3.4.3",
|
||||
"vue": "^2.6.11"
|
||||
"vue": "^2.6.11",
|
||||
"ws": "^8.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/axios": "^0.14.0",
|
||||
@@ -38,6 +40,7 @@
|
||||
"@types/node": "~8.9.4",
|
||||
"@types/nodemailer": "^6.1.1",
|
||||
"@types/pug": "^2.0.4",
|
||||
"@types/ws": "^8.5.3",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"css-loader": "^3.5.3",
|
||||
"file-loader": "^6.0.0",
|
||||
|
||||
@@ -10,6 +10,7 @@ import {headWatcher} from "./watchers/bma/head-watcher";
|
||||
import {jsonWatcher} from "./watchers/wotwizard/json-watcher";
|
||||
import {initConfMail} from './mail'
|
||||
import {membershipWatcher} from './watchers/bma/membership-watcher'
|
||||
import {websocketWatcher} from "./watchers/websocket/websocket-watcher";
|
||||
|
||||
export async function dwatch(confFile: string) {
|
||||
|
||||
@@ -17,6 +18,7 @@ export async function dwatch(confFile: string) {
|
||||
const conf = yaml.load(yml) as Conf
|
||||
initConfMail(conf.mail)
|
||||
const watchers: Watcher[] = [];
|
||||
(await Promise.all((conf.websocketServers || []).map(websocketWatcher(conf)))).forEach(w => watchers.push(w));
|
||||
(await Promise.all((conf.ws2pServers || []).map(ws2pWatcher(conf)))).forEach(w => watchers.push(w));
|
||||
(await Promise.all((conf.bmaServers || []).map(bmaWatcher(conf)))).forEach(w => watchers.push(w));
|
||||
(await Promise.all((conf.dprobeHeartbeats || []).map(dprobeHeartbeat(conf)))).forEach(w => watchers.push(w));
|
||||
|
||||
@@ -3,6 +3,7 @@ export interface Conf {
|
||||
waitingDelay: number
|
||||
recallDelay: number
|
||||
ws2pServers: ConfWS2P[]
|
||||
websocketServers: ConfWebSocket[]
|
||||
bmaServers: ConfBMA[]
|
||||
dprobeHeartbeats: ConfDprobeHeartbeat[]
|
||||
webDiffServers: ConfWebDiff[]
|
||||
@@ -12,6 +13,11 @@ export interface Conf {
|
||||
mail: ConfMail
|
||||
}
|
||||
|
||||
export interface ConfWebSocket {
|
||||
name: string
|
||||
address: string
|
||||
}
|
||||
|
||||
export interface ConfWS2P {
|
||||
address: string
|
||||
expectedPubkey: string
|
||||
|
||||
55
src/lib/watchers/websocket/websocket-watcher.ts
Normal file
55
src/lib/watchers/websocket/websocket-watcher.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import {watcherLoop} from "../../watcherLoop";
|
||||
import {Conf, ConfWebSocket} from "../../types/conf";
|
||||
import {mail} from "../../mail";
|
||||
import * as WebSocket from "ws"
|
||||
|
||||
export function websocketWatcher(conf: Conf) {
|
||||
|
||||
let c: WebSocket
|
||||
let closed: Promise<any>
|
||||
let closedCallback: () => any
|
||||
|
||||
return async (wserver: ConfWebSocket) => {
|
||||
|
||||
const target = `${wserver.address} (${wserver.name})`
|
||||
|
||||
return watcherLoop(
|
||||
`WebSocket ${wserver.name}`,
|
||||
async () => {
|
||||
|
||||
c = new WebSocket(wserver.address)
|
||||
closed = new Promise(res => closedCallback = res)
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
c.onopen = () => {
|
||||
console.log('Connecté à ' + wserver.address)
|
||||
resolve()
|
||||
}
|
||||
c.onerror = (e: any) => {
|
||||
console.log('Erreur de connexion à ' + wserver.address + ' : ' + e.message)
|
||||
reject()
|
||||
}
|
||||
c.onclose = closedCallback
|
||||
})
|
||||
|
||||
console.log('Loop terminé WS')
|
||||
},
|
||||
() => closed,
|
||||
|
||||
conf.waitingDelay,
|
||||
conf.recallDelay,
|
||||
|
||||
mail.onEstablished(target, () => `State OK WebSocket on ${wserver.address}`),
|
||||
|
||||
// When a disconnection is detected
|
||||
mail.onDisconnect(target, () => `State FAILURE WebSocket on ${wserver.address}`),
|
||||
|
||||
async () => {
|
||||
console.log('Trying to connect to %s', target)
|
||||
},
|
||||
|
||||
mail.onRestartSuccess(target, () => `State RECOVERED WebSocket on ${wserver.address}`),
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user