wip some initial relay bootstrap logic

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-06-18 08:20:20 -07:00
parent 4da93b7630
commit 4cd48d3143
6 changed files with 73 additions and 11 deletions

View File

@@ -142,7 +142,7 @@ class HomeModel: ObservableObject {
self.loading = true
send_initial_filters(relay_id: relay_id)
} else {
self.loading = true
//remove_bootstrap_nodes(damus_state)
send_home_filters(relay_id: relay_id)
}
case .error(let merr):
@@ -425,3 +425,27 @@ func load_our_relays(our_pubkey: String, pool: RelayPool, ev: NostrEvent) {
}
}
}
func remove_bootstrap_nodes(_ damus_state: DamusState) {
guard let contacts = damus_state.contacts.event else {
return
}
guard let relays = decode_json_relays(contacts.content) else {
return
}
let descriptors = relays.reduce(into: []) { arr, kv in
guard let url = URL(string: kv.key) else {
return
}
arr.append(RelayDescriptor(url: url, info: kv.value))
}
for relay in BOOTSTRAP_RELAYS {
if !(descriptors.contains { ($0 as! RelayDescriptor).url.absoluteString == relay }) {
damus_state.pool.remove_relay(relay)
}
}
}

View File

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