Skip to main content

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

The Candidate interface defines the core functionality shared by all candidate types.

Interface Definition

candidate.go

Key Methods

string
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.
string
Returns a unique identifier for this candidate. Unlike the foundation, this is different for each candidate instance.
uint16
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.
time.Time
Returns the last time this candidate received traffic.
time.Time
Returns the last time this candidate sent traffic.
NetworkType
Returns the network type (UDP4, UDP6, TCP4, or TCP6) for this candidate.
string
Returns the IP address of the candidate.
int
Returns the port number of the candidate.
uint32
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.
CandidateType
Returns the type of this candidate (host, srflx, prflx, or relay).
string
Returns the string representation of the candidate in SDP format.

CandidateType Enum

The CandidateType represents the different types of ICE candidates.
candidatetype.go

Type Values

CandidateType
Represents a host candidate - a candidate obtained directly from a local interface.
CandidateType
Represents a server reflexive candidate (srflx) - a candidate whose IP address and port are a binding allocated by a STUN server.
CandidateType
Represents a peer reflexive candidate (prflx) - a candidate whose IP address and port are a binding allocated by a NAT, discovered through connectivity checks.
CandidateType
Represents a relay candidate - a candidate obtained from a TURN server.

Methods

string
Returns the string representation: “host”, “srflx”, “prflx”, or “relay”.
uint16
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

The candidateBase 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
string
The related IP address.
int
The related port number.

CandidateExtension

Represents a single candidate extension as defined in RFC 5245 Section 15.1.
candidate_base.go
string
The extension attribute name.
string
The extension attribute value.

NetworkType

Represents the network protocol and IP version for a candidate.
networktype.go

Methods

bool
Returns true when network is UDP4 or UDP6.
bool
Returns true when network is TCP4 or TCP6.
bool
Returns true when network is IPv4 (UDP4 or TCP4).
bool
Returns true when network is IPv6 (UDP6 or TCP6).

Component Constants

candidate.go
uint16
Indicates that the candidate is used for RTP (value: 1).
uint16
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.