udpmux

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

The udpmux package contains the logic for multiplexing multiple WebRTC (ICE) connections over a single UDP socket.

Index

Constants

View Source
const ReceiveBufSize = 1500

ReceiveBufSize 是用于从 PacketConn 接收数据包的缓冲区大小。 这个值可以大于实际的路径 MTU,因为它不会用于决定写入路径上的数据包大小。

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	// Ufrag 是用户片段标识符
	Ufrag string
	// Addr 是候选者的 UDP 地址
	Addr *net.UDPAddr
}

Candidate 表示一个 ICE 候选者

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) Accept

func (mux *UDPMux) Accept(ctx context.Context) (Candidate, error)

Accept 接受新的候选者

参数:

  • ctx: context.Context 上下文

返回值:

  • Candidate 候选者
  • error 错误信息

func (*UDPMux) Close

func (mux *UDPMux) Close() error

Close 实现 ice.UDPMux 接口 关闭多路复用器

返回值:

  • error 错误信息

func (*UDPMux) GetConn

func (mux *UDPMux) GetConn(ufrag string, addr net.Addr) (net.PacketConn, error)

GetConn 实现 ice.UDPMux 接口 如果找不到现有连接,则为给定的 ufrag 创建一个 net.PacketConn。 我们区分 IPv4 和 IPv6 地址,因为远程可以在同一 IP 地址族的多个不同 UDP 地址上可达(例如服务器反射地址和对等反射地址)。

参数:

  • ufrag: string 用户片段标识符
  • addr: net.Addr 网络地址

返回值:

  • net.PacketConn 数据包连接
  • error 错误信息

func (*UDPMux) GetListenAddresses

func (mux *UDPMux) GetListenAddresses() []net.Addr

GetListenAddresses 实现 ice.UDPMux 接口 返回值:

  • []net.Addr 监听地址列表

func (*UDPMux) RemoveConnByUfrag

func (mux *UDPMux) RemoveConnByUfrag(ufrag string)

RemoveConnByUfrag 移除与 ufrag 关联的连接以及与该连接关联的所有地址。 当 peerconnection 关闭时,pion 会调用此方法。

参数:

  • ufrag: string 要移除的连接的 ufrag

func (*UDPMux) Start

func (mux *UDPMux) Start()

Start 启动多路复用器的读取循环

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL