Overview
After gathering candidates, the ICE agent performs connectivity checks to find working candidate pairs:1
Pairing
Local and remote candidates are paired together based on component and foundation
2
Prioritization
Pairs are sorted by priority (controlling agent uses local + remote priority)
3
Connectivity Checks
STUN binding requests are sent to test each pair
4
Nomination
The controlling agent nominates a successful pair for use
Check Interval
The check interval controls how frequently the agent performs connectivity checks:The default check interval is 200ms as defined in
agent_config.go:18.Controlling vs Controlled
ICE agents operate in two roles:Controlling Agent
The controlling agent:- Nominates candidate pairs using the USE-CANDIDATE attribute
- Waits for minimum acceptance times before nomination
- Includes the ICE-CONTROLLING attribute in binding requests
Controlled Agent
The controlled agent:- Accepts nominations from the controlling agent
- Responds to binding requests with binding responses
- Includes the ICE-CONTROLLED attribute in binding requests
Candidate Pair States
Candidate pairs transition through several states:- Waiting - Pair created, waiting to be checked
- In Progress - Check in progress
- Succeeded - Check succeeded, pair is valid
- Failed - Check failed after max binding requests
Nomination Process
The controlling agent nominates pairs based on candidate type acceptance wait times:Nomination Logic
Fromselection.go:34:
Binding Requests
Connectivity checks use STUN binding requests:Controlling Agent Request
Nomination Request
Maximum Binding Requests
Control how many binding requests are sent before considering a pair failed:The default is 7 attempts as defined in
agent_config.go:48.Keepalive
Once a pair is selected, keepalive packets maintain the NAT binding:0 to disable keepalives:
Renomination
Pion ICE supports renomination as described in draft-thatcher-ice-renomination:How Renomination Works
- Controlling agent can renominate multiple times
- Each nomination includes an incrementing nomination value
- Controlled agent follows “last nomination wins” rule
- Allows switching to better paths after initial connection
Automatic Renomination
Automatically switch to better candidate pairs:- Wait at least 3 seconds after connection
- Continuously evaluate candidate pairs
- Automatically renominate when a significantly better pair is found (e.g., switching from relay to direct connection)
Automatic renomination requires renomination to be enabled and both agents to support it.
Custom Nomination Logic
Implement custom candidate pair switching with a binding request handler:Candidate Pair Priority
Pair priority is calculated based on the controlling role:Connection State Transitions
The ICE connection state transitions through:- New - Agent created
- Checking - Performing connectivity checks
- Connected - At least one working pair found
- Completed - All checks completed (optional)
- Failed - All checks failed
- Disconnected - Connection lost
- Closed - Agent closed
Selected Candidate Pair
Monitor when the selected candidate pair changes:Candidate Pair Statistics
Retrieve statistics about candidate pairs:Lite Agent Behavior
ICE Lite agents have simplified check behavior:- Do not perform connectivity checks
- Only provide host candidates
- Respond to incoming binding requests
- Accept nominations from full ICE agent
Example: Monitoring Connectivity
Here’s a complete example monitoring the connectivity check process:Troubleshooting
Checks Never Succeed
- Verify remote credentials are correct
- Check firewall rules allow UDP/TCP traffic
- Enable debug logging to see detailed check progress
- Try increasing max binding requests
Connection Takes Too Long
- Reduce candidate type acceptance wait times
- Disable unnecessary candidate types
- Use ICE Lite if appropriate for your deployment
Frequent Disconnections
- Increase keepalive interval if bandwidth is limited
- Check for network stability issues
- Review disconnected/failed timeout settings
Next Steps
Gathering
Learn about candidate gathering
NAT Traversal
Configure NAT traversal strategies
Multiplexing
Share ports with UDPMux and TCPMux
Examples
See connectivity checks in action