Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to pion/dtls/v3 #489

Merged
merged 2 commits into from
Sep 13, 2024
Merged
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
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"COAP_CRT": "${workspaceFolder}/.tmp/pki_certs/coapcrt.pem",
"COAP_KEY": "${workspaceFolder}/.tmp/pki_certs/coapkey.pem",
"CLOUD_SID": "adebc667-1f2b-41e3-bf5c-6d6eabc68cc6",
// "PION_LOG_TRACE": "all",
// "GOFLAGS": "-mod=vendor"
},
"files.watcherExclude": {
"**/plgd-dev/device/v2/**": true
Expand Down
6 changes: 4 additions & 2 deletions bridge/resources/etag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"encoding/binary"
"sync/atomic"
"time"

"github.com/plgd-dev/device/v2/internal/math"
)

var globalETag atomic.Uint64
Expand All @@ -31,14 +33,14 @@ func generateNextETag(currentETag uint64) uint64 {
buf := make([]byte, 4)
_, err := rand.Read(buf)
if err != nil {
return currentETag + uint64(time.Now().UnixNano()%1000)
return currentETag + math.CastTo[uint64](time.Now().UnixNano()%1000)
}
return currentETag + uint64(binary.BigEndian.Uint32(buf)%1000)
}

func GetETag() uint64 {
for {
now := uint64(time.Now().UnixNano())
now := math.CastTo[uint64](time.Now().UnixNano())
oldEtag := globalETag.Load()
etag := oldEtag
if now > etag {
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sync"
"time"

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
"github.com/plgd-dev/device/v2/client/core"
"github.com/plgd-dev/device/v2/client/core/otm"
"github.com/plgd-dev/device/v2/internal/math"
Expand Down
2 changes: 1 addition & 1 deletion client/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"crypto/x509"
"net"

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
"github.com/pion/logging"
pkgError "github.com/plgd-dev/device/v2/pkg/error"
"github.com/plgd-dev/device/v2/pkg/log"
Expand Down
2 changes: 1 addition & 1 deletion client/core/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"
"time"

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
"github.com/plgd-dev/device/v2/client/core"
"github.com/plgd-dev/device/v2/client/core/otm"
justworks "github.com/plgd-dev/device/v2/client/core/otm/just-works"
Expand Down
2 changes: 1 addition & 1 deletion client/core/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sync/atomic"

"github.com/hashicorp/go-multierror"
"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
"github.com/plgd-dev/device/v2/pkg/net/coap"
"github.com/plgd-dev/device/v2/schema"
coapSync "github.com/plgd-dev/go-coap/v3/pkg/sync"
Expand Down
10 changes: 5 additions & 5 deletions client/core/otm/just-works/cipher/tlsAecdhAes128Sha256.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"hash"
"sync/atomic"

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v2/pkg/crypto/ciphersuite"
"github.com/pion/dtls/v2/pkg/crypto/clientcertificate"
"github.com/pion/dtls/v2/pkg/crypto/prf"
"github.com/pion/dtls/v2/pkg/protocol/recordlayer"
"github.com/pion/dtls/v3"
"github.com/pion/dtls/v3/pkg/crypto/ciphersuite"
"github.com/pion/dtls/v3/pkg/crypto/clientcertificate"
"github.com/pion/dtls/v3/pkg/crypto/prf"
"github.com/pion/dtls/v3/pkg/protocol/recordlayer"
)

var ErrCipherSuiteNotReady = errors.New("CipherSuite is not ready")
Expand Down
5 changes: 1 addition & 4 deletions client/core/otm/just-works/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
"github.com/plgd-dev/device/v2/client/core/otm/just-works/cipher"
"github.com/plgd-dev/device/v2/pkg/net/coap"
"github.com/plgd-dev/device/v2/schema"
Expand Down Expand Up @@ -67,9 +67,6 @@ func (c *Client) Dial(ctx context.Context, addr kitNet.Addr) (*coap.ClientCloseH
return []dtls.CipherSuite{cipher.NewTLSAecdhAes128Sha256(dtls.CipherSuiteID(0xff00))}
},
CipherSuites: []dtls.CipherSuiteID{},
ConnectContextMaker: func() (context.Context, func()) {
return context.WithCancel(ctx)
},
}
return c.dialDTLS(ctx, addr.String(), &tlsConfig)
}
Expand Down
2 changes: 1 addition & 1 deletion client/core/otm/manufacturer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"crypto/x509"
"fmt"

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
"github.com/plgd-dev/device/v2/pkg/net/coap"
"github.com/plgd-dev/device/v2/schema"
"github.com/plgd-dev/device/v2/schema/doxm"
Expand Down
2 changes: 1 addition & 1 deletion client/core/ownDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/google/uuid"
"github.com/hashicorp/go-multierror"
"github.com/pion/dtls/v2"
"github.com/pion/dtls/v3"
"github.com/plgd-dev/device/v2/client/core/otm"
"github.com/plgd-dev/device/v2/pkg/net/coap"
"github.com/plgd-dev/device/v2/schema"
Expand Down
13 changes: 6 additions & 7 deletions client/getDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,18 @@ func TestClientGetDeviceByIPOwnedByOther(t *testing.T) {
require.NoError(t, errClose)
}()

c1, err := testClient.NewTestSecureClientWithGeneratedCertificate()
_, err = c.OwnDevice(ctx, deviceID)
require.NoError(t, err)
defer func() {
errClose := c1.Close(context.Background())
require.NoError(t, errClose)
err = c.DisownDevice(ctx, deviceID)
require.NoError(t, err)
}()

_, err = c.OwnDevice(ctx, deviceID)
c1, err := testClient.NewTestSecureClientWithGeneratedCertificate()
require.NoError(t, err)

defer func() {
err = c.DisownDevice(ctx, deviceID)
require.NoError(t, err)
errClose := c1.Close(context.Background())
require.NoError(t, errClose)
}()

device, err := c1.GetDeviceDetailsByIP(ctx, ip4)
Expand Down
2 changes: 1 addition & 1 deletion cmd/bridge-device/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1
FROM golang:1.22.3-alpine AS build
RUN apk add --no-cache curl git build-base
RUN apk add --no-cache build-base curl git
WORKDIR $GOPATH/src/github.com/plgd-dev/device
COPY go.mod go.sum ./
RUN go mod download
Expand Down
13 changes: 4 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/jessevdk/go-flags v1.6.1
github.com/karrick/tparse/v2 v2.8.2
github.com/pion/dtls/v2 v2.2.8-0.20240701035148-45e16a098c47
github.com/pion/dtls/v3 v3.0.2
github.com/pion/logging v0.2.2
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240904100911-1afdeb72cb92
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240913184713-99a5d131677e
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90
github.com/stretchr/testify v1.9.0
github.com/ugorji/go/codec v1.2.12
Expand All @@ -43,10 +43,5 @@ require (
google.golang.org/protobuf v1.34.2 // indirect
)

replace (
// last version for Go 1.22
github.com/go-json-experiment/json => github.com/go-json-experiment/json v0.0.0-20240815174924-0599f16bf0e2
// note: github.com/pion/dtls/v2/pkg/net package is not yet available in release branches,
// so we force to the use of the pinned master branch
github.com/pion/dtls/v2 => github.com/pion/dtls/v2 v2.2.8-0.20240701035148-45e16a098c47
)
// last version for Go 1.22
replace github.com/go-json-experiment/json => github.com/go-json-experiment/json v0.0.0-20240815174924-0599f16bf0e2
Loading
Loading