Skip to content

Commit f9c1ebf

Browse files
committed
gossip-memory: limit NIP-17 and NIP-65 relay list sizes
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 1e778a2 commit f9c1ebf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

gossip/nostr-gossip-memory/src/constant.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
use std::time::Duration;
66

77
pub(super) const PUBKEY_METADATA_OUTDATED_AFTER: Duration = Duration::from_secs(60 * 60); // 60 min
8+
pub(super) const MAX_NIP17_SIZE: usize = 7;
9+
pub(super) const MAX_NIP65_SIZE: usize = 7;

gossip/nostr-gossip-memory/src/store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use nostr_gossip::error::GossipError;
1414
use nostr_gossip::{BestRelaySelection, GossipListKind, GossipPublicKeyStatus, NostrGossip};
1515
use tokio::sync::Mutex;
1616

17-
use crate::constant::PUBKEY_METADATA_OUTDATED_AFTER;
17+
use crate::constant::{MAX_NIP17_SIZE, MAX_NIP65_SIZE, PUBKEY_METADATA_OUTDATED_AFTER};
1818
use crate::flags::Flags;
1919

2020
#[derive(Default)]
@@ -70,7 +70,7 @@ impl NostrGossipMemory {
7070
let pk_data: &mut PkData =
7171
public_keys.get_or_insert_mut(event.pubkey, PkData::default);
7272

73-
for (relay_url, metadata) in nip65::extract_relay_list(event) {
73+
for (relay_url, metadata) in nip65::extract_relay_list(event).take(MAX_NIP65_SIZE) {
7474
// New bitflag for the relay
7575
let bitflag: Flags = match metadata {
7676
Some(RelayMetadata::Read) => Flags::READ,
@@ -100,7 +100,7 @@ impl NostrGossipMemory {
100100
let pk_data: &mut PkData =
101101
public_keys.get_or_insert_mut(event.pubkey, PkData::default);
102102

103-
for relay_url in nip17::extract_relay_list(event) {
103+
for relay_url in nip17::extract_relay_list(event).take(MAX_NIP17_SIZE) {
104104
let relay_data = pk_data
105105
.relays
106106
.get_or_insert_mut(relay_url.clone(), PkRelayData::default);

0 commit comments

Comments
 (0)