commit 32a1a24e399a1fe9cce880aae46f24a443158a6a
parent 72676623307990cd81a24f1dacc34fd124bb5ebe
Author: William Casarin <jb55@jb55.com>
Date: Tue, 9 May 2023 18:42:59 -0700
pool: skip ephemeral relays by default
Also filter relays by read/write once we introduce that
Diffstat:
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift
@@ -180,10 +180,22 @@ class RelayPool {
request_queue.append(QueuedRequest(req: r, relay: relay))
}
- func send(_ req: NostrRequest, to: [String]? = nil) {
+ func send(_ req: NostrRequest, to: [String]? = nil, skip_ephemeral: Bool = true) {
let relays = to.map{ get_relays($0) } ?? self.relays
for relay in relays {
+ if req.is_read && !relay.descriptor.info.read {
+ continue
+ }
+
+ if req.is_write && !relay.descriptor.info.write {
+ continue
+ }
+
+ if relay.descriptor.info.ephemeral && skip_ephemeral {
+ continue
+ }
+
guard relay.connection.isConnected else {
queue_req(r: req, relay: relay.id)
continue
@@ -194,6 +206,7 @@ class RelayPool {
}
func get_relays(_ ids: [String]) -> [Relay] {
+ // don't include ephemeral relays in the default list to query
relays.filter { ids.contains($0.id) }
}