Overview
Peer reflexive candidates (prflx) are discovered dynamically during ICE connectivity checks rather than being gathered upfront. They represent NAT bindings that are learned when receiving connectivity checks from the remote peer.CandidatePeerReflexive
A peer reflexive candidate represents a public address binding discovered through connectivity checks.candidate_peer_reflexive.go
candidateBase which provides common functionality including priority calculation, marshaling, and traffic tracking.
Creating Peer Reflexive Candidates
NewCandidatePeerReflexive
Creates a new peer reflexive candidate from the provided configuration.Configuration for the peer reflexive candidate.
CandidatePeerReflexive or an error if the configuration is invalid (e.g., invalid IP address).
CandidatePeerReflexiveConfig
Configuration structure for creating peer reflexive candidates.candidate_peer_reflexive.go
Configuration Fields
Unique identifier for the candidate. If empty, a UUID will be automatically generated.
Network protocol: “udp”, “tcp”, “udp4”, “udp6”, “tcp4”, or “tcp6”.
The IP address observed in the connectivity check (the reflexive address).
Port number of the observed address.
Component identifier. Use
ComponentRTP (1) for RTP or ComponentRTCP (2) for RTCP.Custom priority value. If 0, priority will be calculated automatically. Peer reflexive candidates have a type preference of 110.
Custom foundation string. If empty, foundation will be calculated as a CRC32 checksum of the candidate type, address, and network type.
The base (local) IP address that received the connectivity check.
The port of the base (local) address.
Examples
Creating a Peer Reflexive Candidate
Accessing Candidate Properties
Creating an IPv6 Peer Reflexive Candidate
Discovery Process
Peer reflexive candidates are not gathered upfront like host or server reflexive candidates. Instead, they are discovered dynamically during the ICE connectivity check phase:How Discovery Works
- Connectivity Check Sent - The remote peer sends a STUN Binding Request from one of its candidates
- NAT Creates Binding - If the remote peer is behind a NAT, the NAT creates a new binding for the outgoing packet
- Request Received - The local agent receives the request and observes the source IP and port
- Address Comparison - If the observed source address differs from the remote candidate’s address in the request, a peer reflexive candidate is created
- Candidate Added - The new peer reflexive candidate is added to the remote candidate list and checked
Example Discovery Scenario
Priority Calculation
Peer reflexive candidates have a type preference of 110:- Higher than server reflexive candidates (100)
- Higher than relay candidates (0)
- Lower than host candidates (126)
When Peer Reflexive Candidates Appear
Peer reflexive candidates are discovered in several scenarios:Symmetric NAT Scenario
With symmetric NATs, each destination gets a unique binding. Server reflexive candidates show the binding to the STUN server, while peer reflexive candidates show the binding to the actual peer.
Hair-Pinning NAT
When both peers are behind the same NAT:Use Cases
Peer reflexive candidates are particularly useful when:- Working with symmetric NATs that allocate different bindings per destination
- The STUN server binding differs from the peer-to-peer binding
- Hair-pinning occurs with peers behind the same NAT
- Network path changes during the connection process
- Additional NAT layers exist between STUN server and peer
Related Address
The related address for a peer reflexive candidate is the base (host) candidate that received the connectivity check:- Understanding the network topology
- Debugging connectivity issues
- Analyzing NAT behavior
- Troubleshooting symmetric NAT scenarios
Connection Characteristics
Advantages:- Often represents better network path than server reflexive
- Discovered during actual peer-to-peer attempts
- Essential for symmetric NAT traversal
- No dependency on STUN servers after discovery
- Direct peer-to-peer connectivity
- Not available during candidate gathering
- Discovered only during connectivity checks
- Adds complexity to ICE state machine
- May increase connection establishment time
Comparison with Server Reflexive
| Aspect | Peer Reflexive | Server Reflexive |
|---|---|---|
| Discovery Time | During connectivity checks | During gathering phase |
| Discovery Method | From peer’s STUN requests | From STUN server responses |
| Priority | 110 (higher) | 100 (lower) |
| Use Case | Symmetric NAT scenarios | General NAT traversal |
| Availability | After checks start | Before checks start |
Best Practices
Automatic Discovery
Peer reflexive candidates are typically discovered automatically by the ICE agent. You don’t usually need to create them manually:Manual Creation
In advanced scenarios, you might create peer reflexive candidates manually when implementing custom ICE logic:Most applications don’t need to manually create peer reflexive candidates. The ICE agent discovers and manages them automatically during connectivity checks.
Debugging
When debugging peer reflexive candidates:- NAT mapping behavior
- Whether symmetric NAT is in use
- The relationship between local and public addresses
- Priority ordering in candidate pair selection
See Also
- Candidate Types - Core candidate interfaces and types
- Server Reflexive Candidates - STUN-based discovery
- Host Candidates - Direct local interface candidates
- Relay Candidates - TURN-based relay candidates