fix: no more support for WS2P
This commit is contained in:
@@ -15,14 +15,15 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^5.13.0",
|
"@fortawesome/fontawesome-free": "^5.13.0",
|
||||||
|
"@types/moment": "^2.13.0",
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"bootstrap": "^4.4.1",
|
"bootstrap": "^4.4.1",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"diff": "^4.0.1",
|
"diff": "^4.0.1",
|
||||||
"duniter": "^1.8.0",
|
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"js-yaml": "^3.12.1",
|
"js-yaml": "^3.12.1",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"nodemailer": "^6.2.1",
|
"nodemailer": "^6.2.1",
|
||||||
"pug": "^2.0.4",
|
"pug": "^2.0.4",
|
||||||
"typescript": "^3.4.3",
|
"typescript": "^3.4.3",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {Conf} from './types/conf'
|
import {Conf} from './types/conf'
|
||||||
import * as yaml from 'js-yaml';
|
import * as yaml from 'js-yaml';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {ws2pWatcher} from "./watchers/ws2p/ws2p-watcher";
|
|
||||||
import {bmaWatcher} from "./watchers/bma/bma-watcher";
|
import {bmaWatcher} from "./watchers/bma/bma-watcher";
|
||||||
import {dprobeHeartbeat} from './watchers/dprobe/dprobe-heartbeat-watcher'
|
import {dprobeHeartbeat} from './watchers/dprobe/dprobe-heartbeat-watcher'
|
||||||
import {webDiffWatcher} from "./watchers/webdiff/webdiff-watcher";
|
import {webDiffWatcher} from "./watchers/webdiff/webdiff-watcher";
|
||||||
@@ -20,7 +19,6 @@ export async function dwatch(confFile: string) {
|
|||||||
initConfMail(conf.mail)
|
initConfMail(conf.mail)
|
||||||
const watchers: Watcher[] = [];
|
const watchers: Watcher[] = [];
|
||||||
(await Promise.all((conf.websocketServers || []).map(websocketWatcher(conf)))).forEach(w => watchers.push(w));
|
(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.bmaServers || []).map(bmaWatcher(conf)))).forEach(w => watchers.push(w));
|
||||||
(await Promise.all((conf.dprobeHeartbeats || []).map(dprobeHeartbeat(conf)))).forEach(w => watchers.push(w));
|
(await Promise.all((conf.dprobeHeartbeats || []).map(dprobeHeartbeat(conf)))).forEach(w => watchers.push(w));
|
||||||
(await Promise.all((conf.webDiffServers || []).map(webDiffWatcher(conf)))).forEach(w => watchers.push(w));
|
(await Promise.all((conf.webDiffServers || []).map(webDiffWatcher(conf)))).forEach(w => watchers.push(w));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {moment} from "duniter/app/lib/common-libs/moment";
|
|
||||||
import {ConfMail} from "./types/conf";
|
import {ConfMail} from "./types/conf";
|
||||||
import * as nodemailer from 'nodemailer'
|
import * as nodemailer from 'nodemailer'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
|
import * as moment from 'moment'
|
||||||
|
|
||||||
const DEFAULT_FREQUENCY = 5 * 60 * 1000 // 5'
|
const DEFAULT_FREQUENCY = 5 * 60 * 1000 // 5'
|
||||||
const queue: MailContent[] = []
|
const queue: MailContent[] = []
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {Conf, ConfBMA} from "../../types/conf";
|
import {Conf, ConfBMA} from "../../types/conf";
|
||||||
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
||||||
import {moment} from 'duniter/app/lib/common-libs/moment'
|
import * as moment from 'moment'
|
||||||
|
|
||||||
export function bmaWatcher(conf: Conf) {
|
export function bmaWatcher(conf: Conf) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {Conf, ConfCertifications, ConfMembership} from "../../types/conf";
|
import {Conf, ConfCertifications, ConfMembership} from "../../types/conf";
|
||||||
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
||||||
import {moment} from "duniter/app/lib/common-libs/moment";
|
|
||||||
|
|
||||||
export function certificationsWatcher(conf: Conf) {
|
export function certificationsWatcher(conf: Conf) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {Conf, ConfHead} from "../../types/conf";
|
import {Conf, ConfHead} from "../../types/conf";
|
||||||
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
||||||
import {WS2PHead} from "duniter/app/modules/ws2p/lib/WS2PCluster";
|
|
||||||
|
|
||||||
function handleLateness(confHead: ConfHead, mainHeads: HeadMetric[], observedHead?: TrameWS2P): UrlWatcherResult {
|
function handleLateness(confHead: ConfHead, mainHeads: HeadMetric[], observedHead?: TrameWS2P): UrlWatcherResult {
|
||||||
if (!mainHeads.length) {
|
if (!mainHeads.length) {
|
||||||
@@ -28,7 +27,7 @@ export function headWatcher(conf: Conf) {
|
|||||||
return async (confHead: ConfHead) => {
|
return async (confHead: ConfHead) => {
|
||||||
|
|
||||||
return urlWatcher(conf, async (data) => {
|
return urlWatcher(conf, async (data) => {
|
||||||
const heads = data as { heads: WS2PHead[] }
|
const heads = data as { heads: any[] }
|
||||||
const mainHeads = getMain(heads)
|
const mainHeads = getMain(heads)
|
||||||
const observedHead = getObserved(heads, confHead.observedPubkey)
|
const observedHead = getObserved(heads, confHead.observedPubkey)
|
||||||
return handleLateness(confHead, mainHeads, observedHead)
|
return handleLateness(confHead, mainHeads, observedHead)
|
||||||
@@ -43,7 +42,7 @@ export function headWatcher(conf: Conf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMain(heads: { heads: WS2PHead[] }): HeadMetric[] {
|
function getMain(heads: { heads: any[] }): HeadMetric[] {
|
||||||
const mapByHash: { [k: string]: HeadMetric } = {}
|
const mapByHash: { [k: string]: HeadMetric } = {}
|
||||||
for (const head of heads.heads) {
|
for (const head of heads.heads) {
|
||||||
const trame = getTrame(head)
|
const trame = getTrame(head)
|
||||||
@@ -69,7 +68,7 @@ function getMain(heads: { heads: WS2PHead[] }): HeadMetric[] {
|
|||||||
}, [] as HeadMetric[])
|
}, [] as HeadMetric[])
|
||||||
}
|
}
|
||||||
|
|
||||||
function getObserved(heads: { heads: WS2PHead[] }, observedPubkey: string): TrameWS2P|undefined {
|
function getObserved(heads: { heads: any[] }, observedPubkey: string): TrameWS2P|undefined {
|
||||||
const trame = heads.heads
|
const trame = heads.heads
|
||||||
.map(getTrame)
|
.map(getTrame)
|
||||||
.filter(trame => trame && trame.pubkey === observedPubkey)[0]
|
.filter(trame => trame && trame.pubkey === observedPubkey)[0]
|
||||||
@@ -79,7 +78,7 @@ function getObserved(heads: { heads: WS2PHead[] }, observedPubkey: string): Tram
|
|||||||
return trame
|
return trame
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTrame(head: WS2PHead): TrameWS2P|undefined {
|
function getTrame(head: any): TrameWS2P|undefined {
|
||||||
if (head.messageV2) {
|
if (head.messageV2) {
|
||||||
const [ protocol, type, trameVersion, pubkey, blockstamp, peerUuid, software, softVersion, n1, n2, n3 ] = head.messageV2.split(':')
|
const [ protocol, type, trameVersion, pubkey, blockstamp, peerUuid, software, softVersion, n1, n2, n3 ] = head.messageV2.split(':')
|
||||||
const [ blockNumber, blockHash ] = blockstamp.split('-')
|
const [ blockNumber, blockHash ] = blockstamp.split('-')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {Conf, ConfDprobeHeartbeat} from "../../types/conf";
|
import {Conf, ConfDprobeHeartbeat} from "../../types/conf";
|
||||||
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
||||||
import {moment} from 'duniter/app/lib/common-libs/moment'
|
import * as moment from 'moment'
|
||||||
|
|
||||||
export function dprobeHeartbeat(conf: Conf) {
|
export function dprobeHeartbeat(conf: Conf) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {Conf, ConfWWMeta} from "../../types/conf";
|
import {Conf, ConfWWMeta} from "../../types/conf";
|
||||||
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
||||||
import {moment} from "duniter/app/lib/common-libs/moment";
|
import * as moment from 'moment'
|
||||||
|
|
||||||
function handleLateness(confHead: ConfWWMeta, data: WWMetaJson) {
|
function handleLateness(confHead: ConfWWMeta, data: WWMetaJson) {
|
||||||
const diff = Math.round(Date.now()/1000 - data.now)
|
const diff = Math.round(Date.now()/1000 - data.now)
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import {WS2PMessageHandler} from 'duniter/app/modules/ws2p/lib/impl/WS2PMessageHandler'
|
|
||||||
import {WS2PConnection} from 'duniter/app/modules/ws2p/lib/WS2PConnection'
|
|
||||||
import {WS2PResponse} from 'duniter/app/modules/ws2p/lib/impl/WS2PResponse'
|
|
||||||
import {NewLogger} from 'duniter/app/lib/logger'
|
|
||||||
|
|
||||||
export class MessageHandler implements WS2PMessageHandler {
|
|
||||||
|
|
||||||
async answerToRequest(json: any, c: WS2PConnection): Promise<WS2PResponse> {
|
|
||||||
NewLogger().info('Request from %s = %s', c.pubkey, JSON.stringify(json))
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* THAT'S THE CORE OF DWATCHER: tracing push messages
|
|
||||||
*/
|
|
||||||
async handlePushMessage(json: any, c: WS2PConnection): Promise<void> {
|
|
||||||
NewLogger().info('Push from %s = %s', c.pubkey, JSON.stringify(json))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import {WS2PConnection, WS2PPubkeyLocalAuth, WS2PPubkeyRemoteAuth} from "duniter/app/modules/ws2p/lib/WS2PConnection";
|
|
||||||
import {watcherLoop} from "../../watcherLoop";
|
|
||||||
import {MessageHandler} from "./message-handler";
|
|
||||||
import {Conf, ConfWS2P} from "../../types/conf";
|
|
||||||
import {Scrypt} from "duniter/app/modules/keypair/lib/scrypt";
|
|
||||||
import {Key} from "duniter/app/lib/common-libs/crypto/keyring";
|
|
||||||
import {mail} from "../../mail";
|
|
||||||
|
|
||||||
export function ws2pWatcher(conf: Conf) {
|
|
||||||
|
|
||||||
let c: WS2PConnection
|
|
||||||
|
|
||||||
return async (wserver: ConfWS2P) => {
|
|
||||||
|
|
||||||
const keys = await Scrypt(wserver.salt, wserver.passwd)
|
|
||||||
const keypair = new Key(keys.pub, keys.sec)
|
|
||||||
const target = `${wserver.address} (${wserver.expectedPubkey.substr(0, 8)})`
|
|
||||||
|
|
||||||
return watcherLoop(
|
|
||||||
`WS2P ${wserver.address} (${wserver.name})`,
|
|
||||||
async () => {
|
|
||||||
|
|
||||||
const localAuth = new WS2PPubkeyLocalAuth(wserver.currency, keypair, "", async () => true)
|
|
||||||
const remoteAuth = new WS2PPubkeyRemoteAuth(wserver.currency, keypair, async () => true)
|
|
||||||
|
|
||||||
c = WS2PConnection.newConnectionToAddress(
|
|
||||||
1,
|
|
||||||
wserver.address,
|
|
||||||
new MessageHandler(),
|
|
||||||
localAuth,
|
|
||||||
remoteAuth,
|
|
||||||
undefined,
|
|
||||||
{
|
|
||||||
connectionTimeout: conf.connectionTimeout,
|
|
||||||
requestTimeout: 0 // No request anyway
|
|
||||||
},
|
|
||||||
wserver.expectedPubkey
|
|
||||||
)
|
|
||||||
|
|
||||||
await c.connectAsInitiator()
|
|
||||||
},
|
|
||||||
() => c.closed,
|
|
||||||
|
|
||||||
conf.waitingDelay,
|
|
||||||
conf.recallDelay,
|
|
||||||
|
|
||||||
mail.onEstablished(target, () => `State OK WS2P on ${wserver.address}`),
|
|
||||||
|
|
||||||
// When a disconnection is detected
|
|
||||||
mail.onDisconnect(target, () => `State FAILURE WS2P on ${wserver.address}`),
|
|
||||||
|
|
||||||
async () => {
|
|
||||||
console.log('Trying to connect to %s', target)
|
|
||||||
},
|
|
||||||
|
|
||||||
mail.onRestartSuccess(target, () => `State RECOVERED WS2P on ${wserver.address}`),
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user