Skip to content

Commit

Permalink
fix nip-11 for non-wss endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jul 23, 2024
1 parent ccf6ce9 commit a14ec88
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/nocapd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@nostrwatch/controlflow": "0.2.1",
"@nostrwatch/logger": "0.0.6",
"@nostrwatch/nocap": "0.5.2",
"@nostrwatch/nocap-every-adapter-default": "1.3.2",
"@nostrwatch/nocap-every-adapter-default": "1.4.0",
"@nostrwatch/nwcache": "0.1.2",
"@nostrwatch/publisher": "0.4.3",
"@nostrwatch/seed": "0.0.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class NWWorker {
const failure = (err) => { this.log.err(`Could not run ${this.pubkey} check for ${job.data.relay}: ${err.message}`) }
try {
const { relay:url } = job.data
const nocap = new Nocap(url, this.nocapOpts)
const nocap = new Nocap(url, {...this.nocapOpts, logLevel: 'debug'})
await nocap.useAdapters([...adaptersArray])
const result = await nocap.check(this.opts.checks.enabled).catch(failure)
return { result }
Expand Down
7 changes: 4 additions & 3 deletions libraries/nocap/adapters/default/DnsAdapterDefault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class DnsAdapterDefault {
}
async check_dns(){
let result = {}, data = {}
if(this.$.results.get('network') !== 'clearnet')
return this.$.logger.debug('DNS check skipped for url not accessible over clearnet')
let err = false
if(this.$.results.get('network') !== 'clearnet') {
this.$.logger.debug('DNS check skipped for url not accessible over clearnet')
return { status: "error", message: "Relay is not clearnet, cannot check DNS." }
}
let Url = new URL(this.$.url)
let url = `${Url.protocol}//${Url.host}`.replace('wss://', '').replace('ws://', '').replace(/\/+$/, '');
const query = `https://1.1.1.1/dns-query?name=${url}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const IPV4 = /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01
}
else {
const iparr = this.$.results.get('dns')?.data?.ipv4
// console.log(iparr)
ip = iparr[iparr.length-1]
}
const apiKey = this.getApiKey();
Expand Down
34 changes: 25 additions & 9 deletions libraries/nocap/adapters/default/InfoAdapterDefault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,41 @@ class InfoAdapterDefault {

async check_info(){
let result, data = {}
const controller = new AbortController();
const { signal } = controller;
const url = new URL(this.$.url),
const controller = new AbortController(),
{ signal } = controller,
url = new URL(this.$.url),
headers = {"Accept": "application/nostr+json"},
method = 'GET'

url.protocol = 'https:'

// this.$.timeouts.create('info', this.$.config.timeout.info, () => controller.abort())
try {
if( this.$.results.get('network') === 'tor' )
{
url.protocol = 'onion:';
}
else if(url.protocol === 'ws:')
{
url.protocol = 'http:';
}
else if (url.protocol === 'wss:')
{
url.protocol = 'https:';
}

try
{
const response = await fetch(url.toString(), { method, headers, signal })
data = await response.json()
}
catch(e) {

catch(e)
{
result = { status: "error", message: e.message, data }
}

if(!result)
if(!result)
{
result = { status: "success", data }
}

// else {
// // const validate = this.ajv.compile(data)
// // const valid = validate(data)
Expand Down
16 changes: 11 additions & 5 deletions libraries/nocap/adapters/default/SslAdapterDefault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ class SslAdapterDefault {
}

async check_ssl(){

if(typeof window !== 'undefined') {
console.warn('Cannot check SSL from browser.');
return;
}

let result, data = {};
const url = new URL(this.$.url);
const hostname = url.hostname;
const timeout = this.$.config?.timeout.ssl || 1000;

if(url.protocol === 'ws:'){
return this.$.finish('ssl', { status: "error", message: "Cannot check SSL for unsecured websocket.", data: {} });
}

let sslCertificate, sslChecker;
try {
Expand All @@ -22,11 +32,7 @@ class SslAdapterDefault {
return;
}

let result, data = {};
const url = new URL(this.$.url);
const hostname = url.hostname;
const timeout = this.$.config?.timeout.ssl || 1000;


let sslCheckerResponse, sslCertificateResponse;
try {
// Call Node.js specific functions only if available
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nostrwatch/monorepo",
"private": true,
"version": "0.0.1",
"version": "0.2.0",
"scripts": {
"packages:update": "node ./scripts/upkg.js",
"deploy:nocapd@all": "ansible-playbook .ansible/nocapd/deploy.yaml -i .ansible/inventories/frankfurt -i .ansible/inventories/johannesburg -i .ansible/inventories/amsterdam -i .ansible/inventories/mumbai -i .ansible/inventories/newyork -i .ansible/inventories/saopaulo -i .ansible/inventories/seoul -i .ansible/inventories/siliconvalley -i .ansible/inventories/sydney",
Expand Down

0 comments on commit a14ec88

Please sign in to comment.