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

remove duplicate update logic in gateway lwm2m #1092

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 1 addition & 26 deletions pkg/gateway/lwm2m/client/lwm2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

udpClientOpts = append(
udpClientOpts,
options.WithInactivityMonitor(time.Minute, func(cc *udpClient.Conn) {
options.WithInactivityMonitor(time.Second*time.Duration(c.Settings.UpdateIntervalSec), func(cc *udpClient.Conn) {

Check warning on line 153 in pkg/gateway/lwm2m/client/lwm2m.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lwm2m/client/lwm2m.go#L153

Added line #L153 was not covered by tests
logger.Warn("Connection inactive, triggering reconnect")
select {
case c.reconnectCh <- struct{}{}:
Expand Down Expand Up @@ -240,11 +240,6 @@

c.locationPath = locationPath
c.lastUpdatedTime = time.Now()
go func() {
if err := c.AutoUpdate(); err != nil {
logger.Errorf("failed to auto update registration: %v", err)
}
}()

logger.Infof("register %v success", c.locationPath)
return nil
Expand All @@ -271,26 +266,6 @@
return nil
}

// AutoUpdate auto update registration
// Reference: https://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf#page=30
func (c *Client) AutoUpdate() error {
ticker := time.NewTicker(time.Duration(c.Settings.UpdateIntervalSec) * time.Second)
for {
select {
case <-c.ctx.Done():
return nil
case <-ticker.C:
if c.isActivity() {
if err := c.Update(); err != nil {
logger.Errorf("failed to update registration: %v", err)
continue
}
logger.Debug("update registration success")
}
}
}
}

// Update update registration
// Reference: https://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf#page=30
// Reference: https://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf#page=76
Expand Down Expand Up @@ -555,6 +530,6 @@
}
}

func (c *Client) isActivity() bool {

Check failure on line 533 in pkg/gateway/lwm2m/client/lwm2m.go

View workflow job for this annotation

GitHub Actions / lint

func `(*Client).isActivity` is unused (unused)
return c.udpConnection != nil && time.Now().Before(c.lastUpdatedTime.Add(time.Duration(c.Settings.LifeTimeSec)*time.Second))
}
Loading