mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 00:59:07 -05:00
feat: add event kind blacklist
Adds a list to the config where you can specify which event kinds to blacklist. The blacklist check will run right after verifying that the pubkey is allowed to post events to the relay.
This commit is contained in:
parent
104ef2b9e1
commit
7774db8c47
|
@ -100,6 +100,11 @@ reject_future_seconds = 1800
|
||||||
# backpressure to senders if writes are slow.
|
# backpressure to senders if writes are slow.
|
||||||
#event_persist_buffer = 4096
|
#event_persist_buffer = 4096
|
||||||
|
|
||||||
|
# Event kind blacklist. Events with these kinds will be discarded.
|
||||||
|
#event_kind_blacklist = [
|
||||||
|
# 70202,
|
||||||
|
#]
|
||||||
|
|
||||||
[authorization]
|
[authorization]
|
||||||
# Pubkey addresses in this array are whitelisted for event publishing.
|
# Pubkey addresses in this array are whitelisted for event publishing.
|
||||||
# Only valid events by these authors will be accepted, if the variable
|
# Only valid events by these authors will be accepted, if the variable
|
||||||
|
|
|
@ -60,6 +60,7 @@ pub struct Limits {
|
||||||
pub max_ws_frame_bytes: Option<usize>,
|
pub max_ws_frame_bytes: Option<usize>,
|
||||||
pub broadcast_buffer: usize, // events to buffer for subscribers (prevents slow readers from consuming memory)
|
pub broadcast_buffer: usize, // events to buffer for subscribers (prevents slow readers from consuming memory)
|
||||||
pub event_persist_buffer: usize, // events to buffer for database commits (block senders if database writes are too slow)
|
pub event_persist_buffer: usize, // events to buffer for database commits (block senders if database writes are too slow)
|
||||||
|
pub event_kind_blacklist: Option<Vec<u64>>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -225,6 +226,7 @@ impl Default for Settings {
|
||||||
max_ws_frame_bytes: Some(2 << 17), // 128K
|
max_ws_frame_bytes: Some(2 << 17), // 128K
|
||||||
broadcast_buffer: 16384,
|
broadcast_buffer: 16384,
|
||||||
event_persist_buffer: 4096,
|
event_persist_buffer: 4096,
|
||||||
|
event_kind_blacklist: None,
|
||||||
},
|
},
|
||||||
authorization: Authorization {
|
authorization: Authorization {
|
||||||
pubkey_whitelist: None, // Allow any address to publish
|
pubkey_whitelist: None, // Allow any address to publish
|
||||||
|
|
18
src/db.rs
18
src/db.rs
|
@ -232,6 +232,24 @@ pub async fn db_writer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that event kind isn't blacklisted
|
||||||
|
let kinds_blacklist = &settings.limits.event_kind_blacklist.clone();
|
||||||
|
if let Some(event_kind_blacklist) = kinds_blacklist {
|
||||||
|
if event_kind_blacklist.contains(&event.kind) {
|
||||||
|
info!(
|
||||||
|
"Rejecting event {}, blacklisted kind",
|
||||||
|
&event.get_event_id_prefix()
|
||||||
|
);
|
||||||
|
notice_tx
|
||||||
|
.try_send(Notice::blocked(
|
||||||
|
event.id,
|
||||||
|
"event kind is blocked by relay"
|
||||||
|
))
|
||||||
|
.ok();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// send any metadata events to the NIP-05 verifier
|
// send any metadata events to the NIP-05 verifier
|
||||||
if nip05_active && event.is_kind_metadata() {
|
if nip05_active && event.is_kind_metadata() {
|
||||||
// we are sending this prior to even deciding if we
|
// we are sending this prior to even deciding if we
|
||||||
|
|
Loading…
Reference in New Issue
Block a user