mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00
Add InterfaceFilter to SettingEngine
This allows users to filter interfaces from ICE gathering Resolves #843 Co-authored-by: Sean DuBois <sean@siobud.com>
This commit is contained in:

committed by
Sean DuBois

parent
d8b7905aaf
commit
cabbd8b52f
@@ -136,6 +136,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
|
||||
* [Sebastian Waisbrot](https://github.com/seppo0010)
|
||||
* [Masataka Hisasue](https://github.com/sylba2050) - *Fix Docs*
|
||||
* [Hongchao Ma(马洪超)](https://github.com/hcm007)
|
||||
* [Aaron France](https://github.com/AeroNotix)
|
||||
|
||||
### License
|
||||
MIT License - see [LICENSE](LICENSE) for full text
|
||||
|
8
go.mod
8
go.mod
@@ -5,7 +5,7 @@ go 1.12
|
||||
require (
|
||||
github.com/pion/datachannel v1.4.6
|
||||
github.com/pion/dtls v1.5.1
|
||||
github.com/pion/ice v0.5.15
|
||||
github.com/pion/ice v0.6.0
|
||||
github.com/pion/logging v0.2.2
|
||||
github.com/pion/quic v0.1.1
|
||||
github.com/pion/rtcp v1.2.1
|
||||
@@ -13,8 +13,8 @@ require (
|
||||
github.com/pion/sctp v1.6.10
|
||||
github.com/pion/sdp/v2 v2.3.0
|
||||
github.com/pion/srtp v1.2.6
|
||||
github.com/pion/transport v0.8.7
|
||||
github.com/pion/transport v0.8.9
|
||||
github.com/stretchr/testify v1.4.0
|
||||
golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2 // indirect
|
||||
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8 // indirect
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect
|
||||
)
|
||||
|
23
go.sum
23
go.sum
@@ -29,8 +29,8 @@ github.com/pion/datachannel v1.4.6 h1:ALIwApJIxXOxA142PwJ7abvHwVdicVMqjkQNZC1WxL
|
||||
github.com/pion/datachannel v1.4.6/go.mod h1:k02QlG7ZByXzavnjWj3gP3W1474H4ifzxSx2Y0Q5kvc=
|
||||
github.com/pion/dtls v1.5.1 h1:LcCs1l9fzsHC4y+ENjLyuxOAe+k0DV65T2n4tjwM7xw=
|
||||
github.com/pion/dtls v1.5.1/go.mod h1:CjlPLfQdsTg3G4AEXjJp8FY5bRweBlxHrgoFrN+fQsk=
|
||||
github.com/pion/ice v0.5.15 h1:wy9C4JICwKZpQm+VX4WAnr2yVO6tNsqCWg87OOZWbmk=
|
||||
github.com/pion/ice v0.5.15/go.mod h1:8of6pKdMoT9/TNLYdv+UdjSF4DvLUN65mzhhfmQDg5g=
|
||||
github.com/pion/ice v0.6.0 h1:SfzZ/9z6hqclDOwbeSppuP7AugnHJ0Sek6y+3OukG2M=
|
||||
github.com/pion/ice v0.6.0/go.mod h1:9ic6fEpIRXiJEKrMpleyAuSY4ZAOD6e6QX8wYywZwsc=
|
||||
github.com/pion/logging v0.2.1/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
||||
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||
@@ -50,14 +50,17 @@ github.com/pion/srtp v1.2.6 h1:mHQuAMh0P67R7/j1F260u3O+fbRWLyjKLRPZYYvODFM=
|
||||
github.com/pion/srtp v1.2.6/go.mod h1:rd8imc5htjfs99XiEoOjLMEOcVjME63UHx9Ek9IGst0=
|
||||
github.com/pion/stun v0.3.2 h1:Vsy6C+bTbJKEC2TH4vHYOnRKmozNPi5FpeKv9/bX16k=
|
||||
github.com/pion/stun v0.3.2/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
|
||||
github.com/pion/stun v0.3.3 h1:brYuPl9bN9w/VM7OdNzRSLoqsnwlyNvD9MVeJrHjDQw=
|
||||
github.com/pion/stun v0.3.3/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
|
||||
github.com/pion/transport v0.6.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE=
|
||||
github.com/pion/transport v0.7.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE=
|
||||
github.com/pion/transport v0.8.6 h1:xHQq2mxAjB+UrFs90aUBaXwlmIACfQAZnOiVAX3uqMw=
|
||||
github.com/pion/transport v0.8.6/go.mod h1:nAmRRnn+ArVtsoNuwktvAD+jrjSD7pA+H3iRmZwdUno=
|
||||
github.com/pion/transport v0.8.7 h1:t7uYhWOoljd82rnkLH+H2Lw7/IGA5kV9Bl5sWrmcYSc=
|
||||
github.com/pion/transport v0.8.7/go.mod h1:lpeSM6KJFejVtZf8k0fgeN7zE73APQpTF83WvA1FVP8=
|
||||
github.com/pion/turn v1.3.6 h1:N49o5g3SRI5g5Sg8WVft1RDAFxIHOi5roHHdbC39g7g=
|
||||
github.com/pion/turn v1.3.6/go.mod h1:D8XaX/CVKLkRozV9baRvhZmwOyKAJCTHrj23DdwMI4g=
|
||||
github.com/pion/transport v0.8.8/go.mod h1:lpeSM6KJFejVtZf8k0fgeN7zE73APQpTF83WvA1FVP8=
|
||||
github.com/pion/transport v0.8.9 h1:3PUZULb0WZd/QNfXKKMwcUHzLR+XfNem6lF2M9UrxSU=
|
||||
github.com/pion/transport v0.8.9/go.mod h1:lpeSM6KJFejVtZf8k0fgeN7zE73APQpTF83WvA1FVP8=
|
||||
github.com/pion/turn v1.3.7 h1:/nyM2XrlZILD7KKfnh0oYEBTRG5JlbH21ibjluRoCeo=
|
||||
github.com/pion/turn v1.3.7/go.mod h1:js0LBFqMcKAlaWAXoYqNjefGI7kfJCrkCBfHGuTToXE=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
@@ -77,8 +80,8 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r
|
||||
golang.org/x/net v0.0.0-20190619014844-b5b0513f8c1b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2 h1:4dVFTC832rPn4pomLSz1vA+are2+dU19w1H8OngV7nc=
|
||||
golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -87,8 +90,8 @@ golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8 h1:41hwlulw1prEMBxLQSlMSux1zxJf07B3WPsdjJlKZxE=
|
||||
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M=
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
|
@@ -22,6 +22,7 @@ func (api *API) NewICEGatherer(opts ICEGatherOptions) (*ICEGatherer, error) {
|
||||
api.settingEngine.candidates.ICETrickle,
|
||||
api.settingEngine.candidates.ICELite,
|
||||
api.settingEngine.candidates.ICENetworkTypes,
|
||||
api.settingEngine.candidates.InterfaceFilter,
|
||||
opts,
|
||||
)
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@ type ICEGatherer struct {
|
||||
loggerFactory logging.LoggerFactory
|
||||
log logging.LeveledLogger
|
||||
networkTypes []NetworkType
|
||||
interfaceFilter func(string) bool
|
||||
|
||||
onLocalCandidateHdlr func(candidate *ICECandidate)
|
||||
onStateChangeHdlr func(state ICEGathererState)
|
||||
@@ -57,6 +58,7 @@ func NewICEGatherer(
|
||||
agentIsTrickle bool,
|
||||
lite bool,
|
||||
networkTypes []NetworkType,
|
||||
interfaceFilter func(string) bool,
|
||||
opts ICEGatherOptions,
|
||||
) (*ICEGatherer, error) {
|
||||
var validatedServers []*ice.URL
|
||||
@@ -95,6 +97,7 @@ func NewICEGatherer(
|
||||
srflxAcceptanceMinWait: srflxAcceptanceMinWait,
|
||||
prflxAcceptanceMinWait: prflxAcceptanceMinWait,
|
||||
relayAcceptanceMinWait: relayAcceptanceMinWait,
|
||||
interfaceFilter: interfaceFilter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -121,6 +124,7 @@ func (g *ICEGatherer) createAgent() error {
|
||||
SrflxAcceptanceMinWait: g.srflxAcceptanceMinWait,
|
||||
PrflxAcceptanceMinWait: g.prflxAcceptanceMinWait,
|
||||
RelayAcceptanceMinWait: g.relayAcceptanceMinWait,
|
||||
InterfaceFilter: g.interfaceFilter,
|
||||
}
|
||||
|
||||
requestedNetworkTypes := g.networkTypes
|
||||
|
@@ -22,7 +22,7 @@ func TestNewICEGatherer_Success(t *testing.T) {
|
||||
ICEServers: []ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}},
|
||||
}
|
||||
|
||||
gatherer, err := NewICEGatherer(0, 0, nil, nil, nil, nil, nil, nil, nil, logging.NewDefaultLoggerFactory(), false, false, nil, opts)
|
||||
gatherer, err := NewICEGatherer(0, 0, nil, nil, nil, nil, nil, nil, nil, logging.NewDefaultLoggerFactory(), false, false, nil, func(string) bool { return true }, opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func TestICEGather_LocalCandidateOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
to := time.Second
|
||||
gatherer, err := NewICEGatherer(10000, 10010, &to, &to, &to, &to, &to, &to, &to, logging.NewDefaultLoggerFactory(), false, false, []NetworkType{NetworkTypeUDP4}, opts)
|
||||
gatherer, err := NewICEGatherer(10000, 10010, &to, &to, &to, &to, &to, &to, &to, logging.NewDefaultLoggerFactory(), false, false, []NetworkType{NetworkTypeUDP4}, func(string) bool { return true }, opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ type SettingEngine struct {
|
||||
ICELite bool
|
||||
ICETrickle bool
|
||||
ICENetworkTypes []NetworkType
|
||||
InterfaceFilter func(string) bool
|
||||
}
|
||||
LoggerFactory logging.LoggerFactory
|
||||
}
|
||||
@@ -105,3 +106,11 @@ func (e *SettingEngine) SetTrickle(trickle bool) {
|
||||
func (e *SettingEngine) SetNetworkTypes(candidateTypes []NetworkType) {
|
||||
e.candidates.ICENetworkTypes = candidateTypes
|
||||
}
|
||||
|
||||
// SetInterfaceFilter sets the filtering functions when gathering ICE candidates
|
||||
// This can be used to exclude certain network interfaces from ICE. Which may be
|
||||
// useful if you know a certain interface will never succeed, or if you wish to reduce
|
||||
// the amount of information you wish to expose to the remote peer
|
||||
func (e *SettingEngine) SetInterfaceFilter(filter func(string) bool) {
|
||||
e.candidates.InterfaceFilter = filter
|
||||
}
|
||||
|
Reference in New Issue
Block a user