Skip to content

Commit

Permalink
fix nip-01 incompatible websocket servers reporting online
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Mar 16, 2024
1 parent c6af92b commit 1b2395c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/nocapd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@nostrwatch/announce": "^0.0.7",
"@nostrwatch/controlflow": "^0.0.3",
"@nostrwatch/logger": "^0.0.4",
"@nostrwatch/nocap": "^0.2.4",
"@nostrwatch/nocap": "^0.3.0",
"@nostrwatch/nwcache": "^0.0.2",
"@nostrwatch/publisher": "^0.3.2",
"@nostrwatch/seed": "^0.0.1",
Expand Down
16 changes: 8 additions & 8 deletions apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class NWWorker {
catch(err) {
console.log(err)
failure(new Error(`Failure inside work() block: ${err}`))
return { result: false }
return { result: { url: job.data.relay, open: { data: false }} }
}
}

Expand Down Expand Up @@ -128,7 +128,9 @@ export class NWWorker {
this.log.debug(`after_completed(): ${result.url}`)
this.processed++
await this.updateRelayCache( { ...result } )
await delay(200)
await this.retry.setRetries( result.url, !error )
await delay(200)
await this.setLastChecked( result.url, Date.now() )
}

Expand All @@ -139,7 +141,7 @@ export class NWWorker {
}

cbcall(...args){
//this.log.debug(`cbcall(): ${args}`)
this.log.debug(`cbcall(): ${JSON.stringify(args)}`)
const handler = [].shift.call(args)
if(this?.[`on_${handler}`] && typeof this[`on_${handler}`] === 'function')
this[`on_${handler}`](...args)
Expand All @@ -148,32 +150,30 @@ export class NWWorker {
}

async addRelayJobs(relays){
//this.log.debug(`Relay Counts: ${JSON.stringify(await this.counts())}`)
this.log.debug(`Relay Counts: ${JSON.stringify(await this.counts())}`)
for await ( const relay of relays ){
const $job = await this.addRelayJob({ relay })
if($job?.id)
this.total++
}
const c = await this.counts()
//this.log.debug(`Relay Counts: ${JSON.stringify(c)}`)
}

async addRelayJob(jdata){
//this.log.debug(`Adding job for ${jdata.relay} with ${this.opts.checks.enabled} nocap checks: ${JSON.stringify(jdata)}`)
this.log.debug(`Adding job for ${jdata.relay} with ${this.opts.checks.enabled} nocap checks: ${JSON.stringify(jdata)}`)
const priority = this.getPriority(jdata.relay)
this.updateJobOpts({ priority })
return this.$.queue.add( this.id(), jdata, { jobId: this.jobId(jdata.relay), ...this.jobOpts})
}

calculateProgress() {
//this.log.debug(`calculateProgress()`)
this.log.debug(`calculateProgress()`)
if (this.total === 0) return "0.00%"; // Prevent division by zero
let percentage = (this.processed / this.total) * 100;
return percentage.toFixed(2) + "%";
}

async progressMessage(url, result={}, error=false){
//this.log.debug(`progressMessage()`)
this.log.debug(`progressMessage()`)
const failure = chalk.red;
const success = chalk.bold.green;
const mute = chalk.gray
Expand Down
1 change: 1 addition & 0 deletions apps/trawler/src/check-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ const setRetries = async ( url, online ) => {
// logger.info(url, 'is offline')
id = await rcache.retry.increment(retryId(url))
}
return id
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/nocap-every-adapter-default",
"version": "1.1.1",
"version": "1.2.0",
"type": "module",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,6 +9,6 @@
"@nostrwatch/nocap-geo-adapter-default": "^1.0.1",
"@nostrwatch/nocap-info-adapter-default": "^1.0.1",
"@nostrwatch/nocap-ssl-adapter-default": "^1.0.1",
"@nostrwatch/nocap-websocket-adapter-default": "^1.1.0"
"@nostrwatch/nocap-websocket-adapter-default": "^1.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/nocap-websocket-adapter-default",
"version": "1.1.0",
"version": "1.2.0",
"type": "module",
"main": "index.js",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/nocap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/nocap",
"version": "0.2.4",
"version": "0.3.0",
"main": "src/index.js",
"type": "module",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"dependencies": {
"@nostrwatch/logger": "^0.0.1",
"@nostrwatch/nocap-every-adapter-default": "^1.1.1",
"@nostrwatch/nocap-every-adapter-default": "^1.2.0",
"@nostrwatch/utils": "^0.0.1",
"fetch-h2": "3.0.2",
"get-ssl-certificate": "2.3.3",
Expand Down

0 comments on commit 1b2395c

Please sign in to comment.