Add SetDTLSConnectContextMaker to SettingEngine

Allows a user to set the context used during the DTLS Handshake. This
can be used to extend or reduce the timeout on the DTLS Handshake.

Resolves #2477
This commit is contained in:
lisa yan
2023-05-19 10:34:41 +08:00
committed by Sean DuBois
parent c1bec495a3
commit 4d3c4b13b1
3 changed files with 23 additions and 0 deletions

View File

@@ -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

View File

@@ -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) {

View File

@@ -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)