From bbcd660c5a60cd95babbf91adc51a644f7d6fc57 Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Mon, 2 Mar 2026 08:24:04 +0300 Subject: [PATCH] [config] allow setting filters through the config --- README.md | 3 +++ src/config.rs | 36 ++++++++++++++++++++++++++++++++++++ src/main.rs | 35 ++++++++++++++++++++++++++++------- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8d23206..05e6ba7 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ the `WS /stream` (hydrant) and `WS /channel` (tap) endpoints have different desi | `RELAY_HOST` | `wss://relay.fire.hose.cam` | websocket URL of the upstream firehose relay. | | `PLC_URL` | `https://plc.wtf` | base URL(s) of the PLC directory (comma-separated for multiple). | | `FULL_NETWORK` | `false` | if `true`, discovers and indexes all repositories in the network. | +| `FILTER_SIGNALS` | | comma-separated list of NSID patterns to use for the filter on startup (e.g. `app.bsky.feed.post,app.bsky.graph.*`). | +| `FILTER_COLLECTIONS` | | comma-separated list of NSID patterns to use for the collections filter on startup. | +| `FILTER_EXCLUDES` | | comma-separated list of DIDs to exclude from indexing on startup. | | `FIREHOSE_WORKERS` | `8` (`32` if full network) | number of concurrent workers for firehose events. | | `BACKFILL_CONCURRENCY_LIMIT` | `128` | maximum number of concurrent backfill tasks. | | `VERIFY_SIGNATURES` | `full` | signature verification level: `full`, `backfill-only`, or `none`. | diff --git a/src/config.rs b/src/config.rs index 5d7d533..c1df27c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -65,6 +65,9 @@ pub struct Config { pub db_records_memtable_size_mb: u64, pub crawler_max_pending_repos: usize, pub crawler_resume_pending_repos: usize, + pub filter_signals: Option>, + pub filter_collections: Option>, + pub filter_excludes: Option>, } impl Config { @@ -156,6 +159,27 @@ impl Config { let crawler_max_pending_repos = cfg!("CRAWLER_MAX_PENDING_REPOS", 2000usize); let crawler_resume_pending_repos = cfg!("CRAWLER_RESUME_PENDING_REPOS", 1000usize); + let filter_signals = std::env::var("HYDRANT_FILTER_SIGNALS").ok().map(|s| { + s.split(',') + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .collect() + }); + + let filter_collections = std::env::var("HYDRANT_FILTER_COLLECTIONS").ok().map(|s| { + s.split(',') + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .collect() + }); + + let filter_excludes = std::env::var("HYDRANT_FILTER_EXCLUDES").ok().map(|s| { + s.split(',') + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .collect() + }); + Ok(Self { database_path, relay_host, @@ -185,6 +209,9 @@ impl Config { db_records_memtable_size_mb, crawler_max_pending_repos, crawler_resume_pending_repos, + filter_signals, + filter_collections, + filter_excludes, }) } } @@ -272,6 +299,15 @@ impl fmt::Display for Config { " crawler resume pending: {}", self.crawler_resume_pending_repos )?; + if let Some(signals) = &self.filter_signals { + writeln!(f, " filter signals: {:?}", signals)?; + } + if let Some(collections) = &self.filter_collections { + writeln!(f, " filter collections: {:?}", collections)?; + } + if let Some(excludes) = &self.filter_excludes { + writeln!(f, " filter excludes: {:?}", excludes)?; + } writeln!(f, " enable debug: {}", self.enable_debug)?; if self.enable_debug { writeln!(f, " debug port: {}", self.debug_port)?; diff --git a/src/main.rs b/src/main.rs index 1e84142..2a931db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,8 @@ static GLOBAL: MiMalloc = MiMalloc; #[tokio::main] async fn main() -> miette::Result<()> { + rustls::crypto::ring::default_provider().install_default().ok(); + let cfg = Config::from_env()?; let env_filter = tracing_subscriber::EnvFilter::new(&cfg.log_level); @@ -25,18 +27,37 @@ async fn main() -> miette::Result<()> { let state = AppState::new(&cfg)?; - if cfg.full_network { + if cfg.full_network || cfg.filter_signals.is_some() || cfg.filter_collections.is_some() || cfg.filter_excludes.is_some() { let filter_ks = state.db.filter.clone(); let inner = state.db.inner.clone(); + let full_network = cfg.full_network; + let signals = cfg.filter_signals.clone(); + let collections = cfg.filter_collections.clone(); + let excludes = cfg.filter_excludes.clone(); + tokio::task::spawn_blocking(move || { - use hydrant::db::filter::MODE_KEY; - use hydrant::filter::FilterMode; + use hydrant::filter::{FilterMode, SetUpdate}; let mut batch = inner.batch(); - batch.insert( + + let mode = if full_network { + Some(FilterMode::Full) + } else { + None + }; + + let signals_update = signals.map(SetUpdate::Set); + let collections_update = collections.map(SetUpdate::Set); + let excludes_update = excludes.map(SetUpdate::Set); + + hydrant::db::filter::apply_patch( + &mut batch, &filter_ks, - MODE_KEY, - rmp_serde::to_vec(&FilterMode::Full).into_diagnostic()?, - ); + mode, + signals_update, + collections_update, + excludes_update, + )?; + batch.commit().into_diagnostic() }) .await -- knotmirror 0.0.1