commit 1367be0d10dc5224c14ed88e906ef5e05bcdb4d4
parent 32a1a24e399a1fe9cce880aae46f24a443158a6a
Author: William Casarin <jb55@jb55.com>
Date: Tue, 9 May 2023 18:41:06 -0700
relay: handle ephemeral relays in PostBox
We need to make sure ephemeral relay events (not ephemeral events) are
handled properly in the postbox. Make sure we pass the proper
skip_ephemeral flag to the relay pool if we add something like a NWC
event to the PostBox. Events are not sent to ephemeral relays by
default.
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/damus/Util/PostBox.swift b/damus/Util/PostBox.swift
@@ -24,10 +24,12 @@ class Relayer {
class PostedEvent {
let event: NostrEvent
+ let skip_ephemeral: Bool
var remaining: [Relayer]
- init(event: NostrEvent, remaining: [String]) {
+ init(event: NostrEvent, remaining: [String], skip_ephemeral: Bool) {
self.event = event
+ self.skip_ephemeral = skip_ephemeral
self.remaining = remaining.map {
Relayer(relay: $0, attempts: 0, retry_after: 2.0)
}
@@ -93,19 +95,18 @@ class PostBox {
relayer.attempts += 1
relayer.last_attempt = Int64(Date().timeIntervalSince1970)
relayer.retry_after *= 1.5
- pool.send(.event(event.event), to: [relayer.relay])
+ pool.send(.event(event.event), to: [relayer.relay], skip_ephemeral: event.skip_ephemeral)
}
}
- func send(_ event: NostrEvent) {
+ func send(_ event: NostrEvent, to: [String]? = nil, skip_ephemeral: Bool = true) {
// Don't add event if we already have it
if events[event.id] != nil {
return
}
- let remaining = pool.descriptors.map { $0.url.id }
-
- let posted_ev = PostedEvent(event: event, remaining: remaining)
+ let remaining = to ?? pool.descriptors.map { $0.url.id }
+ let posted_ev = PostedEvent(event: event, remaining: remaining, skip_ephemeral: skip_ephemeral)
events[event.id] = posted_ev
flush_event(posted_ev)