Skip to content

Commit

Permalink
fix sending of events for offline relays
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Feb 12, 2024
1 parent 4367603 commit 3b2eb7f
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export class NWWorker {

this.networks = opts?.networks? opts.networks: ['clearnet']

this.bindEvents = true

this.log = opts?.logger? opts.logger.logger: console

this.scheduler = opts?.scheduler? opts.scheduler.bind(this): () => { console.warn(`scheduler not defined for ${this.id}`) }
Expand All @@ -50,9 +48,7 @@ export class NWWorker {
throw new Error(`${this.slug}: on_completed needs to be defined and a function`)

this.log.info(`${this.id()} initialized`)

// this.stats = setInterval( async () => await this.counts(), 30*1000 )


this.delay = delay

this.processed = 0
Expand Down Expand Up @@ -107,9 +103,11 @@ export class NWWorker {
const { relay:url } = job.data
const { result } = rvalue

if(!result || result?.connect?.data !== true)
if(!result || !result?.connect?.data)
return this.on_failed(job, new Error(`Nocap.check('${this.slug}'): failed for ${url}`))

// console.log('PUBLISHING', url, result?.connect?.data, result?.read?.data, result?.write?.data)

const { checked_at } = result

const publish30066 = new Publish.Kind30066()
Expand Down Expand Up @@ -410,33 +408,4 @@ const evaluateMaxRelays = (evaluate, relays) => {
catch(e){
this.log.error(`Error evaluating config.nocapd.checks.all.max -> "${config.nocapd.checks.all.max}": ${e.message}`)
}
}

const eventDataFromResult = result => {
const events = []

const dns = result.dns?.data || {}
const info = result.info?.data || {}
const geo = transformGeoResult(result.geo?.data) || {}
const ssl = result.ssl?.data || {}
const rtt = { open: result.open.duration, read: result.read.duration, write: result.write.duration } || {}

const translated = {
url: result.url,
network: result.network,
isRtt: Object.keys(rtt)?.length > 0,
isDns: Object.keys(dns)?.length > 0,
isInfo: Object.keys(info)?.length > 0,
isGeo: Object.keys(geo)?.length > 0,
isSsl: Object.keys(ssl)?.length > 0,
rtt,
info,
dns,
geo,
ssl
}

const k30066 = ev30066(translated)
const k30166 = ev30166(translated)
return [ k30066, k30166 ]
}

0 comments on commit 3b2eb7f

Please sign in to comment.