Async tokio runtime with modular architecture #1

Merged
razvandimescu merged 4 commits from feat/async-tokio into main 2026-03-10 11:35:26 +08:00
razvandimescu commented 2026-03-10 10:51:27 +08:00 (Migrated from github.com)

Summary

  • Replace synchronous std::net::UdpSocket with tokio async runtime — each incoming DNS query is handled concurrently via tokio::spawn
  • Extract monolithic main.rs into 9 focused modules: buffer, header, question, record, packet, config, cache, forward, stats
  • Shared server state grouped into ServerCtx struct behind Arc, with scoped std::sync::Mutex locks (sub-microsecond holds, never across .await)
  • Add TOML-based config (dns_fun.toml), TTL-aware response cache with lazy eviction, structured per-query logging, and periodic stats summaries
  • Narrow tokio features to rt-multi-thread, macros, net, time (no full)
  • Add Makefile with cargo fmt --check and cargo clippy -- -D warnings; fix all clippy warnings
  • Gitignore CLAUDE.md

Test plan

  • make all passes (fmt + clippy + build)
  • sudo cargo run starts and binds to port 53
  • dig @127.0.0.1 google.com returns valid response (FORWARD path)
  • Repeat same query — returns from cache (CACHED path)
  • Add [[zones]] entry to dns_fun.toml, query it — returns LOCAL path
  • Verify concurrent queries: for i in $(seq 1 10); do dig @127.0.0.1 example.com & done

🤖 Generated with Claude Code

## Summary - Replace synchronous `std::net::UdpSocket` with `tokio` async runtime — each incoming DNS query is handled concurrently via `tokio::spawn` - Extract monolithic `main.rs` into 9 focused modules: buffer, header, question, record, packet, config, cache, forward, stats - Shared server state grouped into `ServerCtx` struct behind `Arc`, with scoped `std::sync::Mutex` locks (sub-microsecond holds, never across `.await`) - Add TOML-based config (`dns_fun.toml`), TTL-aware response cache with lazy eviction, structured per-query logging, and periodic stats summaries - Narrow tokio features to `rt-multi-thread`, `macros`, `net`, `time` (no `full`) - Add Makefile with `cargo fmt --check` and `cargo clippy -- -D warnings`; fix all clippy warnings - Gitignore `CLAUDE.md` ## Test plan - [x] `make all` passes (fmt + clippy + build) - [ ] `sudo cargo run` starts and binds to port 53 - [ ] `dig @127.0.0.1 google.com` returns valid response (FORWARD path) - [ ] Repeat same query — returns from cache (CACHED path) - [ ] Add `[[zones]]` entry to `dns_fun.toml`, query it — returns LOCAL path - [ ] Verify concurrent queries: `for i in $(seq 1 10); do dig @127.0.0.1 example.com & done` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.