This document records the requirements and specifications provided during the development of the RTP Proxy project.
Date: 2025-10-17
Core Functionality Requirements:
-
Multi-Network Interface Support
- Support listening on one network interface and forwarding traffic through another
- Bind listen address and forward address separately for multi-homed proxy scenarios
- Allow explicit specification of network interface/address for both inbound and outbound traffic
- Enable traffic to enter via one interface and exit via another
-
Protocol Layer Support
- Support UDP-based RTP traffic forwarding (primary requirement)
- Support TCP-based RTP traffic forwarding (secondary requirement)
- Implement separate I/O handling logic for UDP (connectionless) and TCP (connection-oriented)
- Create transport layer adapters for each protocol type
-
gRPC Control Interface Design
CreateSession: Create session with parameters:- Listen address/port (where to receive traffic)
- Connect address/port (source address for outbound traffic)
- Destination address/port (final destination)
- Protocol type (UDP/TCP)
DestroySession: Destroy specified sessionGetSessionStatus: Query real-time session status with media statistics (packet loss rate, latency, bytes forwarded)ListSessions: List all active sessions
-
Session State Monitoring
- Track detailed statistics per session:
- Inbound traffic stats (packets received, bytes, packet loss)
- Outbound traffic stats
- Session establishment time
- Last activity time
- Connection state (normal forwarding or error)
- Support periodic push to SIP controller or on-demand query
- Track detailed statistics per session:
-
Architecture Components
SessionManager: Responsible for session creation and destructionTransportAdapter: Handle UDP/TCP protocol differences with unified interfacegRPC Server: Handle control requestsStatistics Collector: Real-time media data collection
-
Traffic Forwarding Logic
- Establish two forwarding channels per session:
- Listen address → forward to destination address
- Handle reverse traffic from destination (optional)
- Maintain source IP/port to session mapping for UDP scenarios
- Establish two forwarding channels per session:
-
Configuration Parameters
- Local listen interface/address and port
- Proxy forward interface/address and port
- Destination endpoint address and port
- Protocol type (UDP or TCP)
- Optional: timeout settings, statistics reporting interval
-
Real-time Feedback Mechanism
- Passive query via
GetSessionStatus - Active push mode using gRPC streaming
- Notify SIP controller when session state changes or alert conditions trigger (e.g., high packet loss)
- Passive query via
-
Fault Handling
- Handle destination unreachable scenarios
- Network interruption handling
- Connection timeout handling
- Reconnection strategy and state transition logic (connecting, forwarding, error, closed states)
Requirement: Implement in Rust
Date: 2025-10-17
- Rust Edition: Use Rust 2024 Edition
- Comments and Logs: All comments and log messages must be in English
- Network Interface: Endpoint message should NOT include interface field (only address and port)
- Session ID: Session ID must be user-specified (string type) when creating a session via gRPC API, not auto-generated
- Logging: Log output must include file name and line number for debugging
Date: 2025-10-19
-
Commit Message Format: Follow conventional commits format
- Use prefixes:
feat:,fix:,chore:,docs:,refactor:, etc. - First line: concise summary (50-72 characters)
- Blank line, then detailed description with bullet points
- Use prefixes:
-
Commit Message Content:
- Must be in English
- Must NOT include auto-generated footers:
- ❌ Do NOT include:
🤖 Generated with [Claude Code](https://claude.com/claude-code) - ❌ Do NOT include:
Co-Authored-By: Claude <noreply@anthropic.com>
- ❌ Do NOT include:
- Should focus on what changed and why
-
Example:
feat: add RTCP support for UDP sessions - Implement automatic RTCP forwarding on port + 1 - Create separate RTCP sockets for each UDP session - Add dedicated async task for RTCP packet forwarding - Update documentation with RTCP details
-
Transport Layer:
- UDP: Fully implemented with dual-socket architecture
- TCP: Framework/placeholder implementation for future development
-
Concurrency Model:
- Lock-free statistics using atomic operations
- Broadcast channels for graceful shutdown
- DashMap for concurrent session storage
-
Statistics Tracking:
- Real-time atomic counters for packets and bytes
- Automatic packet loss rate calculation
- Per-session last activity timestamp
-
RTCP Support (UDP only):
- Automatic RTCP forwarding on port + 1
- Separate task for RTCP packet handling
- Same address as RTP, different port
-
Event System:
- Unbounded MPSC channels for event propagation
- Five event types: Created, StateChanged, StatsUpdate, Error, Closed
- Optional periodic statistics reporting
- TCP transport is a placeholder (not fully implemented)
- Latency metrics (avg_latency_ms) not yet calculated
- Primarily unidirectional traffic (client → destination)
- No packet validation or RTP header parsing
- Complete TCP transport implementation
- Bidirectional RTP traffic handling
- Packet validation and RTP header parsing
- Session persistence
- Authentication and authorization
- Rate limiting and traffic shaping
- Metrics export (Prometheus, etc.)
This document should be updated whenever new requirements or specifications are provided.