Skip to main content

Overview

Deprecated: Use NewAgentWithOptions with functional options instead. This struct will be removed in a future major release.
AgentConfig collects arguments for ICE Agent construction into a single structure. It provides backward compatibility but is less flexible than the functional options pattern.

Type Definition

type AgentConfig struct {
    Urls                         []*stun.URI
    PortMin                      uint16
    PortMax                      uint16
    LocalUfrag                   string
    LocalPwd                     string
    MulticastDNSMode             MulticastDNSMode
    MulticastDNSHostName         string
    DisconnectedTimeout          *time.Duration
    FailedTimeout                *time.Duration
    KeepaliveInterval            *time.Duration
    CheckInterval                *time.Duration
    NetworkTypes                 []NetworkType
    CandidateTypes               []CandidateType
    LoggerFactory                logging.LoggerFactory
    MaxBindingRequests           *uint16
    Lite                         bool
    NAT1To1IPCandidateType       CandidateType // Deprecated
    NAT1To1IPs                   []string      // Deprecated
    HostAcceptanceMinWait        *time.Duration
    SrflxAcceptanceMinWait       *time.Duration
    PrflxAcceptanceMinWait       *time.Duration
    RelayAcceptanceMinWait       *time.Duration
    STUNGatherTimeout            *time.Duration
    Net                          transport.Net
    InterfaceFilter              func(string) bool
    IPFilter                     func(net.IP) bool
    InsecureSkipVerify           bool
    TCPMux                       TCPMux
    UDPMux                       UDPMux
    UDPMuxSrflx                  UniversalUDPMux
    ProxyDialer                  proxy.Dialer
    AcceptAggressiveNomination   bool // Deprecated
    IncludeLoopback              bool
    TCPPriorityOffset            *uint16
    DisableActiveTCP             bool
    BindingRequestHandler        func(*stun.Message, Candidate, Candidate, *CandidatePair) bool
    EnableUseCandidateCheckPriority bool
}

Fields

Network Configuration

Urls
[]*stun.URI
List of STUN/TURN server URLs for gathering server reflexive and relay candidates.
PortMin
uint16
default:"0"
Minimum UDP port for host candidates. 0 allows the OS to choose.
PortMax
uint16
default:"0"
Maximum UDP port for host candidates. 0 allows the OS to choose.
NetworkTypes
[]NetworkType
Enabled network types for gathering. Empty enables all types (UDP4, UDP6, TCP4, TCP6).
CandidateTypes
[]CandidateType
Enabled candidate types. Default: host, server reflexive, and relay.

Credentials

LocalUfrag
string
Local username fragment. Must have at least 24 bits of entropy if specified.
LocalPwd
string
Local password. Must have at least 128 bits of entropy if specified.

Timeouts

DisconnectedTimeout
*time.Duration
default:"5s"
Duration before transitioning to disconnected state. Set to 0 to disable.
FailedTimeout
*time.Duration
default:"25s"
Duration after disconnected before transitioning to failed. Set to 0 to disable.
KeepaliveInterval
*time.Duration
default:"2s"
Interval for sending keepalive packets. Set to 0 to disable.
CheckInterval
*time.Duration
default:"200ms"
How often to run connectivity checks while connecting.
STUNGatherTimeout
*time.Duration
default:"5s"
Wait time for STUN server responses during gathering.

Candidate Acceptance

HostAcceptanceMinWait
*time.Duration
default:"0"
Minimum wait before selecting host candidates.
SrflxAcceptanceMinWait
*time.Duration
default:"500ms"
Minimum wait before selecting server reflexive candidates.
PrflxAcceptanceMinWait
*time.Duration
default:"1s"
Minimum wait before selecting peer reflexive candidates.
RelayAcceptanceMinWait
*time.Duration
default:"2s"
Minimum wait before selecting relay candidates.

Multicast DNS

MulticastDNSMode
MulticastDNSMode
default:"QueryOnly"
Controls mDNS behavior for local candidate resolution.
MulticastDNSHostName
string
Hostname for mDNS. Must end with “.local”. Auto-generated if empty.

Advanced Options

MaxBindingRequests
*uint16
default:"7"
Maximum binding requests before considering a candidate pair failed.
Lite
bool
default:"false"
Enable ICE-lite mode. Lite agents only gather host candidates and don’t perform connectivity checks.
IncludeLoopback
bool
default:"false"
Include loopback addresses in candidate gathering.
DisableActiveTCP
bool
default:"false"
Disable creation of active TCP candidates.
TCPPriorityOffset
*uint16
default:"27"
Value subtracted from TCP candidate priorities relative to UDP.
InsecureSkipVerify
bool
default:"false"
Skip certificate verification for TLS/DTLS TURN connections.
EnableUseCandidateCheckPriority
bool
default:"false"
For lite agents, check priority before switching pairs on USE-CANDIDATE.

Deprecated Fields

NAT1To1IPs
[]string
Deprecated: Use WithAddressRewriteRules option instead.
List of public IP addresses for 1:1 NAT mapping.
NAT1To1IPCandidateType
CandidateType
Deprecated: Use WithAddressRewriteRules option instead.
Candidate type for NAT1To1IPs (host or srflx).
AcceptAggressiveNomination
bool
Deprecated: Always enabled.
Accept aggressive nomination from peer.

Filters and Handlers

InterfaceFilter
func(string) bool
Function to whitelist/blacklist network interfaces by name.
IPFilter
func(net.IP) bool
Function to whitelist/blacklist IP addresses.
BindingRequestHandler
func(*stun.Message, Candidate, Candidate, *CandidatePair) bool
Custom handler for incoming STUN binding requests.

Multiplexing

TCPMux
TCPMux
TCP multiplexer for ICE-TCP. See TCPMux.
UDPMux
UDPMux
UDP multiplexer for host candidates. See UDPMux.
UDPMuxSrflx
UniversalUDPMux
UDP multiplexer for server reflexive candidates. See UniversalUDPMux.

Transport

Net
transport.Net
Custom network implementation (for testing or virtual networks).
ProxyDialer
proxy.Dialer
Proxy dialer for TURN connections through corporate proxies.

Logging

LoggerFactory
logging.LoggerFactory
Logger factory for creating structured loggers.

Migration Guide

config := &ice.AgentConfig{
    Urls: []*stun.URI{stunURL},
    PortMin: 10000,
    PortMax: 20000,
    NetworkTypes: []ice.NetworkType{
        ice.NetworkTypeUDP4,
    },
}
agent, err := ice.NewAgent(config)

Build docs developers (and LLMs) love