Fix crash when you have invalid relays in your relay list

Changelog-Fixed: Fix crash when you have invalid relays in your relay list
This commit is contained in:
William Casarin
2023-04-25 15:06:09 -07:00
parent 633fcd69a8
commit d074d092a2
13 changed files with 51 additions and 45 deletions

View File

@@ -242,7 +242,7 @@ func follow_with_existing_contacts(our_pubkey: String, our_contacts: NostrEvent,
func make_contact_relays(_ relays: [RelayDescriptor]) -> [String: RelayInfo] {
return relays.reduce(into: [:]) { acc, relay in
acc[relay.url.absoluteString] = relay.info
acc[relay.url.url.absoluteString] = relay.info
}
}

View File

@@ -809,7 +809,7 @@ func load_our_relays(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
for d in diff {
changed = true
if new.contains(d) {
if let url = URL(string: d) {
if let url = RelayURL(d) {
add_new_relay(relay_filters: state.relay_filters, metadatas: state.relay_metadata, pool: state.pool, url: url, info: decoded[d] ?? .rw, new_relay_filters: new_relay_filters)
}
} else {
@@ -823,10 +823,10 @@ func load_our_relays(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
}
}
func add_new_relay(relay_filters: RelayFilters, metadatas: RelayMetadatas, pool: RelayPool, url: URL, info: RelayInfo, new_relay_filters: Bool) {
func add_new_relay(relay_filters: RelayFilters, metadatas: RelayMetadatas, pool: RelayPool, url: RelayURL, info: RelayInfo, new_relay_filters: Bool) {
try? pool.add_relay(url, info: info)
let relay_id = url.absoluteString
let relay_id = url.id
guard metadatas.lookup(relay_id: relay_id) == nil else {
return
}

View File

@@ -1,14 +0,0 @@
//
// LocalUserConfig.swift
// damus
//
// Created by William Casarin on 2022-06-15.
//
import Foundation
struct LocalUserConfig: Codable {
let relays: [RelayDescriptor]
}