Skip to content

Commit 6dc4555

Browse files
committed
gossip: replace usize with u8 for relay limits
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 6adf42a commit 6dc4555

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

crates/nostr-sdk/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
2424
-->
2525

26+
## Unreleased
27+
28+
### Breaking changes
29+
30+
- Replace `usize` with `u8` for gossip relay limits
31+
2632
## v0.44.1 - 2025/11/09
2733

2834
### Fixed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use nostr_relay_pool::prelude::*;
1616
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1717
pub struct GossipRelayLimits {
1818
/// Max number of **read** relays per user (default: 3)
19-
pub read_relays_per_user: usize,
19+
pub read_relays_per_user: u8,
2020
/// Max number of **write** relays per user (default: 3)
21-
pub write_relays_per_user: usize,
21+
pub write_relays_per_user: u8,
2222
/// Max number of **hint** relays per user (default: 1)
23-
pub hint_relays_per_user: usize,
23+
pub hint_relays_per_user: u8,
2424
/// Max number of **most used** relays per user (default: 1)
25-
pub most_used_relays_per_user: usize,
25+
pub most_used_relays_per_user: u8,
2626
/// Max number of NIP-17 relays per user (default: 3)
27-
pub nip17_relays: usize,
27+
pub nip17_relays: u8,
2828
}
2929

3030
impl Default for GossipRelayLimits {

gossip/nostr-gossip-memory/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
## Unreleased
2727

28+
### Breaking changes
29+
30+
- Replace `usize` with `u8` for relay limits
31+
2832
### Changed
2933

3034
- Replace `Mutex` with `RwLock` for better concurrency (https://github.com/rust-nostr/nostr/pull/1126)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl NostrGossipMemory {
288288
tx: &LruCache<PublicKey, PkData>,
289289
public_key: &PublicKey,
290290
flag: GossipFlags,
291-
limit: usize,
291+
limit: u8,
292292
) -> impl Iterator<Item = RelayUrl> + '_ {
293293
let mut relays: Vec<(RelayUrl, u64, Option<Timestamp>)> = Vec::new();
294294

@@ -312,7 +312,10 @@ impl NostrGossipMemory {
312312
});
313313

314314
// Take only the requested limit and extract relay URLs
315-
relays.into_iter().take(limit).map(|(url, _, _)| url)
315+
relays
316+
.into_iter()
317+
.take(limit as usize)
318+
.map(|(url, _, _)| url)
316319
}
317320
}
318321

gossip/nostr-gossip/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,38 @@ pub enum BestRelaySelection {
5959
/// Get all the best relays for **reading** and **writing** events (NIP-65)
6060
All {
6161
/// Limit for read relays
62-
read: usize,
62+
read: u8,
6363
/// Limit for write relays
64-
write: usize,
64+
write: u8,
6565
/// Limit for hints
66-
hints: usize,
66+
hints: u8,
6767
/// Limit for most received relays
68-
most_received: usize,
68+
most_received: u8,
6969
},
7070
/// Get the best relays for **reading** events (NIP-65)
7171
Read {
7272
/// Limit
73-
limit: usize,
73+
limit: u8,
7474
},
7575
/// Get the best relays for **writing** events (NIP-65)
7676
Write {
7777
/// Limit
78-
limit: usize,
78+
limit: u8,
7979
},
8080
/// Get the best relays for **reading** and **writing** private messages (NIP-17)
8181
PrivateMessage {
8282
/// Limit
83-
limit: usize,
83+
limit: u8,
8484
},
8585
/// Relays found in hints
8686
Hints {
8787
/// Limit
88-
limit: usize,
88+
limit: u8,
8989
},
9090
/// Relays that received most events
9191
MostReceived {
9292
/// Limit
93-
limit: usize,
93+
limit: u8,
9494
},
9595
}
9696

0 commit comments

Comments
 (0)