Commit 4a4f120
committed
Merge #258: feat: add socket address uniqueness validation for tracker configuration
dc153f0 refactor: [#255] eliminate duplication in binding collection (Jose Celano)
170ce02 refactor: [#255] extract conflict checking logic into separate method (Jose Celano)
97368e5 refactor: [#255] extract binding collection logic into separate method (Jose Celano)
16ade4a feat: [#255] add socket address uniqueness validation with tiered help system (Jose Celano)
981547b refactor: [#255] move database module into config/core (Jose Celano)
eca6dff refactor: [#255] extract tracker config types into submodules (Jose Celano)
ab84bbe feat: add configurable Health Check API to tracker configuration (Jose Celano)
Pull request description:
## Summary
Implements socket address uniqueness validation for tracker configuration as described in issue #255. This prevents configuration errors where multiple services attempt to bind to the same socket address with the same protocol, which would result in runtime failures.
## Changes
### Core Implementation
- **BindingAddress value object** (`src/domain/tracker/binding_address.rs`)
- Combines `SocketAddr` with `Protocol` for type-safe binding representation
- Implements `Hash` and `Eq` for HashMap-based duplicate detection
- 7 comprehensive unit tests
- **TrackerConfig validation** (`src/domain/tracker/config/mod.rs`)
- `validate()` - Main validation orchestrator
- `collect_bindings()` - Gathers all socket bindings with service names
- `check_for_conflicts()` - Detects duplicate bindings
- `register_binding()` / `register_trackers()` - DRY helper methods
- `HasBindAddress` trait for generic tracker handling
- 8 validation tests covering all scenarios
- **TrackerConfigError** with tiered help system
- Brief Display with actionable tip
- Detailed `.help()` method for troubleshooting
- Follows error handling conventions from `docs/contributing/error-handling.md`
### Integration
- Validation integrated at DTO boundary (`TrackerSection.to_tracker_config()`)
- Error propagation through `CreateConfigError`
- 2 integration tests for DTO validation
### Validation Rules
✅ **Rejects**: Same protocol + same socket address
- Multiple HTTP services on same TCP port
- Multiple UDP trackers on same port
- HTTP tracker + HTTP API conflict
- HTTP tracker + Health Check API conflict
✅ **Allows**: Different protocols sharing same port
- UDP tracker + HTTP tracker on same port (different protocols)
- Same port on different IP addresses
## Manual E2E Testing
Tested with real environment configurations to verify production behavior:
### Test Case 1: TCP Conflict ❌ (Correctly Rejected)
**Configuration**: HTTP Tracker and HTTP API both on `0.0.0.0:7070` (TCP)
```json
{
"http_trackers": [{"bind_address": "0.0.0.0:7070"}],
"http_api": {"bind_address": "0.0.0.0:7070", "admin_token": "..."}
}
```
**Result**:
```
❌ Configuration validation failed: Socket address conflict: 'HTTP Tracker #1', 'HTTP API' cannot bind to 0.0.0.0:7070 (TCP)
Tip: Assign different port numbers to each service
```
### Test Case 2: UDP Conflict ❌ (Correctly Rejected)
**Configuration**: Two UDP trackers on same address
```json
{
"udp_trackers": [
{"bind_address": "0.0.0.0:6969"},
{"bind_address": "0.0.0.0:6969"}
]
}
```
**Result**:
```
❌ Socket address conflict: 'UDP Tracker #1', 'UDP Tracker #2' cannot bind to 0.0.0.0:6969 (UDP)
Tip: Assign different port numbers to each service
```
### Test Case 3: Valid Configuration ✅ (Correctly Accepted)
**Configuration**: All services on unique addresses
```json
{
"udp_trackers": [{"bind_address": "0.0.0.0:6969"}],
"http_trackers": [{"bind_address": "0.0.0.0:7070"}],
"http_api": {"bind_address": "0.0.0.0:1212"},
"health_check_api": {"bind_address": "127.0.0.1:1313"}
}
```
**Result**: ✅ Environment created successfully
### Test Case 4: Cross-Protocol ✅ (Correctly Accepted)
**Configuration**: UDP and TCP sharing same port (different protocols)
```json
{
"udp_trackers": [{"bind_address": "0.0.0.0:7070"}],
"http_trackers": [{"bind_address": "0.0.0.0:7070"}]
}
```
**Result**: ✅ Environment created successfully (UDP and TCP use separate port spaces)
## Automated Testing
- ✅ 1613 unit tests passing
- ✅ All linters passing (markdown, YAML, TOML, cspell, clippy, rustfmt, shellcheck)
- ✅ Documentation builds successfully
- ✅ E2E infrastructure lifecycle tests passing
- ✅ E2E deployment workflow tests passing
- ✅ Total pre-commit time: 4m 45s
## Code Quality Improvements
This PR includes several refactoring commits that improve code quality:
1. **Extract binding collection** - Separate method for gathering bindings
2. **Extract conflict checking** - Focused method for duplicate detection
3. **Eliminate duplication** - DRY helpers for binding registration
**Benefits**:
- Single Responsibility Principle compliance
- Better testability with focused methods
- Reduced code duplication (~30 lines → ~15 lines)
- Clear separation of concerns
- Easier to maintain and extend
## Documentation
- Comprehensive rustdoc comments on all public APIs
- Error help text with platform-specific troubleshooting
- References to `docs/external-issues/tracker/udp-tcp-port-sharing-allowed.md`
## Related
- Closes #255
- Related: Socket address validation specification
ACKs for top commit:
josecelano:
ACK dc153f0
Tree-SHA512: e77aae9c25da50fed3aebf6bf513462f5f7b31378920a0b3bd725d454870ab0d8e3f993377a855ae599e96ea63c649f91c8158298f7aca3c7b1f5fff17308372File tree
29 files changed
+1744
-266
lines changed- schemas
- src
- application/command_handlers/create/config
- tracker
- domain
- environment
- tracker
- config
- core
- database
- infrastructure/templating
- ansible/template/wrappers/variables
- tracker/template
- renderer
- wrapper/tracker_config
- presentation/controllers
- create/subcommands/environment
- tests
- testing/e2e
- containers
- tasks/black_box
29 files changed
+1744
-266
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
158 | 169 | | |
159 | 170 | | |
160 | 171 | | |
| |||
320 | 331 | | |
321 | 332 | | |
322 | 333 | | |
323 | | - | |
| 334 | + | |
324 | 335 | | |
325 | 336 | | |
326 | 337 | | |
327 | 338 | | |
328 | 339 | | |
329 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
330 | 345 | | |
331 | 346 | | |
332 | 347 | | |
| |||
350 | 365 | | |
351 | 366 | | |
352 | 367 | | |
353 | | - | |
| 368 | + | |
| 369 | + | |
354 | 370 | | |
355 | 371 | | |
356 | 372 | | |
| |||
365 | 381 | | |
366 | 382 | | |
367 | 383 | | |
368 | | - | |
| 384 | + | |
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
| |||
417 | 420 | | |
418 | 421 | | |
419 | 422 | | |
| 423 | + | |
420 | 424 | | |
421 | 425 | | |
422 | 426 | | |
| |||
572 | 576 | | |
573 | 577 | | |
574 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
575 | 582 | | |
576 | 583 | | |
577 | 584 | | |
| |||
633 | 640 | | |
634 | 641 | | |
635 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
636 | 646 | | |
637 | 647 | | |
638 | 648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
| |||
424 | 429 | | |
425 | 430 | | |
426 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
427 | 453 | | |
428 | 454 | | |
429 | 455 | | |
| |||
Lines changed: 125 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
0 commit comments