Add synthetic radar detection generation endpoint#17
Conversation
Implements /api/synthetic-detections endpoint for generating realistic radar detections with configurable noise characteristics for testing passive radar tracking systems. Key features: - Configurable Gaussian noise for delay and Doppler measurements - Missed detection simulation (configurable detection probability) - False alarm generation (Poisson-distributed clutter) - Reproducible results via seedable random number generation - Frame-based output format compatible with retina-tracker Implementation includes: - SyntheticRNG class with uniform, Gaussian, Poisson, and Bernoulli distributions - Configuration parsing and validation for noise parameters - Comprehensive test suite for statistical properties - Utility scripts for capturing and processing ADS-B snapshots - Updated README with API documentation and examples Technical changes: - Added seedrandom dependency for reproducible RNG - Changed docker-compose networking from host mode to port mapping - Added data/ directory to .gitignore for snapshot storage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Pull Request Review: Synthetic Radar Detection GenerationThank you for this comprehensive PR! This is a well-thought-out feature that adds significant testing and validation capabilities. Here is my detailed review: StrengthsExcellent Test Coverage
Clean Code Architecture
Thoughtful Feature Design
Critical Issues Found1. Potential Performance Issue in EndpointLocation: src/server.js:291-405 The /api/synthetic-detections endpoint generates frames sequentially in a loop, making multiple blocking HTTP requests. With default settings (10 seconds duration, 500ms intervals = 20 frames), this makes 20 sequential HTTP requests before responding. Problems:
Recommendation: Add request timeout handling, consider rate limiting, or redesign to stream results. 2. Bug: Inconsistent norm() Function APILocations: src/server.js:283, 333 vs process_snapshots.js:61 The code uses both array syntax norm([x, y, z]) and object syntax norm({x, y, z}) for the norm() function. This will cause runtime errors if the function doesn't handle both formats. Recommendation: Check src/node/geometry.js implementation and standardize on one calling convention. 3. Missing Error HandlingLocation: src/server.js:339-341 The code only checks if (doppler !== null) but doesn't handle potential exceptions from calculateDopplerFromVelocity(). If this function throws, the entire endpoint crashes. Recommendation: Add try-catch around the delay-Doppler computation loop. 4. Docker Compose Breaking ChangeLocation: docker-compose.yml:5-9 Changed from network_mode: host to explicit port mapping 49155:49155. Problems:
Recommendation: Document this as a BREAKING CHANGE in PR description, explain why necessary, provide migration guidance. Security Concerns5. DoS Risk: Unbounded Frame GenerationLocation: src/server.js:288-289 A malicious user could request duration=100000&frame_interval=1 creating 100 million frames, exhausting memory and CPU. Recommendation: 6. SSRF Risk: External URL ValidationLocation: src/server.js:246, 261-273 The endpoint accepts arbitrary server URLs and makes HTTP requests. While there is protocol validation, there is no protection against private IP ranges (192.168.x.x, 10.x.x.x, 127.0.0.1) or cloud metadata endpoints (169.254.169.254). Recommendation: Add IP range validation to prevent SSRF attacks (check if this exists in original /api/dd endpoint for consistency). Code Quality Suggestions7. Code DuplicationLocation: src/server.js:357-404 The synthetic frame generation logic in the endpoint duplicates code from generateSyntheticFrame() in synthetic.js. Recommendation: Refactor to use the existing function consistently. 8. Missing Input ValidationLocation: src/node/synthetic.js:72-113 parseSyntheticConfig() uses parseFloat() and parseInt() without checking for NaN results. If query.noise_delay = "abc", it becomes NaN which passes parsing but fails validation later. Recommendation: Validate during parsing or return errors immediately. 9. Hardcoded ConfigurationLocation: process_snapshots.js:25-49 The radar configuration is hardcoded (specific to 150 Mississippi / KSCZ-LD), limiting reusability. Recommendation: Accept configuration via command-line arguments or config file. Documentation & Testing10. Missing API Response ExamplesThe README shows URLs but not actual JSON responses. Include example output. 11. Integration Testing ChecklistThe PR description shows unchecked items:
Recommendation: Complete these before merging, or create follow-up issues. 12. Add Integration TestsCurrent tests are unit tests. Consider adding end-to-end tests of the endpoint with mocked HTTP responses. Summary
Must Fix Before Merge:
Should Fix:
Final VerdictThis is high-quality work with excellent test coverage and thoughtful design. The statistical noise modeling is sophisticated and well-implemented. However, there are some critical issues around performance, DoS protection, and a breaking Docker change that should be addressed before merging. Great job on the comprehensive documentation and test suite! |
Security & DoS Protection: - Add MAX_FRAMES (1000) and MAX_DURATION_SECONDS (300) limits to prevent DoS attacks - Implement comprehensive SSRF protection matching /api/dd endpoint - Validate against private IP ranges (127.x, 10.x, 172.16-31.x, 192.168.x, 169.254.x) - Check IPv6 private ranges (::1, fe80, fc00, fd00, ff00) - Resolve hostnames and validate resolved IPs aren't private - Prevent invalid IP formats (hex, octal, decimal encoded) Error Handling: - Add try-catch around delay-Doppler computation to prevent endpoint crashes - Log errors for individual aircraft failures while continuing processing Input Validation: - Fix NaN validation in parseSyntheticConfig with parseAndValidate helper - Validate parsed numbers aren't NaN before applying to config - Add frame count validation against MAX_FRAMES limit - Add duration validation against MAX_DURATION_SECONDS limit Docker Configuration: - Revert docker-compose.yml to network_mode: host - Port mapping should only be used for local testing All 110 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Pull Request Review: Synthetic Radar Detection GenerationSummaryThis PR adds a ✅ StrengthsCode Quality
Security
🔍 Issues & Recommendations1. Potential Memory/Performance Issue (High Priority)Location: The for (let i = 0; i < nFrames; i++) {
// ...
json = await getTar1090(apiUrl); // Blocking call in loop
// ...
}Problems:
Recommendation:
2. Code Duplication (Medium Priority)Location: The new endpoint duplicates ~130 lines of validation logic from
Recommendation: Extract this validation into a shared function: function validateAndCheckServerUrl(server) {
// Returns {valid: boolean, error: string, serverUrl: URL, isAdsbLol: boolean}
}3. Incomplete Test Coverage (Low Priority)Location: Test plan in PR description shows unchecked items Missing tests:
Recommendation: While unit tests are excellent, consider adding an integration test that validates the output format is compatible with retina-tracker. 4. Minor:
|
Summary
/api/synthetic-detectionsendpoint for generating realistic radar detections with configurable noiseKey Features
Implementation Details
SyntheticRNGclass with uniform, Gaussian, Poisson, and Bernoulli distributionsTechnical Changes
seedrandomdependency for reproducible random number generationnetwork_mode: hostto explicit port mapping49155:49155data/directory to .gitignore for snapshot storageTest Plan
npm test)🤖 Generated with Claude Code