Skip to content

Commit

Permalink
fixup! Upgrade to pion/dtls/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Sep 13, 2024
1 parent 54ffaef commit 6f473e1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
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 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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/karrick/tparse/v2 v2.8.2
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 @@ -33,7 +33,6 @@ require (
github.com/dsnet/golib/memfile v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pion/dtls/v2 v2.2.8-0.20240701035148-45e16a098c47 // indirect
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ github.com/panjf2000/ants/v2 v2.4.3/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OI
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pion/dtls/v2 v2.0.1-0.20200503085337-8e86b3a7d585/go.mod h1:/GahSOC8ZY/+17zkaGJIG4OUkSGAcZu/N/g3roBOCkM=
github.com/pion/dtls/v2 v2.0.10-0.20210502094952-3dc563b9aede/go.mod h1:86wv5dgx2J/z871nUR+5fTTY9tISLUlo+C5Gm86r1Hs=
github.com/pion/dtls/v2 v2.2.8-0.20240701035148-45e16a098c47 h1:WCUn5hJZLLMoOvedDEDA/OFzaYbZy7G71mQ9h5GiQ/o=
github.com/pion/dtls/v2 v2.2.8-0.20240701035148-45e16a098c47/go.mod h1:8eXNLDNOiXaHvo/wOFnFcr/yinEimCDUQ512tlOSvPo=
github.com/pion/dtls/v3 v3.0.2 h1:425DEeJ/jfuTTghhUDW0GtYZYIwwMtnKKJNMcWccTX0=
github.com/pion/dtls/v3 v3.0.2/go.mod h1:dfIXcFkKoujDQ+jtd8M6RgqKK3DuaUilm3YatAbGp5k=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
Expand All @@ -115,8 +113,8 @@ github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA=
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo=
github.com/plgd-dev/go-coap/v2 v2.0.4-0.20200819112225-8eb712b901bc/go.mod h1:+tCi9Q78H/orWRtpVWyBgrr4vKFo2zYtbbxUllerBp4=
github.com/plgd-dev/go-coap/v2 v2.4.1-0.20210517130748-95c37ac8e1fa/go.mod h1:rA7fc7ar+B/qa+Q0hRqv7yj/EMtIlmo1l7vkQGSrHPU=
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240904100911-1afdeb72cb92 h1:lYHs2T4R5UYcn0+qo2381wpZRAPnAsAZiJMFC1dWlhg=
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240904100911-1afdeb72cb92/go.mod h1:BONaewfxSezj9KR39TGHIV3viL/Diz+XVOnAzBS80Fw=
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240913184713-99a5d131677e h1:uSwkaOSAHk5X4B39IBXsXuWhaYruFM5tWTcKCV5/7wQ=
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240913184713-99a5d131677e/go.mod h1:Cs6sfxmF/b8ktTVfPMf6FzihFx+0mEZ/ClbFNUnnsZw=
github.com/plgd-dev/kit v0.0.0-20200819113605-d5fcf3e94f63/go.mod h1:Yl9zisyXfPdtP9hTWlJqjJYXmgU/jtSDKttz9/CeD90=
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90 h1:TC1HJ/UbyflJFPvaOdGmNZ5TeFGex1/dyr9urNGLy7M=
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90/go.mod h1:Z7oKFLSGQjdi8eInxwFCs0tSApuEM1o0qNck+sJYp4M=
Expand Down
12 changes: 12 additions & 0 deletions pkg/net/coap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sync"
"time"

"github.com/hashicorp/go-multierror"
piondtls "github.com/pion/dtls/v3"
codecOcf "github.com/plgd-dev/device/v2/pkg/codec/ocf"
"github.com/plgd-dev/go-coap/v3/dtls"
Expand Down Expand Up @@ -493,6 +494,17 @@ func DialUDPSecure(ctx context.Context, addr string, dtlsCfg *piondtls.Config, o
if err != nil {
return nil, err
}
if dtlsConn, ok := c.NetConn().(*piondtls.Conn); ok {
var errors *multierror.Error
err = dtlsConn.HandshakeContext(ctx)
if err != nil {
errors = multierror.Append(errors, err)
if errC := c.Close(); errC != nil {
errors = multierror.Append(errors, errC)
}
return nil, errors
}
}
c.AddOnClose(func() {
h.OnClose(nil)
})
Expand Down
4 changes: 2 additions & 2 deletions test/cloud-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG GO_TEST_ARGS=
RUN go test -c ${GO_TEST_ARGS} -coverpkg=./... -covermode=atomic ./client -o /go/bin/device.client.test
RUN go test -c ${GO_TEST_ARGS} -coverpkg=./... -covermode=atomic ./client/core -o /go/bin/device.client.core.test
RUN go test -c ${GO_TEST_ARGS} -coverpkg=./... -covermode=atomic ./client -o /go/bin/device.client.test && \
go test -c ${GO_TEST_ARGS} -coverpkg=./... -covermode=atomic ./client/core -o /go/bin/device.client.core.test

FROM alpine:3.20 AS service
RUN apk add --no-cache bash
Expand Down

0 comments on commit 6f473e1

Please sign in to comment.