Repository: pion/webrtc
Pull request #2482 (2023-05-19 02:43:38)

set config for dtls handshake timeout
#### Description
Config dtls handshake for peerconn
#### Reference issue
New request


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pion/webrtc/pull/2482?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) Report
Patch coverage: **`100.00`**% and project coverage change: **`-0.08`** :warning:
> Comparison is base [(`c1bec49`)](https://app.codecov.io/gh/pion/webrtc/commit/c1bec495a3e43dafde9d301c8e20516fed844a99?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) 77.78% compared to head [(`b7b32b6`)](https://app.codecov.io/gh/pion/webrtc/pull/2482?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) 77.70%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #2482      +/-   ##
==========================================
- Coverage   77.78%   77.70%   -0.08%     
==========================================
  Files          87       87              
  Lines        9321     9324       +3     
==========================================
- Hits         7250     7245       -5     
- Misses       1643     1650       +7     
- Partials      428      429       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `79.48% <100.00%> (-0.09%)` | :arrow_down: |
| wasm | `70.15% <ø> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://app.codecov.io/gh/pion/webrtc/pull/2482?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | |
|---|---|---|
| [dtlstransport.go](https://app.codecov.io/gh/pion/webrtc/pull/2482?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-ZHRsc3RyYW5zcG9ydC5nbw==) | `63.82% <100.00%> (-1.72%)` | :arrow_down: |
| [settingengine.go](https://app.codecov.io/gh/pion/webrtc/pull/2482?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-c2V0dGluZ2VuZ2luZS5nbw==) | `57.44% <100.00%> (+0.92%)` | :arrow_up: |

... and [3 files with indirect coverage changes](https://app.codecov.io/gh/pion/webrtc/pull/2482/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pion/webrtc/pull/2482?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).


Patch:
diff --git a/dtlstransport.go b/dtlstransport.go
index 68983e9f..a5426d56 100644
--- a/dtlstransport.go
+++ b/dtlstransport.go
@@ -334,6 +334,7 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
 	dtlsConfig.FlightInterval = t.api.settingEngine.dtls.retransmissionInterval
 	dtlsConfig.InsecureSkipVerifyHello = t.api.settingEngine.dtls.insecureSkipHelloVerify
 	dtlsConfig.EllipticCurves = t.api.settingEngine.dtls.ellipticCurves
+	dtlsConfig.ConnectContextMaker = t.api.settingEngine.dtls.connectContextMaker
 
 	// Connect as DTLS Client/Server, function is blocking and we
 	// must not hold the DTLSTransport lock
diff --git a/settingengine.go b/settingengine.go
index 914412aa..1c7824d8 100644
--- a/settingengine.go
+++ b/settingengine.go
@@ -7,6 +7,7 @@
 package webrtc
 
 import (
+	"context"
 	"io"
 	"net"
 	"time"
@@ -63,6 +64,7 @@ type SettingEngine struct {
 		insecureSkipHelloVerify bool
 		retransmissionInterval  time.Duration
 		ellipticCurves          []dtlsElliptic.Curve
+		connectContextMaker     func() (context.Context, func())
 	}
 	sctp struct {
 		maxReceiveBufferSize uint32
@@ -368,6 +370,17 @@ func (e *SettingEngine) SetDTLSEllipticCurves(ellipticCurves ...dtlsElliptic.Cur
 	e.dtls.ellipticCurves = ellipticCurves
 }
 
+// SetDTLSConnectContextMaker sets the context used during the DTLS Handshake.
+// It can be used to extend or reduce the timeout on the DTLS Handshake.
+// If nil, the default dtls.ConnectContextMaker is used. It can be implemented as following.
+//
+//	func ConnectContextMaker() (context.Context, func()) {
+//		return context.WithTimeout(context.Background(), 30*time.Second)
+//	}
+func (e *SettingEngine) SetDTLSConnectContextMaker(connectContextMaker func() (context.Context, func())) {
+	e.dtls.connectContextMaker = connectContextMaker
+}
+
 // SetSCTPMaxReceiveBufferSize sets the maximum receive buffer size.
 // Leave this 0 for the default maxReceiveBufferSize.
 func (e *SettingEngine) SetSCTPMaxReceiveBufferSize(maxReceiveBufferSize uint32) {


Test patch:
diff --git a/settingengine_test.go b/settingengine_test.go
index 6001ad81..3834db83 100644
--- a/settingengine_test.go
+++ b/settingengine_test.go
@@ -7,6 +7,7 @@
 package webrtc
 
 import (
+	"context"
 	"net"
 	"testing"
 	"time"
@@ -252,6 +253,14 @@ func TestSetDTLSEllipticCurves(t *testing.T) {
 	}
 }
 
+func TestSetDTLSHandShakeTimeout(*testing.T) {
+	s := SettingEngine{}
+
+	s.SetDTLSConnectContextMaker(func() (context.Context, func()) {
+		return context.WithTimeout(context.Background(), 60*time.Second)
+	})
+}
+
 func TestSetSCTPMaxReceiverBufferSize(t *testing.T) {
 	s := SettingEngine{}
 	assert.Equal(t, uint32(0), s.sctp.maxReceiveBufferSize)