Skip to content

Commit

Permalink
fix missing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jul 27, 2024
1 parent 696917e commit 679ecb0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 46 deletions.
4 changes: 2 additions & 2 deletions apps/nocapd/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nostrwatch/nocapd",
"type": "module",
"version": "1.2.0",
"version": "1.2.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
Expand All @@ -12,7 +12,7 @@
"@nostrwatch/nocap": "0.5.3",
"@nostrwatch/nocap-every-adapter-default": "1.4.0",
"@nostrwatch/nwcache": "0.1.2",
"@nostrwatch/publisher": "0.5.5",
"@nostrwatch/publisher": "0.5.6",
"@nostrwatch/seed": "0.0.2",
"@nostrwatch/utils": "0.1.3",
"bluebird": "3.7.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 @@ -134,7 +134,7 @@ export class NWWorker {
if(this.hard_stop) return
this.log.debug(`on_success(): ${result.url}`)
const publish30166 = new Publish.Kind30166()
await publish30166.one( result ).catch(this.log.error)
await publish30166.one( result ).catch(this.log.error.bind(this.log))
}

async on_fail(result){
Expand Down
2 changes: 1 addition & 1 deletion internal/publisher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/publisher",
"version": "0.5.5",
"version": "0.5.6",
"type": "module",
"description": "Library for publishing nostr.watch relay status and publisher registration events",
"main": "index.js",
Expand Down
93 changes: 51 additions & 42 deletions internal/publisher/src/kinds/Kind30166.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export class Kind30166 extends PublisherNocap {
this.machine_readable = true
}

generateEvent(data){
generateEvent(check){
let content
const tags = Kind30166.generateTags(data)
const tags = Kind30166.generateTags(check)
try {
content = `${JSON.stringify(data?.info?.data)}`
content = `${JSON.stringify(check.content)}`
} catch (e) {
content = "{}"
this.logger.err(`generateEvent(): Error: ${e}`)
this.logger.info(data)
this.logger.info(check.content)
}
const event = {
...this.tpl(),
Expand All @@ -29,113 +29,122 @@ export class Kind30166 extends PublisherNocap {
return event
}

static generateTags(data){
const protocol = new URL(data.url).protocol
static generateTags(check){
const protocol = new URL(check.url).protocol

const info = check?.info?.data || {}
const geo = check?.geo?.data || {}
const ssl = check?.ssl?.data || {}
const dns = check?.dns?.data || {}

const open = check?.open?.duration
const read = check?.read?.duration
const write = check?.write?.duration

let tags = []

tags.push(['d', data.url])
tags.push(['d', check.url])

if( data?.open?.data ){
tags.push(['rtt-open', String(data?.open?.duration)])
if( open ){
tags.push(['rtt-open', String(open)])
}

if( data?.read?.data ){
tags.push(['rtt-read', String(data?.read?.duration)])
if( read ){
tags.push(['rtt-read', String(read)])
}

if( data?.write?.data ){
tags.push(['rtt-write', String(data?.write?.duration)])
if( write ){
tags.push(['rtt-write', String(write)])
}

if (data?.network){
tags.push(['n', data.network])
if (check?.network){
tags.push(['n', check.network])
}

if (data?.info){
if (data?.info?.data?.pubkey && typeof data?.info?.data?.pubkey === 'string'){
tags.push(['p', data.info.data.pubkey])
if (info){
if (info?.pubkey && typeof info?.pubkey === 'string'){
tags.push(['p', info.pubkey])
}

for(const nip in data.info.data.supported_nips){
for(const nip in info.supported_nips){
tags.push(['N', String(nip)])
}

for(const lang in data.info.data.language_tags){
for(const lang in info.language_tags){
//TODO: validate language tags, attempt transform on invalids.
tags.push(['L', 'ISO-639-1'])
tags.push(['l', String(lang), 'ISO-639-1'])
}

for(const tag in data.info.data.tags){
for(const tag in info.tags){
tags.push(['t', String(tag)])
}

if (data?.info?.data?.limitation?.auth_required === true){
if (info?.limitation?.auth_required === true){
tags.push(['R', 'auth'])
}
else {
tags.push(['R', '!auth'])
}

if (data?.info?.data?.limitation?.payment_required === true){
if (info?.limitation?.payment_required === true){
tags.push(['R', 'payment'])
}
else {
tags.push(['R', '!payment'])
}

if (data?.info?.data?.software){
tags.push(['s', data.info.data.software])
if (info?.software){
tags.push(['s', info.software])
}

if (data?.info?.data?.version ){
if (info?.version ){
tags.push(['L', 'nip11.version'])
tags.push(['l', data.info.data.version, 'nip11.version'])
tags.push(['l', info.version, 'nip11.version'])
}
}

if (data?.ssl && protocol === 'wss:') {
const validFrom = new Date(data.ssl.data.valid_from).getTime()
const validTo = new Date(data.ssl.data.valid_to).getTime()
if (ssl && protocol === 'wss:') {
const validFrom = new Date(ssl.valid_from).getTime()
const validTo = new Date(ssl.valid_to).getTime()
const current = validFrom < Date.now() && validTo > Date.now()
tags.push(['R', current ? 'ssl' : '!ssl'])
}
else if(protocol !== 'wss:') {
tags.push(['R', '!ssl'])
}

if (data?.dns?.data?.ipv4?.length){
if (dns?.ipv4?.length){
tags.push(['L', 'dns.ipv4'])
for(const ipv4 of data.dns.data.ipv4){
for(const ipv4 of dns.ipv4){
tags.push(['l', ipv4, 'dns.ipv4'])
}
}

if (data?.dns?.data?.ipv6?.length){
if (dns?.ipv6?.length){
tags.push(['L', 'dns.ipv6'])
for(const ipv6 of data.dns.data.ipv6){
for(const ipv6 of dns.ipv6){
tags.push(['l', ipv6, 'dns.ipv6'])
}
}

if (data?.geo?.isp){
if (geo?.isp){
tags.push(['L', 'host.isp'])
tags.push(['l', data.dns?.data?.isp, 'host.isp'])
tags.push(['l', geo.isp, 'host.isp'])
}

if (data?.geo?.as){
if (geo?.as){
tags.push(['L', 'host.as'])
tags.push(['l', data.geo?.data?.as, 'host.as'])
tags.push(['l', geo.as, 'host.as'])
}

if (data?.geo?.asn){
if (geo?.asname){
tags.push(['L', 'host.asn'])
tags.push(['l', data.geo?.data?.asname, 'host.asn'])
tags.push(['l', geo.asname, 'host.asn'])
}

if(data?.geo?.data && data.geo.data instanceof Object)
tags = [...tags, ...ngeotags(data.geo.data, {isoAsNamespace: false})];
if(geo && geo instanceof Object)
tags = [...tags, ...ngeotags(geo, {isoAsNamespace: false})];

tags.push(['l', 'draft7', 'nip66.draft'])

Expand Down

0 comments on commit 679ecb0

Please sign in to comment.