[enh] generalise dwatcher (not only WS2P)
This commit is contained in:
@@ -18,13 +18,15 @@ export async function dwatch(confFile: string) {
|
||||
|
||||
await Promise.all(conf.ws2pServers.map(async wserver => {
|
||||
|
||||
let c: WS2PConnection
|
||||
|
||||
await processHandler(
|
||||
() => {
|
||||
async () => {
|
||||
|
||||
const localAuth = new WS2PPubkeyLocalAuth(conf.currency, keypair, "", async () => true)
|
||||
const remoteAuth = new WS2PPubkeyRemoteAuth(conf.currency, keypair, async () => true)
|
||||
|
||||
return WS2PConnection.newConnectionToAddress(
|
||||
c = WS2PConnection.newConnectionToAddress(
|
||||
1,
|
||||
wserver.address,
|
||||
new MessageHandler(),
|
||||
@@ -37,11 +39,15 @@ export async function dwatch(confFile: string) {
|
||||
},
|
||||
wserver.expectedKey
|
||||
)
|
||||
|
||||
await c.connectAsInitiator()
|
||||
},
|
||||
|
||||
() => c.closed,
|
||||
|
||||
conf.reconnectionDelays,
|
||||
|
||||
async (c: WS2PConnection) => {
|
||||
async () => {
|
||||
console.log('Connection established')
|
||||
await sendMail(conf.mail, '[dwatcher] Connection established', `
|
||||
<p>
|
||||
@@ -51,7 +57,7 @@ export async function dwatch(confFile: string) {
|
||||
},
|
||||
|
||||
// When a disconnection is detected
|
||||
async (c: WS2PConnection, waitingDelay) => {
|
||||
async (waitingDelay) => {
|
||||
console.log('Connection closed')
|
||||
console.log('Waiting %s seconds...', waitingDelay)
|
||||
await sendMail(conf.mail, '[dwatcher] Connection closed', `
|
||||
@@ -64,11 +70,11 @@ export async function dwatch(confFile: string) {
|
||||
`)
|
||||
},
|
||||
|
||||
async (c: WS2PConnection) => {
|
||||
async () => {
|
||||
console.log('Trying to connect to %s', c.pubkey)
|
||||
},
|
||||
|
||||
async (c: WS2PConnection) => {
|
||||
async () => {
|
||||
console.log('Connection recovered')
|
||||
await sendMail(conf.mail, '[dwatcher] Connection recovered', `
|
||||
<p>
|
||||
@@ -83,4 +89,4 @@ export async function dwatch(confFile: string) {
|
||||
)
|
||||
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user