From c3ba801570bc9a7a86c3bec705a09e243aecea0b Mon Sep 17 00:00:00 2001 From: Tomas Kubovic Date: Tue, 25 Mar 2025 12:59:01 +0100 Subject: [PATCH 1/2] Added trim [] for IPv6 address in getDeviceByIP method --- client/getDevice.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/getDevice.go b/client/getDevice.go index 0573d068..3f79e5ab 100644 --- a/client/getDevice.go +++ b/client/getDevice.go @@ -21,6 +21,7 @@ import ( "crypto/x509" "errors" "fmt" + "strings" "github.com/plgd-dev/device/v2/client/core" "github.com/plgd-dev/device/v2/pkg/net/coap" @@ -92,7 +93,7 @@ type DeviceWithLinks struct { } func (c *Client) getDevicesByIP(ctx context.Context, ip string, expectedDeviceID string) ([]DeviceWithLinks, error) { - devs, err := c.getDeviceByIPWithUpdateCache(ctx, ip, expectedDeviceID) + devs, err := c.getDeviceByIPWithUpdateCache(ctx, strings.Trim(ip, "[]"), expectedDeviceID) if err != nil { return nil, err } From c04fa5934e652a3de664dc5303f813ff882f072c Mon Sep 17 00:00:00 2001 From: Tomas Kubovic Date: Wed, 26 Mar 2025 13:13:39 +0100 Subject: [PATCH 2/2] Fixed trim IPv6 brackets in observe devices --- client/observeDevices.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/observeDevices.go b/client/observeDevices.go index a272b7a1..6c846bc8 100644 --- a/client/observeDevices.go +++ b/client/observeDevices.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strings" "sync" "github.com/google/uuid" @@ -220,7 +221,7 @@ func (o *devicesObserver) observe(ctx context.Context) (map[string]uint8, error) for deviceID, ip := range devicesByIP { go func(deviceID string, ip string) { defer wg.Done() - if _, e := o.c.getDeviceByIPWithUpdateCache(ctx, ip, deviceID); e == nil { + if _, e := o.c.getDeviceByIPWithUpdateCache(ctx, strings.Trim(ip, "[]"), deviceID); e == nil { newDevices.devices.LoadOrStore(deviceID, struct{}{}) } }(deviceID, ip)