Skip to content

Commit 9672be7

Browse files
gsmlgGSMLG-BOT
andauthored
feat: Add Zone feature (#4)
Co-authored-by: Jonathan Gao <[email protected]>
1 parent 6d9b597 commit 9672be7

33 files changed

+3709
-103
lines changed

.envrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export DIRENV_WARN_TIMEOUT=20s
2+
3+
eval "$(devenv direnvrc)"
4+
5+
# The use_devenv function supports passing flags to the devenv command
6+
# For example: use devenv --impure --option services.postgres.enable:bool true
7+
use devenv

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ jobs:
1616
matrix:
1717
include:
1818
- os: ubuntu-latest
19-
elixir: 1.17
19+
elixir: 1.18
2020
otp: 26
2121
- os: ubuntu-latest
2222
elixir: 1.18
2323
otp: 27
24+
- os: ubuntu-latest
25+
elixir: 1.18
26+
otp: 28
2427

2528
runs-on: ${{ matrix.os }}
2629
env:

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ jobs:
2121
strategy:
2222
matrix:
2323
include:
24-
- elixir: 1.17
24+
- elixir: 1.18
2525
otp: 26
2626
- elixir: 1.18
2727
otp: 27
28+
- elixir: 1.18
29+
otp: 28
2830

2931
runs-on: ubuntu-latest
3032
env:
@@ -76,8 +78,8 @@ jobs:
7678
- name: Set up Elixir
7779
uses: erlef/setup-beam@v1
7880
with:
79-
otp-version: 27
8081
elixir-version: 1.18
82+
otp-version: 28
8183

8284
- name: Install Deps
8385
run: |

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ ex_dns-*.tar
2929
/tmp/
3030
/debug_*
3131
/test_*
32+
33+
# Development environment files
34+
.devenv/
35+
.devenv.*

CLAUDE.md

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,113 @@ DNS/
3333
└── Class.ex # DNS class definitions
3434
```
3535

36+
### Core Components
37+
38+
**DNS.Message Protocol System**
39+
- `DNS.Parameter` protocol handles binary serialization/deserialization
40+
- `String.Chars` protocol provides human-readable string representations
41+
- All DNS entities implement both protocols for consistent behavior
42+
43+
**DNS.Message Hierarchy**
44+
- `DNS.Message` - Top-level DNS message with header, questions, and record sections
45+
- `DNS.Message.Header` - Message header (ID, flags, counts)
46+
- `DNS.Message.Question` - Query section with QNAME, QTYPE, QCLASS
47+
- `DNS.Message.Record` - Resource records with name, type, class, TTL, and data
48+
- `DNS.Message.Record.Data/*` - 20+ specific record type implementations (A, AAAA, CNAME, MX, TXT, DNSSEC records, etc.)
49+
- `DNS.Message.Domain` - Domain name parsing with compression support
50+
- `DNS.Message.EDNS0` - Extension mechanisms and options
51+
52+
**DNS.Zone Management**
53+
- `DNS.Zone` - Zone abstraction supporting 4 types: :authoritative, :stub, :forward, :cache
54+
- `DNS.Zone.Manager` - CRUD operations and zone lifecycle management
55+
- `DNS.Zone.Store` - ETS-based persistent zone storage
56+
- `DNS.Zone.Cache` - TTL-based caching with automatic expiration
57+
- `DNS.Zone.Loader` - Zone file loading from various sources
58+
- `DNS.Zone.FileParser` - BIND format zone file parsing
59+
- `DNS.Zone.Validator` - Zone validation and diagnostics
60+
- `DNS.Zone.DNSSEC` - DNSSEC signing and validation (basic implementation)
61+
62+
### Key Implementation Patterns
63+
64+
**Protocol-Based Architecture**
65+
All DNS entities implement `DNS.Parameter.to_iodata/1` for binary serialization and `String.Chars.to_string/1` for display. This provides consistent behavior across the entire library.
66+
67+
**Binary Pattern Matching**
68+
Heavy use of Elixir's pattern matching on binaries for efficient DNS protocol parsing, particularly in domain name compression and record data parsing.
69+
70+
**ETS-Based Storage**
71+
Zone management uses ETS tables for in-memory storage with separate tables for zone data and metadata, supporting high-concurrency access patterns.
72+
73+
**Type System Integration**
74+
Comprehensive use of `@type` specifications throughout the codebase with proper union types and structured error returns.
75+
76+
### Critical Implementation Details
77+
78+
**Domain Name Compression**
79+
Located in `DNS.Message.Domain.parse_domain_from_message/2` - handles DNS message compression with pointer dereferencing. This is a performance-critical path and security-sensitive area.
80+
81+
**Record Data Dispatch**
82+
`DNS.Message.Record.Data` uses pattern matching on record type integers to dispatch to appropriate record type modules. New record types require adding entries in multiple places.
83+
84+
**Zone Manager Store Integration**
85+
`DNS.Zone.Manager` coordinates with `DNS.Zone.Store` for persistence and `DNS.Zone.Cache` for temporary storage, with automatic initialization and cleanup.
86+
87+
**Error Handling Patterns**
88+
The codebase uses a mix of throw/1 for parsing errors and {:error, reason} tuples for validation errors. This inconsistency is being addressed in ongoing refactoring.
89+
90+
### Security Considerations
91+
92+
**Domain Compression Depth**
93+
Domain name decompression in `DNS.Message.Domain` is vulnerable to compression loop attacks. Implementation must include depth limits.
94+
95+
**Binary Data Validation**
96+
Record length fields (rdlength) require validation to prevent memory exhaustion attacks. Critical in `DNS.Message.Record.from_iodata/2`.
97+
98+
**DNSSEC Implementation**
99+
Current DNSSEC support uses placeholder cryptographic functions. Production use requires proper cryptographic implementations.
100+
36101
## Development Commands
37102

38103
### Testing
39104
```bash
40-
mix test # Run all tests
41-
mix test test/path/to/file_test.exs # Run specific test file
105+
mix test # Run all tests
106+
mix test test/dns/message_test.exs # Run specific test file
107+
mix test --include wip # Run tests including WIP tagged tests
108+
mix test --trace # Run tests with detailed output
42109
```
43110

44-
### Code Quality
111+
### Code Quality & Analysis
45112
```bash
46-
mix format # Format code with Elixir formatter
47-
mix credo # Run static code analysis
48-
mix dialyzer # Run type checking and static analysis
113+
mix format # Format code with Elixir formatter
114+
mix format --check-formatted # Check if code is formatted
115+
mix credo # Run static code analysis
116+
mix dialyzer # Run type checking and static analysis
117+
```
118+
119+
### Build & Dependencies
120+
```bash
121+
mix deps.get # Install/update dependencies
122+
mix compile # Compile the project
123+
mix clean # Clean compiled files
124+
mix compile --warnings-as-errors # Treat warnings as errors (CI requirement)
49125
```
50126

51127
### Documentation
52128
```bash
53-
mix docs # Generate documentation
54-
mix help # List available tasks
129+
mix docs # Generate documentation
130+
mix help # List available tasks
131+
```
132+
133+
### Publishing & Release
134+
```bash
135+
mix publish # Format and publish to hex.pm (custom alias)
136+
mix hex.publish --yes # Direct publish to hex.pm
55137
```
56138

57-
### Publishing
139+
### Manual Testing Scripts
58140
```bash
59-
mix publish # Format and publish to hex.pm
141+
elixir test_all_string_chars.exs # Test all record type String.Chars implementations
142+
elixir test_zone_system.exs # Test zone management functionality
60143
```
61144

62145
## Key Patterns
@@ -70,6 +153,8 @@ mix publish # Format and publish to hex.pm
70153
## File Organization
71154

72155
- `lib/dns/` - Core DNS implementation
73-
- `test/dns/` - Corresponding test files
74-
- `priv/data/` - DNS root hints and zone data
75-
- `doc/` - Generated documentation
156+
- `message/` - DNS protocol message handling
157+
- `zone/` - Zone management operations
158+
- `test/dns/` - Comprehensive test suite matching lib structure
159+
- `priv/data/` - DNS root hints and zone data files
160+
- `test_*_string_chars.exs` - Manual testing scripts for protocol implementations

0 commit comments

Comments
 (0)