Skip to content

Commit

Permalink
coap-gateway: report local endpoints only once through logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Mar 4, 2024
1 parent 18e99fd commit db43d18
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
4 changes: 0 additions & 4 deletions coap-gateway/service/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ func (c *session) getLogger() log.Logger {
if deviceID != "" {
logger = logger.With(log.DeviceIDKey, deviceID)
}
localEndpoints := c.getLocalEndpoints()
if len(localEndpoints) > 0 {
logger = logger.With(log.LocalEndpointsKey, localEndpoints)
}
select {
case <-c.coapConn.Done():
logger = logger.With("closedConnection", true)
Expand Down
24 changes: 3 additions & 21 deletions coap-gateway/service/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math"
"net"
"sync"
"sync/atomic"
"time"

"github.com/pion/dtls/v2"
Expand Down Expand Up @@ -107,7 +106,6 @@ type session struct {
exchangeCache *ExchangeCache
refreshCache *RefreshCache
tlsDeviceID string
localEndpoints atomic.Pointer[[]string]
private struct { // guarded by mutex
mutex sync.Mutex
authCtx *authorizationContext
Expand Down Expand Up @@ -519,30 +517,14 @@ func (c *session) batchNotifyContentChanged(ctx context.Context, deviceID string
return err
}

func (c *session) resolveLocalEndpoints() {
v := []string{}
if !c.localEndpoints.CompareAndSwap(nil, &v) {
return
}

func (c *session) getLocalEndpoints() []string {
localEndpoints, err := coap.GetEndpointsFromDeviceResource(c.Context(), c)
if err != nil {
c.getLogger().Warnf("cannot get local endpoints: %v", err)
c.localEndpoints.Store(nil)
return
}
c.localEndpoints.Store(&localEndpoints)
}

func (c *session) getLocalEndpoints() []string {
v := c.localEndpoints.Load()
if v == nil {
return nil
}
if len(*v) == 0 {
return nil
}
return *v
c.getLogger().With(log.LocalEndpointsKey, localEndpoints).Debugf("local endpoints retrieval successful.")
return localEndpoints
}

func (c *session) notifyContentChanged(deviceID, href string, batch bool, notification *pool.Message) error {
Expand Down
1 change: 0 additions & 1 deletion coap-gateway/service/signIn.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (c *session) updateBySignInData(ctx context.Context, upd updateType, device
}

if upd == updateTypeNew {
c.resolveLocalEndpoints()
resp, err := c.server.devicesStatusUpdater.UpdateOnlineStatus(ctx, c)
if err != nil {
return nil, fmt.Errorf("cannot update cloud device status: %w", err)
Expand Down

0 comments on commit db43d18

Please sign in to comment.