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

Commit

Permalink
fix: address review by dig
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Apr 9, 2024
1 parent 1a0396c commit 03b0c16
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 360 deletions.
102 changes: 28 additions & 74 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
resolver = "2"
members = ["iroh-dns-server"]

[patch."https://github.com/n0-computer/iroh.git"]
iroh-net = { path = "../iroh/iroh-net" }
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 N0, INC.
Copyright 2024 N0, INC.

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
38 changes: 19 additions & 19 deletions iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ license = "MIT OR Apache-2.0"
authors = ["Frando <[email protected]>", "n0 team"]
repository = "https://github.com/n0-computer/iroh-dns-server"
keywords = ["networking", "pkarr", "dns", "dns-server", "iroh"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["mainline-dht"]
mainline-dht = ["pkarr/dht"]
readme = "README.md"

[dependencies]
anyhow = "1.0.80"
Expand All @@ -22,37 +17,42 @@ axum-server = { version = "0.6.0", features = ["tls-rustls"] }
base64-url = "2.0.2"
bytes = "1.5.0"
clap = { version = "4.5.1", features = ["derive"] }
derive_more = { version = "0.99.17", features = ["display"] }
derive_more = { version = "1.0.0-beta.1", features = ["debug", "display"] }
dirs-next = "2.0.0"
futures = "0.3.30"
governor = "0.6.3"
hex = "0.4.3"
hickory-proto = "0.24.0"
hickory-server = { version = "0.24.0", features = ["dns-over-rustls"] }
http = "1.0.0"
pkarr = { version = "1.1.2", features = ["async", "relay"], default_features = false }
iroh-metrics = "0.13.0"
parking_lot = "0.12.1"
pkarr = { version = "1.1.2", features = [
"async",
"relay",
], default_features = false }
rcgen = "0.12.1"
redb = "2.0.0"
regex = "1.10.3"
rustls = "0.21"
rustls-pemfile = "1"
serde = { version = "1.0.197", features = ["derive"] }
struct_iterable = "0.1.1"
strum = { version = "0.26.1", features = ["derive"] }
tokio = { version = "1.36.0", features = ["full"] }
tokio-rustls = "0.24"
tokio-rustls-acme = { git = "https://github.com/n0-computer/tokio-rustls-acme.git", branch = "main", features = ["axum"] }
tokio-rustls-acme = { git = "https://github.com/n0-computer/tokio-rustls-acme.git", branch = "main", features = [
"axum",
] }
tokio-stream = "0.1.14"
tokio-util = "0.7.10"
toml = "0.8.10"
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
tower_governor = "0.3.2"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
url = "2.5.0"
dirs-next = "2.0.0"
strum = { version = "0.26.1", features = ["derive"] }
parking_lot = "0.12.1"
ttl_cache = "0.5.1"
redb = "2.0.0"
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
tower_governor = "0.3.2"
governor = "0.6.3"
iroh-metrics = "0.13.0"
struct_iterable = "0.1.1"
url = "2.5.0"

[dev-dependencies]
hickory-resolver = "0.24.0"
Expand Down
6 changes: 5 additions & 1 deletion iroh-dns-server/examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ async fn main() -> Result<()> {
println!(" node_id: {node_id}");
println!(" relay: {}", args.relay_url);
let publisher = match (args.pkarr_relay, args.env) {
(Some(pkarr_relay), _) => Publisher::new(secret_key, pkarr_relay),
(Some(pkarr_relay), _) => {
println!("create for {pkarr_relay}");
Publisher::new(secret_key, pkarr_relay)
}
(None, Env::Default) => Publisher::n0_testdns(secret_key),
(None, Env::Dev) => Publisher::new(secret_key, LOCALHOST_PKARR.parse().unwrap()),
};
println!("pub {publisher:?}");

let info = AddrInfo {
relay_url: Some(args.relay_url.into()),
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/examples/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main() -> anyhow::Result<()> {
let (resolver, origin) = match args.env {
Env::Default => (
iroh_net::dns::default_resolver().clone(),
N0_TESTDNS_NODE_ORIGIN,
"dns.iroh.link", // N0_TESTDNS_NODE_ORIGIN,
),
Env::Dev => {
let nameserver: SocketAddr = LOCALHOST_DNS.parse()?;
Expand Down
10 changes: 5 additions & 5 deletions iroh-dns-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ pub struct MetricsConfig {
}

impl Config {
pub fn load(path: impl AsRef<Path>) -> Result<Config> {
let s = std::fs::read_to_string(path.as_ref())
pub async fn load(path: impl AsRef<Path>) -> Result<Config> {
let s = tokio::fs::read_to_string(path.as_ref())
.await
.with_context(|| format!("failed to read {}", path.as_ref().to_string_lossy()))?;
let config: Config = toml::from_str(&s)?;
Ok(config)
Expand Down Expand Up @@ -74,9 +75,8 @@ impl Default for Config {
letsencrypt_prod: false,
}),
dns: DnsConfig {
default_soa:
"irohdns.example hostmaster.irohdns.example 0 10800 3600 604800 3600"
.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,
Expand Down
14 changes: 3 additions & 11 deletions iroh-dns-server/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ pub async fn serve(
let sock_addr = SocketAddrV4::new(ip4_addr, config.port);

server.register_socket(UdpSocket::bind(sock_addr).await?);
server.register_listener(
TcpListener::bind(sock_addr).await?,
TCP_TIMEOUT, // Duration::from_millis(settings.timeout_ms),
);
server.register_listener(TcpListener::bind(sock_addr).await?, TCP_TIMEOUT);
tracing::info!("DNS server listening on {}", sock_addr);

tokio::select! {
Expand All @@ -94,21 +91,16 @@ pub async fn serve(
Ok(())
}
/// State for serving DNS
#[derive(Clone)]
#[derive(Clone, derive_more::Debug)]
pub struct DnsServer {
pub authority: Arc<NodeAuthority>,
/// The default SOA record used for all zones that this DNS server controls
pub default_soa: rdata::SOA,
pub default_ttl: u32,
#[debug("Catalog")]
pub catalog: Arc<Catalog>,
}

impl std::fmt::Debug for DnsServer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DnsServer").finish()
}
}

impl DnsServer {
/// Create a DNS server given some settings, a connection to the DB for DID-by-username lookups
/// and the server DID to serve under `_did.<origin>`.
Expand Down
Loading

0 comments on commit 03b0c16

Please sign in to comment.