Skip to content

Commit

Permalink
make mainline a separate config section
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Apr 16, 2024
1 parent 5d008de commit 0802cf6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion iroh-dns-server/config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ origins = ["irohdns.example.", "."]
rr_a = "127.0.0.1"
rr_ns = "ns1.irohdns.example."

dht_fallback = false
[mainline]
enabled = false
3 changes: 2 additions & 1 deletion iroh-dns-server/config.prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ origins = ["irohdns.example.org", "."]
rr_a = "203.0.10.10"
rr_ns = "ns1.irohdns.example.org."

dht_fallback = false
[mainline]
enabled = false
24 changes: 21 additions & 3 deletions iroh-dns-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub struct Config {
/// `Some(MetricsConfig::disabled())`.
pub metrics: Option<MetricsConfig>,

/// Fall back to the dht for resolution.
pub dht_fallback: bool,
/// Config for the mainline lookup.
pub mainline: Option<MainlineConfig>,
}

/// The config for the metrics server.
Expand All @@ -64,6 +64,20 @@ impl MetricsConfig {
}
}

/// The config for the metrics server.
#[derive(Debug, Serialize, Deserialize)]
pub struct MainlineConfig {
/// Set to true to enable the mainline lookup.
pub enabled: bool,
}

#[allow(clippy::derivable_impls)]
impl Default for MainlineConfig {
fn default() -> Self {
Self { enabled: false }
}
}

impl Config {
/// Load the config from a file.
pub async fn load(path: impl AsRef<Path>) -> Result<Config> {
Expand Down Expand Up @@ -106,6 +120,10 @@ impl Config {
},
}
}

pub(crate) fn mainline_enabled(&self) -> bool {
self.mainline.as_ref().map(|x| x.enabled).unwrap_or_default()
}
}

impl Default for Config {
Expand Down Expand Up @@ -137,7 +155,7 @@ impl Default for Config {
rr_ns: Some("ns1.irohdns.example.".to_string()),
},
metrics: None,
dht_fallback: true,
mainline: None,
}
}
}
4 changes: 2 additions & 2 deletions iroh-dns-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
/// Spawn the server and run until the `Ctrl-C` signal is received, then shutdown.
pub async fn run_with_config_until_ctrl_c(config: Config) -> Result<()> {
let mut store = ZoneStore::persistent(Config::signed_packet_store_path()?)?;
if config.dht_fallback {
store = store.with_pkarr(Some(Default::default()));
if config.mainline_enabled() {
store = store.with_pkarr(Default::default());
};
let server = Server::spawn(config, store).await?;
tokio::signal::ctrl_c().await?;
Expand Down

0 comments on commit 0802cf6

Please sign in to comment.