Add ipfilter to exclude ip from candidates gather (#1052)
This commit is contained in:
@@ -64,6 +64,7 @@ type RTCConfig struct {
|
||||
UseExternalIP bool `yaml:"use_external_ip"`
|
||||
UseICELite bool `yaml:"use_ice_lite,omitempty"`
|
||||
Interfaces InterfacesConfig `yaml:"interfaces"`
|
||||
IPs IPsConfig `yaml:"ips"`
|
||||
|
||||
// Number of packets to buffer for NACK
|
||||
PacketBufferSize int `yaml:"packet_buffer_size,omitempty"`
|
||||
@@ -107,6 +108,11 @@ type InterfacesConfig struct {
|
||||
Excludes []string `yaml:"excludes"`
|
||||
}
|
||||
|
||||
type IPsConfig struct {
|
||||
Includes []string `yaml:"includes"`
|
||||
Excludes []string `yaml:"excludes"`
|
||||
}
|
||||
|
||||
type AudioConfig struct {
|
||||
// minimum level to be considered active, 0-127, where 0 is loudest
|
||||
ActiveLevel uint8 `yaml:"active_level"`
|
||||
|
||||
@@ -227,6 +227,49 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
||||
})
|
||||
}
|
||||
|
||||
if len(rtcConf.IPs.Includes) != 0 || len(rtcConf.IPs.Excludes) != 0 {
|
||||
var ipnets [2][]*net.IPNet
|
||||
for i, ips := range [][]string{rtcConf.IPs.Includes, rtcConf.IPs.Excludes} {
|
||||
ipnets[i], err = func(fromIPs []string) ([]*net.IPNet, error) {
|
||||
var toNets []*net.IPNet
|
||||
for _, ip := range fromIPs {
|
||||
_, ipnet, err := net.ParseCIDR(ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
toNets = append(toNets, ipnet)
|
||||
}
|
||||
return toNets, nil
|
||||
}(ips)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
includes, excludes := ipnets[0], ipnets[1]
|
||||
|
||||
s.SetIPFilter(func(ip net.IP) bool {
|
||||
if len(includes) > 0 {
|
||||
for _, ipn := range includes {
|
||||
if ipn.Contains(ip) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if len(excludes) > 0 {
|
||||
for _, ipn := range excludes {
|
||||
if ipn.Contains(ip) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return &WebRTCConfig{
|
||||
Configuration: c,
|
||||
SettingEngine: s,
|
||||
|
||||
Reference in New Issue
Block a user