Skip to content

Commit 8b8fffd

Browse files
WofWcaSean-Der
authored andcommitted
Use named return val for IP/if filter
This should make it clear that you need to return `true` to keep it and `false` to exclude. Relates to pion/webrtc#2958
1 parent 1c850ea commit 8b8fffd

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ type Agent struct {
138138
udpMux UDPMux
139139
udpMuxSrflx UniversalUDPMux
140140

141-
interfaceFilter func(string) bool
142-
ipFilter func(net.IP) bool
141+
interfaceFilter func(string) (keep bool)
142+
ipFilter func(net.IP) (keep bool)
143143
includeLoopback bool
144144

145145
insecureSkipVerify bool

agent_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ type AgentConfig struct {
148148

149149
// InterfaceFilter is a function that you can use in order to whitelist or blacklist
150150
// the interfaces which are used to gather ICE candidates.
151-
InterfaceFilter func(string) bool
151+
InterfaceFilter func(string) (keep bool)
152152

153153
// IPFilter is a function that you can use in order to whitelist or blacklist
154154
// the ips which are used to gather ICE candidates.
155-
IPFilter func(net.IP) bool
155+
IPFilter func(net.IP) (keep bool)
156156

157157
// InsecureSkipVerify controls if self-signed certificates are accepted when connecting
158158
// to TURN servers via TLS or DTLS

gather_vnet_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
387387
t.Run("InterfaceFilter should exclude the interface", func(t *testing.T) {
388388
a, err := NewAgent(&AgentConfig{
389389
Net: nw,
390-
InterfaceFilter: func(interfaceName string) bool {
390+
InterfaceFilter: func(interfaceName string) (keep bool) {
391391
require.Equal(t, "eth0", interfaceName)
392392
return false
393393
},
@@ -408,7 +408,7 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
408408
t.Run("IPFilter should exclude the IP", func(t *testing.T) {
409409
a, err := NewAgent(&AgentConfig{
410410
Net: nw,
411-
IPFilter: func(ip net.IP) bool {
411+
IPFilter: func(ip net.IP) (keep bool) {
412412
require.Equal(t, net.IP{1, 2, 3, 1}, ip)
413413
return false
414414
},
@@ -429,7 +429,7 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
429429
t.Run("InterfaceFilter should not exclude the interface", func(t *testing.T) {
430430
a, err := NewAgent(&AgentConfig{
431431
Net: nw,
432-
InterfaceFilter: func(interfaceName string) bool {
432+
InterfaceFilter: func(interfaceName string) (keep bool) {
433433
require.Equal(t, "eth0", interfaceName)
434434
return true
435435
},

net.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func isZeros(ip net.IP) bool {
3939
//nolint:gocognit
4040
func localInterfaces(
4141
n transport.Net,
42-
interfaceFilter func(string) bool,
43-
ipFilter func(net.IP) bool,
42+
interfaceFilter func(string) (keep bool),
43+
ipFilter func(net.IP) (keep bool),
4444
networkTypes []NetworkType,
4545
includeLoopback bool,
4646
) ([]*transport.Interface, []netip.Addr, error) {

net_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestCreateAddr(t *testing.T) {
4545
require.Equal(t, &net.TCPAddr{IP: ipv6.AsSlice(), Port: port}, createAddr(NetworkTypeTCP6, ipv6, port))
4646
}
4747

48-
func problematicNetworkInterfaces(s string) bool {
48+
func problematicNetworkInterfaces(s string) (keep bool) {
4949
defaultDockerBridgeNetwork := strings.Contains(s, "docker")
5050
customDockerBridgeNetwork := strings.Contains(s, "br-")
5151

udp_mux_multi.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ type UDPMuxFromPortOption interface {
141141
}
142142

143143
type multiUDPMuxFromPortParam struct {
144-
ifFilter func(string) bool
145-
ipFilter func(ip net.IP) bool
144+
ifFilter func(string) (keep bool)
145+
ipFilter func(ip net.IP) (keep bool)
146146
networks []NetworkType
147147
readBufferSize int
148148
writeBufferSize int
@@ -160,7 +160,7 @@ func (o *udpMuxFromPortOption) apply(p *multiUDPMuxFromPortParam) {
160160
}
161161

162162
// UDPMuxFromPortWithInterfaceFilter set the filter to filter out interfaces that should not be used
163-
func UDPMuxFromPortWithInterfaceFilter(f func(string) bool) UDPMuxFromPortOption {
163+
func UDPMuxFromPortWithInterfaceFilter(f func(string) (keep bool)) UDPMuxFromPortOption {
164164
return &udpMuxFromPortOption{
165165
f: func(p *multiUDPMuxFromPortParam) {
166166
p.ifFilter = f
@@ -169,7 +169,7 @@ func UDPMuxFromPortWithInterfaceFilter(f func(string) bool) UDPMuxFromPortOption
169169
}
170170

171171
// UDPMuxFromPortWithIPFilter set the filter to filter out IP addresses that should not be used
172-
func UDPMuxFromPortWithIPFilter(f func(ip net.IP) bool) UDPMuxFromPortOption {
172+
func UDPMuxFromPortWithIPFilter(f func(ip net.IP) (keep bool)) UDPMuxFromPortOption {
173173
return &udpMuxFromPortOption{
174174
f: func(p *multiUDPMuxFromPortParam) {
175175
p.ipFilter = f

0 commit comments

Comments
 (0)