From 1fe54380b898cf487926932cc9a18fc6282d1ae4 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 10 May 2023 13:24:46 -0700 Subject: [PATCH] relay: make RelayInfo encoding more flexible So that we don't fail relay list decoding as easy --- damus/Nostr/Relay.swift | 6 +++--- damus/Nostr/RelayPool.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/damus/Nostr/Relay.swift b/damus/Nostr/Relay.swift index 472f74d8..2aa159de 100644 --- a/damus/Nostr/Relay.swift +++ b/damus/Nostr/Relay.swift @@ -8,9 +8,9 @@ import Foundation public struct RelayInfo: Codable { - let read: Bool - let write: Bool - let ephemeral: Bool + let read: Bool? + let write: Bool? + let ephemeral: Bool? init(read: Bool, write: Bool, ephemeral: Bool = false) { self.read = read diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift index eec7dedf..20ab9490 100644 --- a/damus/Nostr/RelayPool.swift +++ b/damus/Nostr/RelayPool.swift @@ -43,7 +43,7 @@ class RelayPool { } var our_descriptors: [RelayDescriptor] { - return all_descriptors.filter { d in !d.info.ephemeral } + return all_descriptors.filter { d in !(d.info.ephemeral ?? false) } } var all_descriptors: [RelayDescriptor] { @@ -188,15 +188,15 @@ class RelayPool { let relays = to.map{ get_relays($0) } ?? self.relays for relay in relays { - if req.is_read && !relay.descriptor.info.read { + if req.is_read && !(relay.descriptor.info.read ?? true) { continue } - if req.is_write && !relay.descriptor.info.write { + if req.is_write && !(relay.descriptor.info.write ?? true) { continue } - if relay.descriptor.info.ephemeral && skip_ephemeral { + if (relay.descriptor.info.ephemeral ?? false) && skip_ephemeral { continue }