Documentation ¶
Overview ¶
The udpmux package contains the logic for multiplexing multiple WebRTC (ICE) connections over a single UDP socket.
Index ¶
- Constants
- type Candidate
- type UDPMux
- func (mux *UDPMux) Accept(ctx context.Context) (Candidate, error)
- func (mux *UDPMux) Close() error
- func (mux *UDPMux) GetConn(ufrag string, addr net.Addr) (net.PacketConn, error)
- func (mux *UDPMux) GetListenAddresses() []net.Addr
- func (mux *UDPMux) RemoveConnByUfrag(ufrag string)
- func (mux *UDPMux) Start()
Constants ¶
const ReceiveBufSize = 1500
ReceiveBufSize 是用于从 PacketConn 接收数据包的缓冲区大小。 这个值可以大于实际的路径 MTU,因为它不会用于决定写入路径上的数据包大小。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type UDPMux ¶
type UDPMux struct {
// contains filtered or unexported fields
}
UDPMux 在单个 net.PacketConn(通常是 UDP socket)上多路复用多个 ICE 连接。
连接通过(ufrag, IP 地址族)和接收到有效 STUN/RTC 数据包的远程地址进行索引。
当在底层 net.PacketConn 上收到新数据包时,我们首先检查地址映射以查看是否有与远程地址关联的连接: 如果找到,我们将数据包传递给该连接。 否则,我们检查数据包是否为 STUN 数据包。 如果是,我们从 STUN 数据包中读取 ufrag 并使用它来检查是否有与(ufrag, IP 地址族)对关联的连接。 如果找到,我们将关联添加到地址映射中。
func NewUDPMux ¶
func NewUDPMux(socket net.PacketConn) *UDPMux
NewUDPMux 创建一个新的 UDP 多路复用器 参数:
- socket: net.PacketConn 底层的数据包连接
返回值:
- *UDPMux 新创建的 UDP 多路复用器
func (*UDPMux) GetConn ¶
GetConn 实现 ice.UDPMux 接口 如果找不到现有连接,则为给定的 ufrag 创建一个 net.PacketConn。 我们区分 IPv4 和 IPv6 地址,因为远程可以在同一 IP 地址族的多个不同 UDP 地址上可达(例如服务器反射地址和对等反射地址)。
参数:
- ufrag: string 用户片段标识符
- addr: net.Addr 网络地址
返回值:
- net.PacketConn 数据包连接
- error 错误信息
func (*UDPMux) RemoveConnByUfrag ¶
RemoveConnByUfrag 移除与 ufrag 关联的连接以及与该连接关联的所有地址。 当 peerconnection 关闭时,pion 会调用此方法。
参数:
- ufrag: string 要移除的连接的 ufrag