Repository: pion/webrtc
Pull request #1463 (2020-10-05 22:04:53)

Rename SettingEngine mDNS Config option
GenerateMulticastDNSCandidates -> SetICEMulticastDNSMode.
Before a user wasn't able to disable mDNS. By changing it we can
do more with this API.

codecov[bot]: # [Codecov](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=h1) Report
> Merging [#1463](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=desc) into [master](https://codecov.io/gh/pion/webrtc/commit/4c280289afc9fea34ad8917b58c4c9971ec319ec?el=desc) will **decrease** coverage by `0.09%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/pion/webrtc/pull/1463/graphs/tree.svg?width=650&height=150&src=pr&token=XOOuQo07I2)](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1463      +/-   ##
==========================================
- Coverage   74.20%   74.10%   -0.10%     
==========================================
  Files          73       73              
  Lines        5252     5252              
==========================================
- Hits         3897     3892       -5     
- Misses        995      997       +2     
- Partials      360      363       +3     
```

| Flag | Coverage Δ | |
|---|---|---|
| #go | `75.73% <100.00%> (-0.11%)` | :arrow_down: |
| #wasm | `71.79% <ø> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [icegatherer.go](https://codecov.io/gh/pion/webrtc/pull/1463/diff?src=pr&el=tree#diff-aWNlZ2F0aGVyZXIuZ28=) | `82.21% <100.00%> (ø)` | |
| [settingengine.go](https://codecov.io/gh/pion/webrtc/pull/1463/diff?src=pr&el=tree#diff-c2V0dGluZ2VuZ2luZS5nbw==) | `64.51% <100.00%> (ø)` | |
| [rtpsender.go](https://codecov.io/gh/pion/webrtc/pull/1463/diff?src=pr&el=tree#diff-cnRwc2VuZGVyLmdv) | `74.44% <0.00%> (-2.23%)` | :arrow_down: |
| [dtlstransport.go](https://codecov.io/gh/pion/webrtc/pull/1463/diff?src=pr&el=tree#diff-ZHRsc3RyYW5zcG9ydC5nbw==) | `64.11% <0.00%> (-1.92%)` | :arrow_down: |
| [peerconnection.go](https://codecov.io/gh/pion/webrtc/pull/1463/diff?src=pr&el=tree#diff-cGVlcmNvbm5lY3Rpb24uZ28=) | `74.73% <0.00%> (+0.08%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=footer). Last update [4c28028...05acc18](https://codecov.io/gh/pion/webrtc/pull/1463?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/icegatherer.go b/icegatherer.go
index 058c9130..49a2cbe1 100644
--- a/icegatherer.go
+++ b/icegatherer.go
@@ -82,9 +82,10 @@ func (g *ICEGatherer) createAgent() error {
 		nat1To1CandiTyp = ice.CandidateTypeUnspecified
 	}
 
-	var multicastDNSMode ice.MulticastDNSMode
-	if g.api.settingEngine.candidates.GenerateMulticastDNSCandidates {
-		multicastDNSMode = ice.MulticastDNSModeQueryAndGather
+	mDNSMode := g.api.settingEngine.candidates.MulticastDNSMode
+	if mDNSMode != ice.MulticastDNSModeDisabled && mDNSMode != ice.MulticastDNSModeQueryAndGather {
+		// If enum is in state we don't recognized default to MulticastDNSModeQueryOnly
+		mDNSMode = ice.MulticastDNSModeQueryOnly
 	}
 
 	config := &ice.AgentConfig{
@@ -105,7 +106,7 @@ func (g *ICEGatherer) createAgent() error {
 		NAT1To1IPs:             g.api.settingEngine.candidates.NAT1To1IPs,
 		NAT1To1IPCandidateType: nat1To1CandiTyp,
 		Net:                    g.api.settingEngine.vnet,
-		MulticastDNSMode:       multicastDNSMode,
+		MulticastDNSMode:       mDNSMode,
 		MulticastDNSHostName:   g.api.settingEngine.candidates.MulticastDNSHostName,
 		LocalUfrag:             g.api.settingEngine.candidates.UsernameFragment,
 		LocalPwd:               g.api.settingEngine.candidates.Password,
diff --git a/settingengine.go b/settingengine.go
index 133821e3..d5b9dcd2 100644
--- a/settingengine.go
+++ b/settingengine.go
@@ -32,15 +32,15 @@ type SettingEngine struct {
 		ICERelayAcceptanceMinWait *time.Duration
 	}
 	candidates struct {
-		ICELite                        bool
-		ICENetworkTypes                []NetworkType
-		InterfaceFilter                func(string) bool
-		NAT1To1IPs                     []string
-		NAT1To1IPCandidateType         ICECandidateType
-		GenerateMulticastDNSCandidates bool
-		MulticastDNSHostName           string
-		UsernameFragment               string
-		Password                       string
+		ICELite                bool
+		ICENetworkTypes        []NetworkType
+		InterfaceFilter        func(string) bool
+		NAT1To1IPs             []string
+		NAT1To1IPCandidateType ICECandidateType
+		MulticastDNSMode       ice.MulticastDNSMode
+		MulticastDNSHostName   string
+		UsernameFragment       string
+		Password               string
 	}
 	replayProtection struct {
 		DTLS  *uint
@@ -181,9 +181,9 @@ func (e *SettingEngine) SetVNet(vnet *vnet.Net) {
 	e.vnet = vnet
 }
 
-// GenerateMulticastDNSCandidates instructs pion/ice to generate host candidates with mDNS hostnames instead of IP Addresses
-func (e *SettingEngine) GenerateMulticastDNSCandidates(generateMulticastDNSCandidates bool) {
-	e.candidates.GenerateMulticastDNSCandidates = generateMulticastDNSCandidates
+// SetICEMulticastDNSMode controls if pion/ice queries and generates mDNS ICE Candidates
+func (e *SettingEngine) SetICEMulticastDNSMode(multicastDNSMode ice.MulticastDNSMode) {
+	e.candidates.MulticastDNSMode = multicastDNSMode
 }
 
 // SetMulticastDNSHostName sets a static HostName to be used by pion/ice instead of generating one on startup


Test patch:
diff --git a/icegatherer_test.go b/icegatherer_test.go
index 0ce14539..23b571ed 100644
--- a/icegatherer_test.go
+++ b/icegatherer_test.go
@@ -8,6 +8,7 @@ import (
 	"testing"
 	"time"
 
+	"github.com/pion/ice/v2"
 	"github.com/pion/transport/test"
 	"github.com/stretchr/testify/assert"
 )
@@ -77,7 +78,7 @@ func TestICEGather_mDNSCandidateGathering(t *testing.T) {
 	defer report()
 
 	s := SettingEngine{}
-	s.GenerateMulticastDNSCandidates(true)
+	s.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
 
 	gatherer, err := NewAPI(WithSettingEngine(s)).NewICEGatherer(ICEGatherOptions{})
 	if err != nil {
diff --git a/peerconnection_go_test.go b/peerconnection_go_test.go
index 96c02516..04a1cc65 100644
--- a/peerconnection_go_test.go
+++ b/peerconnection_go_test.go
@@ -838,7 +838,7 @@ func TestMulticastDNSCandidates(t *testing.T) {
 	defer report()
 
 	s := SettingEngine{}
-	s.GenerateMulticastDNSCandidates(true)
+	s.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
 
 	pcOffer, pcAnswer, err := NewAPI(WithSettingEngine(s)).newPair(Configuration{})
 	assert.NoError(t, err)