Overview
ICE candidates represent potential network paths for establishing peer-to-peer connections. The Pion ICE library provides a comprehensive type system for working with different candidate types defined in RFC 8445.Candidate Interface
TheCandidate interface defines the core functionality shared by all candidate types.
Interface Definition
candidate.go
Key Methods
Returns an arbitrary string used in the freezing algorithm to group similar candidates. It is the same for two candidates that have the same type, base IP address, protocol (UDP, TCP, etc.), and STUN or TURN server.
Returns a unique identifier for this candidate. Unlike the foundation, this is different for each candidate instance.
Returns the component identifier. A component is a piece of a data stream. Common values are
ComponentRTP (1) for RTP and ComponentRTCP (2) for RTCP.Returns the last time this candidate received traffic.
Returns the last time this candidate sent traffic.
Returns the network type (UDP4, UDP6, TCP4, or TCP6) for this candidate.
Returns the IP address of the candidate.
Returns the port number of the candidate.
Returns the priority value for this candidate. Priority is computed according to RFC 8445 Section 5.1.2.1.
Returns a transport address related to the candidate, useful for diagnostics and other purposes. For reflexive and relay candidates, this is the base address.
Returns the type of this candidate (host, srflx, prflx, or relay).
Returns the string representation of the candidate in SDP format.
CandidateType Enum
TheCandidateType represents the different types of ICE candidates.
candidatetype.go
Type Values
Represents a host candidate - a candidate obtained directly from a local interface.
Represents a server reflexive candidate (srflx) - a candidate whose IP address and port are a binding allocated by a STUN server.
Represents a peer reflexive candidate (prflx) - a candidate whose IP address and port are a binding allocated by a NAT, discovered through connectivity checks.
Represents a relay candidate - a candidate obtained from a TURN server.
Methods
Returns the string representation: “host”, “srflx”, “prflx”, or “relay”.
Returns the type preference value used in priority calculation. Returns 126 for host, 110 for peer reflexive, 100 for server reflexive, and 0 for relay candidates.
CandidateBase
ThecandidateBase struct provides common functionality for all candidate types. It is embedded in all concrete candidate implementations.
Priority Calculation
Candidate priority is calculated according to RFC 8445:Foundation Calculation
The foundation is computed as a CRC32 checksum of the candidate type, base address, and network type, unless explicitly overridden.CandidateRelatedAddress
Conveys transport addresses related to the candidate, useful for diagnostics.candidaterelatedaddress.go
The related IP address.
The related port number.
CandidateExtension
Represents a single candidate extension as defined in RFC 5245 Section 15.1.candidate_base.go
The extension attribute name.
The extension attribute value.
NetworkType
Represents the network protocol and IP version for a candidate.networktype.go
Methods
Returns true when network is UDP4 or UDP6.
Returns true when network is TCP4 or TCP6.
Returns true when network is IPv4 (UDP4 or TCP4).
Returns true when network is IPv6 (UDP6 or TCP6).
Component Constants
candidate.go
Indicates that the candidate is used for RTP (value: 1).
Indicates that the candidate is used for RTCP (value: 2).
Unmarshaling Candidates
Parse a candidate from its string representation:Example
The
UnmarshalCandidate function accepts candidates with or without the “candidate:” prefix as defined in RFC 5245 Section 15.1.