package udpmux

import "github.com/libp2p/go-libp2p/p2p/transport/webrtc/udpmux"

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

Index

Constants

const ReceiveBufSize = 1500

ReceiveBufSize is the size of the buffer used to receive packets from the PacketConn. It is fine for this number to be higher than the actual path MTU as this value is not used to decide the packet size on the write path.

Types

type Candidate

type Candidate struct {
	Ufrag string
	Addr  *net.UDPAddr
}

type UDPMux

type UDPMux struct {
	// contains filtered or unexported fields
}

UDPMux multiplexes multiple ICE connections over a single net.PacketConn, generally a UDP socket.

The connections are indexed by (ufrag, IP address family) and by remote address from which the connection has received valid STUN/RTC packets.

When a new packet is received on the underlying net.PacketConn, we first check the address map to see if there is a connection associated with the remote address: If found, we pass the packet to that connection. Otherwise, we check to see if the packet is a STUN packet. If it is, we read the ufrag from the STUN packet and use it to check if there is a connection associated with the (ufrag, IP address family) pair. If found we add the association to the address map.

func NewUDPMux

func NewUDPMux(socket net.PacketConn) *UDPMux

func (*UDPMux) Accept

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

func (*UDPMux) Close

func (mux *UDPMux) Close() error

Close implements ice.UDPMux

func (*UDPMux) GetConn

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

GetConn implements ice.UDPMux It creates a net.PacketConn for a given ufrag if an existing one cannot be found. We differentiate IPv4 and IPv6 addresses, since a remote is can be reachable at multiple different UDP addresses of the same IP address family (eg. server-reflexive addresses and peer-reflexive addresses).

func (*UDPMux) GetListenAddresses

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

GetListenAddresses implements ice.UDPMux

func (*UDPMux) RemoveConnByUfrag

func (mux *UDPMux) RemoveConnByUfrag(ufrag string)

RemoveConnByUfrag removes the connection associated with the ufrag and all the addresses associated with that connection. This method is called by pion when a peerconnection is closed.

func (*UDPMux) Start

func (mux *UDPMux) Start()

Source Files

mux.go muxed_connection.go

Version
v0.41.1 (latest)
Published
Mar 24, 2025
Platform
linux/amd64
Imports
13 packages
Last checked
3 weeks ago

Tools for package owners.