Warn when trying to connect to bad urls
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {Emitter} from '@welshman/lib'
|
||||
import {normalizeRelayUrl} from '@welshman/util'
|
||||
import {Socket} from './Socket'
|
||||
import type {Message} from './Socket'
|
||||
import {ConnectionEvent} from './ConnectionEvent'
|
||||
@@ -27,6 +28,10 @@ export class Connection extends Emitter {
|
||||
constructor(url: string) {
|
||||
super()
|
||||
|
||||
if (url !== normalizeRelayUrl(url)) {
|
||||
console.warn(`Attempted to open connection to non-normalized url ${url}`)
|
||||
}
|
||||
|
||||
this.url = url
|
||||
this.socket = new Socket(this)
|
||||
this.sender = new ConnectionSender(this)
|
||||
|
||||
@@ -69,7 +69,7 @@ export class Socket {
|
||||
// Allow the socket to start closing before waiting
|
||||
await sleep(100)
|
||||
|
||||
// Wait for the socket to fully clos
|
||||
// Wait for the socket to fully close
|
||||
await this.wait()
|
||||
|
||||
this.ws = undefined
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {ctx, Emitter, max, chunk, randomId, once, groupBy, uniq} from '@welshman/lib'
|
||||
import {matchFilters, unionFilters, TrustedEvent} from '@welshman/util'
|
||||
import {LOCAL_RELAY_URL, matchFilters, normalizeRelayUrl, unionFilters, TrustedEvent} from '@welshman/util'
|
||||
import type {Filter} from '@welshman/util'
|
||||
import {Tracker} from "./Tracker"
|
||||
import {Connection} from './Connection'
|
||||
@@ -354,6 +354,12 @@ export type SubscribeRequestWithHandlers = SubscribeRequest & {
|
||||
export const subscribe = ({onEvent, onEose, onClose, onComplete, ...request}: SubscribeRequestWithHandlers) => {
|
||||
const sub: Subscription = makeSubscription({delay: 50, ...request})
|
||||
|
||||
for (const relay of request.relays) {
|
||||
if (relay !== LOCAL_RELAY_URL && relay !== normalizeRelayUrl(relay)) {
|
||||
console.warn(`Attempted to open subscription to non-normalized url ${relay}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (request.delay === 0) {
|
||||
executeSubscription(sub)
|
||||
} else {
|
||||
|
||||
@@ -6,9 +6,9 @@ import type {HashedEvent, TrustedEvent} from './Events'
|
||||
|
||||
// Constants and types
|
||||
|
||||
export const LOCAL_RELAY_URL = "local://welshman.relay"
|
||||
export const LOCAL_RELAY_URL = "local://welshman.relay/"
|
||||
|
||||
export const BOGUS_RELAY_URL = "bogus://welshman.relay"
|
||||
export const BOGUS_RELAY_URL = "bogus://welshman.relay/"
|
||||
|
||||
export type RelayProfile = {
|
||||
url: string
|
||||
|
||||
Reference in New Issue
Block a user