Normalize tor urls to use ws://
This commit is contained in:
@@ -231,6 +231,7 @@ export type RouterScenarioOptions = {
|
||||
limit?: number
|
||||
allowLocal?: boolean
|
||||
allowOnion?: boolean
|
||||
allowInsecure?: boolean
|
||||
}
|
||||
|
||||
export class RouterScenario {
|
||||
@@ -265,6 +266,8 @@ export class RouterScenario {
|
||||
|
||||
allowOnion = (allowOnion: boolean) => this.clone({allowOnion})
|
||||
|
||||
allowInsecure = (allowInsecure: boolean) => this.clone({allowInsecure})
|
||||
|
||||
weight = (scale: number) =>
|
||||
this.update(selection => ({...selection, weight: selection.weight * scale}))
|
||||
|
||||
@@ -276,12 +279,14 @@ export class RouterScenario {
|
||||
const limit = this.getLimit()
|
||||
const fallbackPolicy = this.getPolicy()
|
||||
const relayWeights = new Map<string, number>()
|
||||
const {allowOnion, allowLocal, allowInsecure} = this.options
|
||||
|
||||
for (const {weight, relays} of this.selections) {
|
||||
for (const relay of relays) {
|
||||
if (!isRelayUrl(relay)) continue
|
||||
if (!this.options.allowOnion && isOnionUrl(relay)) continue
|
||||
if (!this.options.allowLocal && isLocalUrl(relay)) continue
|
||||
if (!allowOnion && isOnionUrl(relay)) continue
|
||||
if (!allowLocal && isLocalUrl(relay)) continue
|
||||
if (!allowInsecure && relay.startsWith("ws://") && !isOnionUrl(relay)) continue
|
||||
|
||||
relayWeights.set(relay, add(weight, relayWeights.get(relay)))
|
||||
}
|
||||
|
||||
@@ -1102,7 +1102,9 @@ export const fetchJson = async (url: string, opts: FetchOpts = {}) => {
|
||||
opts.headers = {}
|
||||
}
|
||||
|
||||
opts.headers["Accept"] = "application/json"
|
||||
if (!opts.headers["Accept"]) {
|
||||
opts.headers["Accept"] = "application/json"
|
||||
}
|
||||
|
||||
const res = await fetch(url, opts as RequestInit)
|
||||
const json = await res.json()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/util",
|
||||
"version": "0.0.56",
|
||||
"version": "0.0.57",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of nostr-related utilities.",
|
||||
|
||||
@@ -62,7 +62,7 @@ export const isIPAddress = (url: string) => Boolean(url.match(/\d+\.\d+\.\d+\.\d
|
||||
export const isShareableRelayUrl = (url: string) => Boolean(isRelayUrl(url) && !isLocalUrl(url))
|
||||
|
||||
export const normalizeRelayUrl = (url: string) => {
|
||||
const prefix = url.match(/^wss?:\/\//)?.[0] || "wss://"
|
||||
const prefix = url.match(/^wss?:\/\//)?.[0] || (isOnionUrl(url) ? "ws://" : "wss://")
|
||||
|
||||
// Use our library to normalize
|
||||
url = normalizeUrl(url, {stripHash: true, stripAuthentication: false})
|
||||
|
||||
Reference in New Issue
Block a user