Skip to content

Commit baeba7b

Browse files
committed
sdk: add verify_subscriptions and ban_relay_on_mismatch to ClientOptions
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 8c03d6d commit baeba7b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

crates/nostr-sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
### Added
3737

3838
- Add `ClientOptions::sleep_when_idle` (https://github.com/rust-nostr/nostr/pull/959)
39+
- add `verify_subscriptions` and `ban_relay_on_mismatch` to `ClientOptions` (https://github.com/rust-nostr/nostr/pull/998)
3940

4041
### Deprecated
4142

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ impl Client {
256256
// Set limits
257257
opts.limits(self.opts.relay_limits.clone())
258258
.max_avg_latency(self.opts.max_avg_latency)
259+
.verify_subscriptions(self.opts.verify_subscriptions)
260+
.ban_relay_on_mismatch(self.opts.ban_relay_on_mismatch)
259261
}
260262

261263
/// If return `false` means that already existed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct ClientOptions {
2626
pub(super) relay_limits: RelayLimits,
2727
pub(super) max_avg_latency: Option<Duration>,
2828
pub(super) sleep_when_idle: SleepWhenIdle,
29+
pub(super) verify_subscriptions: bool,
30+
pub(super) ban_relay_on_mismatch: bool,
2931
pub(super) pool: RelayPoolOptions,
3032
}
3133

@@ -114,6 +116,18 @@ impl ClientOptions {
114116
self
115117
}
116118

119+
/// Verify that received events belong to a subscription and match the filter.
120+
pub fn verify_subscriptions(mut self, enable: bool) -> Self {
121+
self.verify_subscriptions = enable;
122+
self
123+
}
124+
125+
/// If true, ban a relay when it sends an event that doesn't match the subscription filter.
126+
pub fn ban_relay_on_mismatch(mut self, ban_relay: bool) -> Self {
127+
self.ban_relay_on_mismatch = ban_relay;
128+
self
129+
}
130+
117131
/// Set relay pool options
118132
#[inline]
119133
pub fn pool(mut self, opts: RelayPoolOptions) -> Self {

0 commit comments

Comments
 (0)