Skip to content

Commit 4c6cbb8

Browse files
committed
sdk: don't send kind 3 to inbox relays when using gossip
Closes nostr:nevent1qvzqqqqx25pzpepndn2jthmelfxn4umylktqp493ph8yy9d2fse76al2ppprgjcsqqsdp02ns3rrcnwdlnpxte3yctp5sm5kj2vkjz92rtyfky8lmekv0vcu9c9su Pull-Request: #1112 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 0688603 commit 4c6cbb8

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

crates/nostr-sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
- Fetch gossip NIP-17 list only if really needed (https://github.com/rust-nostr/nostr/pull/1090)
3636
- Try to fetch only newer events when updating gossip lists (https://github.com/rust-nostr/nostr/pull/1090)
37+
- Don't send kind 3 (contact list) to inbox relays when using gossip (https://github.com/rust-nostr/nostr/pull/1112)
3738

3839
### Added
3940

crates/nostr-sdk/src/client/mod.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@ impl Client {
16301630
event: &Event,
16311631
is_nip17: bool,
16321632
) -> Result<Output<EventId>, Error> {
1633+
let is_contact_list: bool = event.kind == Kind::ContactList;
16331634
let is_gift_wrap: bool = event.kind == Kind::GiftWrap;
16341635

16351636
// Get involved public keys and check what are up to date in the gossip graph and which ones require an update.
@@ -1643,6 +1644,10 @@ impl Client {
16431644
// Get only p tags since the author of a gift wrap is randomized
16441645
let public_keys = event.tags.public_keys().copied();
16451646
self.check_and_update_gossip(public_keys, kind).await?;
1647+
} else if is_contact_list {
1648+
// Contact list, update only author
1649+
self.check_and_update_gossip([event.pubkey], GossipKind::Nip65)
1650+
.await?;
16461651
} else {
16471652
// Get all public keys involved in the event: author + p tags
16481653
let public_keys = event
@@ -1680,15 +1685,21 @@ impl Client {
16801685

16811686
relays
16821687
} else {
1683-
// Get NIP65 relays
1684-
let mut outbox = self.gossip.get_nip65_outbox_relays(&[event.pubkey]).await;
1685-
let inbox = self
1686-
.gossip
1687-
.get_nip65_inbox_relays(event.tags.public_keys())
1688-
.await;
1688+
// Get OUTBOX relays
1689+
let mut relays = self.gossip.get_nip65_outbox_relays(&[event.pubkey]).await;
16891690

1690-
// Add outbox and inbox relays
1691-
for url in outbox.iter().chain(inbox.iter()) {
1691+
// Extend with INBOX relays
1692+
if !is_contact_list {
1693+
let inbox = self
1694+
.gossip
1695+
.get_nip65_inbox_relays(event.tags.public_keys())
1696+
.await;
1697+
1698+
relays.extend(inbox);
1699+
}
1700+
1701+
// Add OUTBOX and INBOX relays
1702+
for url in relays.iter() {
16921703
if self.add_gossip_relay(url).await? {
16931704
self.connect_relay(url).await?;
16941705
}
@@ -1697,14 +1708,11 @@ impl Client {
16971708
// Get WRITE relays
16981709
let write_relays: Vec<RelayUrl> = self.pool.__write_relay_urls().await;
16991710

1700-
// Extend OUTBOX relays with WRITE ones
1701-
outbox.extend(write_relays);
1702-
1703-
// Extend outbox relays with inbox ones
1704-
outbox.extend(inbox);
1711+
// Extend relays with WRITE ones
1712+
relays.extend(write_relays);
17051713

17061714
// Return all relays
1707-
outbox
1715+
relays
17081716
};
17091717

17101718
// Send event

0 commit comments

Comments
 (0)