Skip to content

Commit

Permalink
Add SetDTLSConnectContextMaker to SettingEngine
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lisay-yan authored and Sean-Der committed May 19, 2023
1 parent c1bec49 commit 4d3c4b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions dtlstransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions settingengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package webrtc

import (
"context"
"io"
"net"
"time"
Expand Down Expand Up @@ -63,6 +64,7 @@ type SettingEngine struct {
insecureSkipHelloVerify bool
retransmissionInterval time.Duration
ellipticCurves []dtlsElliptic.Curve
connectContextMaker func() (context.Context, func())
}
sctp struct {
maxReceiveBufferSize uint32
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions settingengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package webrtc

import (
"context"
"net"
"testing"
"time"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4d3c4b1

Please sign in to comment.