mirror of
https://github.com/pion/webrtc.git
synced 2025-10-04 14:53:05 +08:00
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:
@@ -334,6 +334,7 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
|
|||||||
dtlsConfig.FlightInterval = t.api.settingEngine.dtls.retransmissionInterval
|
dtlsConfig.FlightInterval = t.api.settingEngine.dtls.retransmissionInterval
|
||||||
dtlsConfig.InsecureSkipVerifyHello = t.api.settingEngine.dtls.insecureSkipHelloVerify
|
dtlsConfig.InsecureSkipVerifyHello = t.api.settingEngine.dtls.insecureSkipHelloVerify
|
||||||
dtlsConfig.EllipticCurves = t.api.settingEngine.dtls.ellipticCurves
|
dtlsConfig.EllipticCurves = t.api.settingEngine.dtls.ellipticCurves
|
||||||
|
dtlsConfig.ConnectContextMaker = t.api.settingEngine.dtls.connectContextMaker
|
||||||
|
|
||||||
// Connect as DTLS Client/Server, function is blocking and we
|
// Connect as DTLS Client/Server, function is blocking and we
|
||||||
// must not hold the DTLSTransport lock
|
// must not hold the DTLSTransport lock
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
package webrtc
|
package webrtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
@@ -63,6 +64,7 @@ type SettingEngine struct {
|
|||||||
insecureSkipHelloVerify bool
|
insecureSkipHelloVerify bool
|
||||||
retransmissionInterval time.Duration
|
retransmissionInterval time.Duration
|
||||||
ellipticCurves []dtlsElliptic.Curve
|
ellipticCurves []dtlsElliptic.Curve
|
||||||
|
connectContextMaker func() (context.Context, func())
|
||||||
}
|
}
|
||||||
sctp struct {
|
sctp struct {
|
||||||
maxReceiveBufferSize uint32
|
maxReceiveBufferSize uint32
|
||||||
@@ -368,6 +370,17 @@ func (e *SettingEngine) SetDTLSEllipticCurves(ellipticCurves ...dtlsElliptic.Cur
|
|||||||
e.dtls.ellipticCurves = ellipticCurves
|
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.
|
// SetSCTPMaxReceiveBufferSize sets the maximum receive buffer size.
|
||||||
// Leave this 0 for the default maxReceiveBufferSize.
|
// Leave this 0 for the default maxReceiveBufferSize.
|
||||||
func (e *SettingEngine) SetSCTPMaxReceiveBufferSize(maxReceiveBufferSize uint32) {
|
func (e *SettingEngine) SetSCTPMaxReceiveBufferSize(maxReceiveBufferSize uint32) {
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
package webrtc
|
package webrtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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) {
|
func TestSetSCTPMaxReceiverBufferSize(t *testing.T) {
|
||||||
s := SettingEngine{}
|
s := SettingEngine{}
|
||||||
assert.Equal(t, uint32(0), s.sctp.maxReceiveBufferSize)
|
assert.Equal(t, uint32(0), s.sctp.maxReceiveBufferSize)
|
||||||
|
Reference in New Issue
Block a user