Implement NostrNetworkManager and UserRelayListManager

This commit implements a new layer called NostrNetworkManager,
responsible for managing interactions with the Nostr network, and
providing a higher level API that is easier and more secure to use for
the layer above it.

It also integrates it with the rest of the app, by moving RelayPool and PostBox
into NostrNetworkManager, along with all their usages.

Changelog-Added: Added NIP-65 relay list support
Changelog-Changed: Improved robustness of relay list handling
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-03-26 15:23:59 -03:00
parent 0ec2b05070
commit 3a0acfaba1
60 changed files with 837 additions and 398 deletions

View File

@@ -98,7 +98,7 @@ final class AuthIntegrationTests: XCTestCase {
sent_messages.append(str)
}
XCTAssertEqual(pool.relays.count, 0)
let relay_descriptor = RelayPool.RelayDescriptor.init(url: relay_url, info: .rw)
let relay_descriptor = RelayPool.RelayDescriptor.init(url: relay_url, info: .readWrite)
try! pool.add_relay(relay_descriptor)
XCTAssertEqual(pool.relays.count, 1)
let connection_expectation = XCTestExpectation(description: "Waiting for connection")
@@ -142,7 +142,7 @@ final class AuthIntegrationTests: XCTestCase {
sent_messages.append(str)
}
XCTAssertEqual(pool.relays.count, 0)
let relay_descriptor = RelayPool.RelayDescriptor.init(url: relay_url, info: .rw)
let relay_descriptor = RelayPool.RelayDescriptor.init(url: relay_url, info: .readWrite)
try! pool.add_relay(relay_descriptor)
XCTAssertEqual(pool.relays.count, 1)
let connection_expectation = XCTestExpectation(description: "Waiting for connection")

View File

@@ -27,8 +27,7 @@ func generate_test_damus_state(
}()
let mutelist_manager = MutelistManager(user_keypair: test_keypair)
let damus = DamusState(pool: pool,
keypair: test_keypair,
let damus = DamusState(keypair: test_keypair,
likes: .init(our_pubkey: our_pubkey),
boosts: .init(our_pubkey: our_pubkey),
contacts: .init(our_pubkey: our_pubkey), mutelist_manager: mutelist_manager,
@@ -43,8 +42,6 @@ func generate_test_damus_state(
drafts: .init(),
events: .init(ndb: ndb),
bookmarks: .init(pubkey: our_pubkey),
postbox: .init(pool: pool),
bootstrap_relays: .init(),
replies: .init(our_pubkey: our_pubkey),
wallet: .init(settings: settings),
nav: .init(),

View File

@@ -35,7 +35,7 @@ final class MutingTests: XCTestCase {
}
test_damus_state.mutelist_manager.set_mutelist(mutelist)
test_damus_state.postbox.send(mutelist)
test_damus_state.nostrNetwork.postbox.send(mutelist)
XCTAssert(test_damus_state.mutelist_manager.is_event_muted(spammy_test_note))
XCTAssertFalse(test_damus_state.mutelist_manager.is_event_muted(test_note))

View File

@@ -20,7 +20,7 @@ final class RequestTests: XCTestCase {
func testMakeAuthRequest() {
let challenge_string = "8bc847dd-f2f6-4b3a-9c8a-71776ad9b071"
let url = RelayURL("wss://example.com")!
let relayDescriptor = RelayPool.RelayDescriptor(url: url, info: .rw)
let relayDescriptor = RelayPool.RelayDescriptor(url: url, info: .readWrite)
let relayConnection = RelayConnection(url: url) { _ in
} processEvent: { _ in
}