Documentation ¶
Overview ¶
Package ice implements the Interactive Connectivity Establishment (ICE) protocol defined in rfc5245.
Index ¶
- Constants
- Variables
- type Agent
- func (a *Agent) Accept(ctx context.Context, remoteUfrag, remotePwd string) (*Conn, error)
- func (a *Agent) AddRemoteCandidate(c *Candidate) error
- func (a *Agent) Close() error
- func (a *Agent) Dial(ctx context.Context, remoteUfrag, remotePwd string) (*Conn, error)
- func (a *Agent) GetLocalCandidates() ([]*Candidate, error)
- func (a *Agent) GetLocalUserCredentials() (frag string, pwd string)
- func (a *Agent) OnConnectionStateChange(f func(ConnectionState)) error
- func (a *Agent) OnSelectedCandidatePairChange(f func(*Candidate, *Candidate)) error
- type AgentConfig
- type Candidate
- func NewCandidateHost(network string, ip net.IP, port int, component uint16) (*Candidate, error)
- func NewCandidatePeerReflexive(network string, ip net.IP, port int, component uint16, relAddr string, ...) (*Candidate, error)
- func NewCandidateRelay(network string, ip net.IP, port int, component uint16, relAddr string, ...) (*Candidate, error)
- func NewCandidateServerReflexive(network string, ip net.IP, port int, component uint16, relAddr string, ...) (*Candidate, error)
- type CandidateRelatedAddress
- type CandidateType
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(p []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(p []byte) (int, error)
- type ConnectionState
- type GatheringState
- type NetworkType
- type ProtoType
- type SchemeType
- type URL
Constants ¶
const ( // ComponentRTP indicates that the candidate is used for RTP ComponentRTP uint16 = 1 // ComponentRTCP indicates that the candidate is used for RTCP ComponentRTCP )
const ( // ConnectionStateNew ICE agent is gathering addresses ConnectionStateNew = iota + 1 // ConnectionStateChecking ICE agent has been given local and remote candidates, and is attempting to find a match ConnectionStateChecking // ConnectionStateConnected ICE agent has a pairing, but is still checking other pairs ConnectionStateConnected // ConnectionStateCompleted ICE agent has finished ConnectionStateCompleted // ConnectionStateFailed ICE agent never could successfully connect ConnectionStateFailed // ConnectionStateDisconnected ICE agent connected successfully, but has entered a failed state ConnectionStateDisconnected // ConnectionStateClosed ICE agent has finished and is no longer handling requests ConnectionStateClosed )
List of supported States
const Unknown = iota
Unknown defines default public constant to use for "enum" like struct comparisons when no value was defined.
Variables ¶
var ( // ErrUnknownType indicates an error with Unknown info. ErrUnknownType = errors.New("Unknown") // ErrSchemeType indicates the scheme type could not be parsed. ErrSchemeType = errors.New("unknown scheme type") // ErrSTUNQuery indicates query arguments are provided in a STUN URL. ErrSTUNQuery = errors.New("queries not supported in stun address") // ErrInvalidQuery indicates an malformed query is provided. ErrInvalidQuery = errors.New("invalid query") // ErrHost indicates malformed hostname is provided. ErrHost = errors.New("invalid hostname") // ErrPort indicates malformed port is provided. ErrPort = errors.New("invalid port") // ErrProtoType indicates an unsupported transport type was provided. ErrProtoType = errors.New("invalid transport protocol type") // ErrClosed indicates the agent is closed ErrClosed = errors.New("the agent is closed") // ErrNoCandidatePairs indicates agent does not have a valid candidate pair ErrNoCandidatePairs = errors.New("no candidate pairs available") // ErrCanceledByCaller indicates agent connection was canceled by the caller ErrCanceledByCaller = errors.New("connecting canceled by caller") // ErrMultipleStart indicates agent was started twice ErrMultipleStart = errors.New("attempted to start agent twice") // ErrRemoteUfragEmpty indicates agent was started with an empty remote ufrag ErrRemoteUfragEmpty = errors.New("remote ufrag is empty") // ErrRemotePwdEmpty indicates agent was started with an empty remote pwd ErrRemotePwdEmpty = errors.New("remote pwd is empty") )
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent represents the ICE agent
func (*Agent) Accept ¶
Accept connects to the remote agent, acting as the controlled ice agent. Accept blocks until at least one ice candidate pair has successfully connected.
func (*Agent) AddRemoteCandidate ¶
AddRemoteCandidate adds a new remote candidate
func (*Agent) Dial ¶
Dial connects to the remote agent, acting as the controlling ice agent. Dial blocks until at least one ice candidate pair has successfully connected.
func (*Agent) GetLocalCandidates ¶
GetLocalCandidates returns the local candidates
func (*Agent) GetLocalUserCredentials ¶
GetLocalUserCredentials returns the local user credentials
func (*Agent) OnConnectionStateChange ¶
func (a *Agent) OnConnectionStateChange(f func(ConnectionState)) error
OnConnectionStateChange sets a handler that is fired when the connection state changes
type AgentConfig ¶
type AgentConfig struct { Urls []*URL // PortMin and PortMax are optional. Leave them 0 for the default UDP port allocation strategy. PortMin uint16 PortMax uint16 // ConnectionTimeout defaults to 30 seconds when this property is nil. // If the duration is 0, we will never timeout this connection. ConnectionTimeout *time.Duration // KeepaliveInterval determines how often should we send ICE // keepalives (should be less then connectiontimeout above) // when this is nil, it defaults to 10 seconds. // A keepalive interval of 0 means we never send keepalive packets KeepaliveInterval *time.Duration // NetworkTypes is an optional configuration for disabling or enablding // support for specific network types. NetworkTypes []NetworkType LoggerFactory logging.LoggerFactory // contains filtered or unexported fields }
AgentConfig collects the arguments to ice.Agent construction into a single structure, for future-proofness of the interface
type Candidate ¶
type Candidate struct { NetworkType Type CandidateType LocalPreference uint16 Component uint16 IP net.IP Port int RelatedAddress *CandidateRelatedAddress // contains filtered or unexported fields }
Candidate represents an ICE candidate
func NewCandidateHost ¶
NewCandidateHost creates a new host candidate
func NewCandidatePeerReflexive ¶
func NewCandidatePeerReflexive(network string, ip net.IP, port int, component uint16, relAddr string, relPort int) (*Candidate, error)
NewCandidatePeerReflexive creates a new peer reflective candidate
func NewCandidateRelay ¶
func NewCandidateRelay(network string, ip net.IP, port int, component uint16, relAddr string, relPort int) (*Candidate, error)
NewCandidateRelay creates a new relay candidate
func NewCandidateServerReflexive ¶
func NewCandidateServerReflexive(network string, ip net.IP, port int, component uint16, relAddr string, relPort int) (*Candidate, error)
NewCandidateServerReflexive creates a new server reflective candidate
func (*Candidate) LastReceived ¶
LastReceived returns a time.Time indicating the last time this candidate was received
func (*Candidate) LastSent ¶
LastSent returns a time.Time indicating the last time this candidate was sent
type CandidateRelatedAddress ¶
CandidateRelatedAddress convey transport addresses related to the candidate, useful for diagnostics and other purposes.
func (*CandidateRelatedAddress) Equal ¶
func (c *CandidateRelatedAddress) Equal(other *CandidateRelatedAddress) bool
Equal allows comparing two CandidateRelatedAddresses. The CandidateRelatedAddress are allowed to be nil.
func (*CandidateRelatedAddress) String ¶
func (c *CandidateRelatedAddress) String() string
String makes CandidateRelatedAddress printable
type CandidateType ¶
type CandidateType byte
CandidateType represents the type of candidate
const ( CandidateTypeHost CandidateType = iota + 1 CandidateTypeServerReflexive CandidateTypePeerReflexive CandidateTypeRelay )
CandidateType enum
func (CandidateType) Preference ¶
func (c CandidateType) Preference() uint16
Preference returns the preference weight of a CandidateType
4.1.2.2. Guidelines for Choosing Type and Local Preferences The RECOMMENDED values are 126 for host candidates, 100 for server reflexive candidates, 110 for peer reflexive candidates, and 0 for relayed candidates.
func (CandidateType) String ¶
func (c CandidateType) String() string
String makes CandidateType printable
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents the ICE connection. At the moment the lifetime of the Conn is equal to the Agent.
func (*Conn) Close ¶
Close implements the Conn Close method. It is used to close the connection. Any calls to Read and Write will be unblocked and return an error.
func (*Conn) SetReadDeadline ¶
SetReadDeadline is a stub
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline is a stub
type ConnectionState ¶
type ConnectionState int
ConnectionState is an enum showing the state of a ICE Connection
func (ConnectionState) String ¶
func (c ConnectionState) String() string
type GatheringState ¶
type GatheringState int
GatheringState describes the state of the candidate gathering process
const ( // GatheringStateNew indicates candidate gatering is not yet started GatheringStateNew GatheringState = iota + 1 // GatheringStateGathering indicates candidate gatering is ongoing GatheringStateGathering // GatheringStateComplete indicates candidate gatering has been completed GatheringStateComplete )
func (GatheringState) String ¶
func (t GatheringState) String() string
type NetworkType ¶
type NetworkType int
NetworkType represents the type of network
const ( // NetworkTypeUDP4 indicates UDP over IPv4. NetworkTypeUDP4 NetworkType = iota + 1 // NetworkTypeUDP6 indicates UDP over IPv6. NetworkTypeUDP6 // NetworkTypeTCP4 indicates TCP over IPv4. NetworkTypeTCP4 // NetworkTypeTCP6 indicates TCP over IPv6. NetworkTypeTCP6 )
func (NetworkType) IsIPv4 ¶
func (t NetworkType) IsIPv4() bool
IsIPv4 returns whether the network type is IPv4 or not.
func (NetworkType) IsIPv6 ¶
func (t NetworkType) IsIPv6() bool
IsIPv6 returns whether the network type is IPv6 or not.
func (NetworkType) IsReliable ¶
func (t NetworkType) IsReliable() bool
IsReliable returns true if the network is reliable
func (NetworkType) NetworkShort ¶
func (t NetworkType) NetworkShort() string
NetworkShort returns the short network description
func (NetworkType) String ¶
func (t NetworkType) String() string
type ProtoType ¶
type ProtoType int
ProtoType indicates the transport protocol type that is used in the ice.URL structure.
func NewProtoType ¶
NewProtoType defines a procedure for creating a new ProtoType from a raw string naming the transport protocol type.
type SchemeType ¶
type SchemeType int
SchemeType indicates the type of server used in the ice.URL structure.
const ( // SchemeTypeSTUN indicates the URL represents a STUN server. SchemeTypeSTUN SchemeType = iota + 1 // SchemeTypeSTUNS indicates the URL represents a STUNS (secure) server. SchemeTypeSTUNS // SchemeTypeTURN indicates the URL represents a TURN server. SchemeTypeTURN // SchemeTypeTURNS indicates the URL represents a TURNS (secure) server. SchemeTypeTURNS )
func NewSchemeType ¶
func NewSchemeType(raw string) SchemeType
NewSchemeType defines a procedure for creating a new SchemeType from a raw string naming the scheme type.
func (SchemeType) String ¶
func (t SchemeType) String() string
type URL ¶
type URL struct { Scheme SchemeType Host string Port int Proto ProtoType }
URL represents a STUN (rfc7064) or TURN (rfc7065) URL
func ParseURL ¶
ParseURL parses a STUN or TURN urls following the ABNF syntax described in https://tools.ietf.org/html/rfc7064 and https://tools.ietf.org/html/rfc7065 respectively.