Skip to content

Commit

Permalink
Refactor muxs to muxes
Browse files Browse the repository at this point in the history
As other locations in the code used muxes already before.
  • Loading branch information
stv0g committed Nov 13, 2022
1 parent dc5bce4 commit 2b0f884
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions tcp_mux_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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.
Expand All @@ -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
}
Expand Down
20 changes: 10 additions & 10 deletions udp_mux_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -46,15 +46,15 @@ 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)
}
}

// 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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion udp_mux_multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
Expand Down

0 comments on commit 2b0f884

Please sign in to comment.