$ show mokeyish/smartdns-rs
SmartDNS-rs is a cross-platform Rust implementation of a DNS server that forwards queries to multiple upstream DNS servers and returns the response from the fastest server (lowest latency). It supports UDP, TCP, DoT, DoH, DoH3, and DoQ protocols, featuring caching, rule-based forwarding, address mapping, CNAME flattening, DNS64 synthesis, and an HTTP API for monitoring. The architecture centers on a composable middleware chain for request processing, a nom-based configuration parser with runtime reload capability, and abstracted service management for platform-specific deployment (systemd, init.d, launchd, Windows services, OpenWrt). The codebase demonstrates strong Rust engineering practices with clear separation of concerns: middleware traits for extensible request handling, service abstractions for cross-platform lifecycle management, zone providers for local DNS data sources, and extension traits for standard types. Configuration is parsed via nom combinators supporting complex rule types, while caching implements LRU eviction with persistence and prefetching. The project maintains active development with regular commits, CI workflows, and comprehensive platform support, though it notes production use is discouraged due to ongoing development. Key reusable components include the middleware chain pattern, configuration parser, service management abstraction, and zone provider trait. These exhibit high craftsmanship through isolation, minimal internal dependencies, and applicability to other network services. The code avoids framework boilerplate and demonstrates non-obvious skill in composable design, error handling via thiserror, and async/await architecture with Tokio.
The LLM identified 4 files worth highlighting for reuse:
Implements a composable middleware chain for DNS request processing using a trait-based design. Each middleware (bogus, cache, nameserver, etc.) processes requests independently and can short-circuit or pass to the next. Demonstrates clean separation of concerns and is reusable in any network service pipeline.
Nom-based parser for SmartDNS configuration format supporting complex rule types (address, nameserver, client rules, etc.). Enables runtime configuration reloads and showcases advanced parser combinators with error handling. The parsing logic is isolated and could be adapted for similar configuration languages.
Provides platform-agnostic service management (install, start, stop, status) via a ServiceDefinition trait. Implemented for systemd, init.d, launchd, Windows services, and OpenWrt. Demonstrates clean abstraction of platform differences with minimal coupling to core logic.
Defines a ZoneProvider trait for extensible DNS data sources with implementations for identity (CHAOS TXT), reverse DNS (local_ptr), and rule-based zones. Enables chaining providers with fallback and illustrates plugin-like architecture for DNS resolution.