noteguard

the nostr relay spam guardian
git clone git://jb55.com/noteguard
Log | Files | Refs | README | LICENSE

whitelist.rs (974B)


      1 use crate::{Action, InputMessage, NoteFilter, OutputMessage};
      2 use serde::Deserialize;
      3 
      4 #[derive(Deserialize, Default)]
      5 pub struct Whitelist {
      6     pub pubkeys: Option<Vec<String>>,
      7     pub ips: Option<Vec<String>>,
      8 }
      9 
     10 impl NoteFilter for Whitelist {
     11     fn filter_note(&mut self, msg: &InputMessage) -> OutputMessage {
     12         if let Some(pubkeys) = &self.pubkeys {
     13             if pubkeys.contains(&msg.event.pubkey) {
     14                 return OutputMessage::new(msg.event.id.clone(), Action::Accept, None);
     15             }
     16         }
     17 
     18         if let Some(ips) = &self.ips {
     19             if ips.contains(&msg.source_info) {
     20                 return OutputMessage::new(msg.event.id.clone(), Action::Accept, None);
     21             }
     22         }
     23 
     24         OutputMessage::new(
     25             msg.event.id.clone(),
     26             Action::Reject,
     27             Some("blocked: pubkey/ip not on the whitelist".to_string()),
     28         )
     29     }
     30 
     31     fn name(&self) -> &'static str {
     32         "whitelist"
     33     }
     34 }