Skip to content

Commit

Permalink
more stable queues
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jul 25, 2024
1 parent 0fd0f54 commit 11db0e4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
14 changes: 4 additions & 10 deletions apps/trawler/src/sanitizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* @returns Filtered and deduped list of relays
*/

import isLocal from "url-local"

import lmdb from './relaydb.js'
import Logger from '@nostrwatch/logger'
import isLocal from "url-local"

const logger = new Logger('sanitizers')

const BLOCK_HOSTNAMES = [];

export const normalizeRelays = (relays) => {
return relays
.map( sanitizeRelayUrl )
Expand All @@ -33,11 +33,6 @@ export const sanitizeRelayList = (relays) => {
return relays
}

export const relayAlreadyKnown = async (relay) => {
if(await lmdb.relay.exists(relay))
return false
}

export const qualifyRelayUrl = (relay) => {
if(isLocal(relay))
return false
Expand Down Expand Up @@ -79,6 +74,7 @@ const normalizeRelayUrl = (relay) => {
try {
const url = new URL(relay)
url.hash = ''
url.search = ''
return url.toString()
}
catch(e) {
Expand All @@ -102,7 +98,6 @@ export const sanitizeRelayUrl = (relay) => {
}
}


export const relaysFilterInvalid = (relays) => {
let invalids = 0;
const re = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
Expand All @@ -128,7 +123,6 @@ export const relaysFilterInvalid = (relays) => {
return validRelays;
}


export const relaysFilterDuplicates = (relays) => {
const hostnameMap = new Map();
return relays.filter(url => {
Expand Down
6 changes: 3 additions & 3 deletions internal/controlflow/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { SyncQueue, TrawlQueue, NocapdQueue, RestApiQueue, QueueInit, BullMQ } from './src/queues.js'
export { Scheduler } from './src/scheduler.js'
export { RetryManager } from './src/retry.js'
export * from './src/queues.js'
export * from './src/scheduler.js'
export * from './src/retry.js'
5 changes: 5 additions & 0 deletions internal/controlflow/src/queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const TrawlQueue = (qopts={}) => {
return QueueInit('TrawlQueue', qopts)
}

export const LivenessQueue = (qopts={}) => {
return QueueInit('LivenessQueue', qopts)
}

export const NocapdQueue = (name=null, qopts={}) => {
name = name? name: 'NocapdQueue'
return QueueInit(name, qopts)
Expand Down Expand Up @@ -45,6 +49,7 @@ export const BullMQ = {
export default {
SyncQueue,
TrawlQueue,
LivenessQueue,
NocapdQueue,
RestApiQueue,
QueueInit,
Expand Down
1 change: 1 addition & 0 deletions internal/redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bullboard.js
22 changes: 22 additions & 0 deletions libraries/nocap/src/classes/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,5 +1162,27 @@ export default class Base {
static checksSupported() {
return ['open', 'read', 'write', 'ssl', 'dns', 'geo', 'info'];
}

/**
* translateCheckKeys
* Translates check key shortcuts and synonyms to internal keys.
*
* @public
* @static
* @param {string[]} checks - The array of checks to translate
*/
static translateCheckKeys(checks) {
const translation = {
'rtt' : ['open', 'read', 'write'],
'nip11': ['info']
}
const translated = []
checks.forEach(check => {
if(translation?.[check])
return translated.push(...translation[check]);
translated.push(check)
})
return Array.from(new Set(translated))
}
}

0 comments on commit 11db0e4

Please sign in to comment.