// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage iceimport ()// AllConnsGetter allows multiple fixed TCP ports to be used,// each of which is multiplexed like TCPMux. AllConnsGetter also acts as// a TCPMux, in which case it will return a single connection for one// of the ports.typeAllConnsGetterinterface {GetAllConns(ufrag string, isIPv6 bool, localIP net.IP) ([]net.PacketConn, error)}// MultiTCPMuxDefault implements both TCPMux and AllConnsGetter,// allowing users to pass multiple TCPMux instances to the ICE agent// configuration.typeMultiTCPMuxDefaultstruct { muxes []TCPMux}// NewMultiTCPMuxDefault creates an instance of MultiTCPMuxDefault that// uses the provided TCPMux instances.func ( ...TCPMux) *MultiTCPMuxDefault {return &MultiTCPMuxDefault{muxes: , }}// GetConnByUfrag returns a PacketConn given the connection's ufrag, network and local address// creates the connection if an existing one can't be found. This, unlike// GetAllConns, will only return a single PacketConn from the first mux that was// passed in to NewMultiTCPMuxDefault.func ( *MultiTCPMuxDefault) ( string, bool, net.IP) (net.PacketConn, error) {// NOTE: We always use the first element here in order to maintain the // behavior of using an existing connection if one exists.iflen(.muxes) == 0 {returnnil, errNoTCPMuxAvailable }return .muxes[0].GetConnByUfrag(, , )}// RemoveConnByUfrag stops and removes the muxed packet connection// from all underlying TCPMux instances.func ( *MultiTCPMuxDefault) ( string) {for , := range .muxes { .RemoveConnByUfrag() }}// GetAllConns returns a PacketConn for each underlying TCPMux.func ( *MultiTCPMuxDefault) ( string, bool, net.IP) ([]net.PacketConn, error) {iflen(.muxes) == 0 {// Make sure that we either return at least one connection or an error.returnnil, errNoTCPMuxAvailable }var []net.PacketConnfor , := range .muxes { , := .GetConnByUfrag(, , )if != nil {// For now, this implementation is all or none.returnnil, }if != nil { = append(, ) } }return , nil}// Close the multi mux, no further connections could be created.func ( *MultiTCPMuxDefault) () error {varerrorfor , := range .muxes {if := .Close(); != nil { = } }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.