Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
refactor: better config layout and testability
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Apr 10, 2024
1 parent a70ef5a commit 1e47fcb
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 294 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[workspace]
resolver = "2"
members = ["iroh-dns-server"]

[patch."https://github.com/n0-computer/iroh.git"]
iroh-net = { path = "../iroh/iroh-net" }
10 changes: 6 additions & 4 deletions iroh-dns-server/config.dev.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
[http]
port = 8080
bind_addr = "127.0.0.1"

[https]
port = 8443
bind_addr = "127.0.0.1"
domains = ["localhost"]
cert_mode = "self_signed"
letsencrypt_prod = false

[dns]
port = 5300
bind_addr = "127.0.0.1"
default_soa = "dns1.irohdns.example hostmaster.irohdns.example 0 10800 3600 604800 3600"
default_ttl = 900
origin = "irohdns.example."
additional_origins = ["."]
ipv4_addr = "127.0.0.1"
origins = ["irohdns.example.", "."]
rr_a = "127.0.0.1"
rr_ns = "ns1.irohdns.example."
7 changes: 3 additions & 4 deletions iroh-dns-server/config.prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ letsencrypt_prod = true
port = 53
default_soa = "dns1.irohdns.example.org hostmaster.irohdns.example.org 0 10800 3600 604800 3600"
default_ttl = 30
origin = "irohdns.example.org"
additional_origins = ["."]
ipv4_addr = "203.0.10.10"
ns_name = "ns1.irohdns.example.org"
origins = ["irohdns.example.org", "."]
rr_a = "203.0.10.10"
rr_ns = "ns1.irohdns.example.org."
5 changes: 4 additions & 1 deletion iroh-dns-server/examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ async fn main() -> Result<()> {
println!(" dig {} TXT", fmt_domain(&node_id, N0_DNS_NODE_ORIGIN))
}
Env::Dev => {
println!(" cargo run --example resolve -- --env dev node {}", node_id);
println!(
" cargo run --example resolve -- --env dev node {}",
node_id
);
println!(
" dig @localhost -p 5300 {} TXT",
fmt_domain(&node_id, EXAMPLE_ORIGIN)
Expand Down
30 changes: 23 additions & 7 deletions iroh-dns-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ pub struct MetricsConfig {
bind_addr: Option<SocketAddr>,
}

impl MetricsConfig {
pub fn disabled() -> Self {
Self {
disabled: true,
bind_addr: None,
}
}
}

impl Config {
pub async fn load(path: impl AsRef<Path>) -> Result<Config> {
let s = tokio::fs::read_to_string(path.as_ref())
Expand Down Expand Up @@ -66,23 +75,30 @@ impl Config {
impl Default for Config {
fn default() -> Self {
Self {
http: Some(HttpConfig { port: 8080 }),
http: Some(HttpConfig {
port: 8080,
bind_addr: None,
}),
https: Some(HttpsConfig {
port: 8443,
bind_addr: None,
domains: vec!["localhost".to_string()],
cert_mode: CertMode::SelfSigned,
letsencrypt_contact: None,
letsencrypt_prod: false,
letsencrypt_prod: None,
}),
dns: DnsConfig {
port: 5300,
bind_addr: None,
origins: vec!["irohdns.example.".to_string(), ".".to_string()],

default_soa: "irohdns.example hostmaster.irohdns.example 0 10800 3600 604800 3600"
.to_string(),
origin: "irohdns.example.".to_string(),
port: 5300,
default_ttl: 900,
additional_origins: vec![".".to_string()],
ipv4_addr: Some(Ipv4Addr::LOCALHOST),
ns_name: Some("ns1.irohdns.example.".to_string()),

rr_a: Some(Ipv4Addr::LOCALHOST),
rr_aaaa: None,
rr_ns: Some("ns1.irohdns.example.".to_string()),
},
metrics: None,
}
Expand Down
Loading

0 comments on commit 1e47fcb

Please sign in to comment.