Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dtlstransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package webrtc

import (
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
Expand Down Expand Up @@ -301,6 +302,20 @@ func (t *DTLSTransport) role() DTLSRole {

// Start DTLS transport negotiation with the parameters of the remote DTLS transport.
func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
ctx := context.Background()
if t.api.settingEngine.dtls.connectContextMaker != nil {
var cancel func()
ctx, cancel = t.api.settingEngine.dtls.connectContextMaker()
defer cancel()
}

return t.StartContext(ctx, remoteParameters)
}

// StartContext starts DTLS transport negotiation with the parameters of the remote DTLS
// transport. If the context is canceled before the DTLS handshake is complete, the handshake
// is interrupted and an error is returned.
func (t *DTLSTransport) StartContext(ctx context.Context, remoteParameters DTLSParameters) error {
role, certificate, err := t.prepareStart(remoteParameters)
if err != nil {
return err
Expand All @@ -319,7 +334,7 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
return t.failStart(err)
}

if err = t.handshakeDTLS(dtlsConn); err != nil {
if err = dtlsConn.HandshakeContext(ctx); err != nil {
dtlsEndpoint.SetOnClose(nil)
_ = dtlsConn.Close()

Expand Down
2 changes: 1 addition & 1 deletion dtlstransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (c *failingPacketConn) SetReadDeadline(time.Time) error { return nil }
func (c *failingPacketConn) SetWriteDeadline(time.Time) error { return nil }

func TestDTLSTransport_Start_ErrICEConnectionNotStarted(t *testing.T) {
transport := &DTLSTransport{state: DTLSTransportStateNew}
transport := &DTLSTransport{api: NewAPI(), state: DTLSTransportStateNew}

err := transport.Start(DTLSParameters{Role: DTLSRoleServer})
assert.ErrorIs(t, err, errICEConnectionNotStarted)
Expand Down
17 changes: 15 additions & 2 deletions icetransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,20 @@ func NewICETransport(gatherer *ICEGatherer, loggerFactory logging.LoggerFactory)
}

// Start incoming connectivity checks based on its configured role.
func (t *ICETransport) Start(gatherer *ICEGatherer, params ICEParameters, role *ICERole) error { //nolint:cyclop
func (t *ICETransport) Start(gatherer *ICEGatherer, params ICEParameters, role *ICERole) error {
return t.StartContext(context.Background(), gatherer, params, role)
}

// StartContext incoming connectivity checks based on its configured role.
// If the context is canceled, the ICE transport will stop.
//
//nolint:cyclop
func (t *ICETransport) StartContext(
ctx context.Context,
gatherer *ICEGatherer,
params ICEParameters,
role *ICERole,
) error {
t.lock.Lock()
defer t.lock.Unlock()

Expand Down Expand Up @@ -134,7 +147,7 @@ func (t *ICETransport) Start(gatherer *ICEGatherer, params ICEParameters, role *
}
t.role = *role

ctx, ctxCancel := context.WithCancel(context.Background())
ctx, ctxCancel := context.WithCancel(ctx)
t.ctxCancel = ctxCancel

// Drop the lock here to allow ICE candidates to be
Expand Down
Loading