mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Refactor muxs to muxes
As other locations in the code used muxes already before.
This commit is contained in:
+9
-9
@@ -17,14 +17,14 @@ type AllConnsGetter interface {
|
||||
// allowing users to pass multiple TCPMux instances to the ICE agent
|
||||
// configuration.
|
||||
type MultiTCPMuxDefault struct {
|
||||
muxs []TCPMux
|
||||
muxes []TCPMux
|
||||
}
|
||||
|
||||
// NewMultiTCPMuxDefault creates an instance of MultiTCPMuxDefault that
|
||||
// uses the provided TCPMux instances.
|
||||
func NewMultiTCPMuxDefault(muxs ...TCPMux) *MultiTCPMuxDefault {
|
||||
func NewMultiTCPMuxDefault(muxes ...TCPMux) *MultiTCPMuxDefault {
|
||||
return &MultiTCPMuxDefault{
|
||||
muxs: muxs,
|
||||
muxes: muxes,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,28 +35,28 @@ func NewMultiTCPMuxDefault(muxs ...TCPMux) *MultiTCPMuxDefault {
|
||||
func (m *MultiTCPMuxDefault) GetConnByUfrag(ufrag string, isIPv6 bool, local 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.
|
||||
if len(m.muxs) == 0 {
|
||||
if len(m.muxes) == 0 {
|
||||
return nil, errNoTCPMuxAvailable
|
||||
}
|
||||
return m.muxs[0].GetConnByUfrag(ufrag, isIPv6, local)
|
||||
return m.muxes[0].GetConnByUfrag(ufrag, isIPv6, local)
|
||||
}
|
||||
|
||||
// RemoveConnByUfrag stops and removes the muxed packet connection
|
||||
// from all underlying TCPMux instances.
|
||||
func (m *MultiTCPMuxDefault) RemoveConnByUfrag(ufrag string) {
|
||||
for _, mux := range m.muxs {
|
||||
for _, mux := range m.muxes {
|
||||
mux.RemoveConnByUfrag(ufrag)
|
||||
}
|
||||
}
|
||||
|
||||
// GetAllConns returns a PacketConn for each underlying TCPMux
|
||||
func (m *MultiTCPMuxDefault) GetAllConns(ufrag string, isIPv6 bool, local net.IP) ([]net.PacketConn, error) {
|
||||
if len(m.muxs) == 0 {
|
||||
if len(m.muxes) == 0 {
|
||||
// Make sure that we either return at least one connection or an error.
|
||||
return nil, errNoTCPMuxAvailable
|
||||
}
|
||||
var conns []net.PacketConn
|
||||
for _, mux := range m.muxs {
|
||||
for _, mux := range m.muxes {
|
||||
conn, err := mux.GetConnByUfrag(ufrag, isIPv6, local)
|
||||
if err != nil {
|
||||
// For now, this implementation is all or none.
|
||||
@@ -72,7 +72,7 @@ func (m *MultiTCPMuxDefault) GetAllConns(ufrag string, isIPv6 bool, local net.IP
|
||||
// Close the multi mux, no further connections could be created
|
||||
func (m *MultiTCPMuxDefault) Close() error {
|
||||
var err error
|
||||
for _, mux := range m.muxs {
|
||||
for _, mux := range m.muxes {
|
||||
if e := mux.Close(); e != nil {
|
||||
err = e
|
||||
}
|
||||
|
||||
+10
-10
@@ -14,21 +14,21 @@ import (
|
||||
// allowing users to pass multiple UDPMux instances to the ICE agent
|
||||
// configuration.
|
||||
type MultiUDPMuxDefault struct {
|
||||
muxs []UDPMux
|
||||
muxes []UDPMux
|
||||
localAddrToMux map[string]UDPMux
|
||||
}
|
||||
|
||||
// NewMultiUDPMuxDefault creates an instance of MultiUDPMuxDefault that
|
||||
// uses the provided UDPMux instances.
|
||||
func NewMultiUDPMuxDefault(muxs ...UDPMux) *MultiUDPMuxDefault {
|
||||
func NewMultiUDPMuxDefault(muxes ...UDPMux) *MultiUDPMuxDefault {
|
||||
addrToMux := make(map[string]UDPMux)
|
||||
for _, mux := range muxs {
|
||||
for _, mux := range muxes {
|
||||
for _, addr := range mux.GetListenAddresses() {
|
||||
addrToMux[addr.String()] = mux
|
||||
}
|
||||
}
|
||||
return &MultiUDPMuxDefault{
|
||||
muxs: muxs,
|
||||
muxes: muxes,
|
||||
localAddrToMux: addrToMux,
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func (m *MultiUDPMuxDefault) GetConn(ufrag string, addr net.Addr) (net.PacketCon
|
||||
// RemoveConnByUfrag stops and removes the muxed packet connection
|
||||
// from all underlying UDPMux instances.
|
||||
func (m *MultiUDPMuxDefault) RemoveConnByUfrag(ufrag string) {
|
||||
for _, mux := range m.muxs {
|
||||
for _, mux := range m.muxes {
|
||||
mux.RemoveConnByUfrag(ufrag)
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func (m *MultiUDPMuxDefault) RemoveConnByUfrag(ufrag string) {
|
||||
// Close the multi mux, no further connections could be created
|
||||
func (m *MultiUDPMuxDefault) Close() error {
|
||||
var err error
|
||||
for _, mux := range m.muxs {
|
||||
for _, mux := range m.muxes {
|
||||
if e := mux.Close(); e != nil {
|
||||
err = e
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (m *MultiUDPMuxDefault) Close() error {
|
||||
// GetListenAddresses returns the list of addresses that this mux is listening on
|
||||
func (m *MultiUDPMuxDefault) GetListenAddresses() []net.Addr {
|
||||
addrs := make([]net.Addr, 0, len(m.localAddrToMux))
|
||||
for _, mux := range m.muxs {
|
||||
for _, mux := range m.muxes {
|
||||
addrs = append(addrs, mux.GetListenAddresses()...)
|
||||
}
|
||||
return addrs
|
||||
@@ -109,13 +109,13 @@ func NewMultiUDPMuxFromPort(port int, opts ...UDPMuxFromPortOption) (*MultiUDPMu
|
||||
return nil, err
|
||||
}
|
||||
|
||||
muxs := make([]UDPMux, 0, len(conns))
|
||||
muxes := make([]UDPMux, 0, len(conns))
|
||||
for _, conn := range conns {
|
||||
mux := NewUDPMuxDefault(UDPMuxParams{Logger: params.logger, UDPConn: conn})
|
||||
muxs = append(muxs, mux)
|
||||
muxes = append(muxes, mux)
|
||||
}
|
||||
|
||||
return NewMultiUDPMuxDefault(muxs...), nil
|
||||
return NewMultiUDPMuxDefault(muxes...), nil
|
||||
}
|
||||
|
||||
// UDPMuxFromPortOption provide options for NewMultiUDPMuxFromPort
|
||||
|
||||
@@ -120,7 +120,7 @@ func TestUnspecifiedUDPMux(t *testing.T) {
|
||||
}))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.GreaterOrEqual(t, len(udpMuxMulti.muxs), 1, "at least have 1 muxs")
|
||||
require.GreaterOrEqual(t, len(udpMuxMulti.muxes), 1, "at least have 1 muxes")
|
||||
defer func() {
|
||||
_ = udpMuxMulti.Close()
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user