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

net: Enhance observation management with ETag tracking #469

Merged
merged 3 commits into from
Aug 8, 2023

Conversation

Danielius1922
Copy link
Member

This commit introduces an enhancement to the observation mechanism in the network module by implementing ETag tracking. The latest ETag value associated with each observation is now stored in the internal representation.

With this update, each incoming message containing the ETag CoAP option automatically updates the ETag value for the relevant observation. When an observation is canceled, the stored ETag value is utilized. When the server detects a valid ETag match, it now responds with a VALID code and an empty payload instead of resending the content of the resource. This optimization minimizes unnecessary data transfer and reduces network load.

This commit introduces an enhancement to the observation mechanism
in the network module by implementing ETag tracking. The latest ETag
value associated with each observation is now stored in the internal
representation.

With this update, each incoming message containing the ETag CoAP option
automatically updates the ETag value for the relevant observation.
When an observation is canceled, the stored ETag value is utilized.
When the server detects a valid ETag match, it now responds with a
VALID code and an empty payload instead of resending the content
of the resource. This optimization minimizes unnecessary data transfer
and reduces network load.
@codecov-commenter
Copy link

codecov-commenter commented Aug 8, 2023

Codecov Report

Merging #469 (906eb11) into master (f73387a) will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #469      +/-   ##
==========================================
+ Coverage   72.16%   72.26%   +0.10%     
==========================================
  Files          70       70              
  Lines        5461     5470       +9     
==========================================
+ Hits         3941     3953      +12     
+ Misses       1123     1120       -3     
  Partials      397      397              
Files Changed Coverage Δ
net/observation/handler.go 84.21% <100.00%> (+1.95%) ⬆️

... and 3 files with indirect coverage changes

@Danielius1922 Danielius1922 marked this pull request as ready for review August 8, 2023 08:38
@@ -240,6 +251,9 @@ func (o *Observation[C]) wantBeNotified(r *pool.Message) bool {
if ValidSequenceNumber(o.private.obsSequence, obsSequence, o.private.lastEvent, now) {
o.private.obsSequence = obsSequence
o.private.lastEvent = now
if etag, err := r.ETag(); err == nil {
o.private.etag = etag
Copy link
Member

@jkralik jkralik Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use copy instead of assignation -> the underlayer buffer could be reused.
on new observation preallocate buffer with 8 bytes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy() copies works based on length not capacity, so if the lengths do not match I have to allocate a new slice

@sonarcloud
Copy link

sonarcloud bot commented Aug 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

88.2% 88.2% Coverage
0.0% 0.0% Duplication

@jkralik jkralik merged commit 3625c08 into master Aug 8, 2023
10 checks passed
@jkralik jkralik deleted the adam/feature/etag branch August 8, 2023 13:25
HRogge pushed a commit to HRogge/go-coap that referenced this pull request Oct 26, 2023
* net: Enhance observation management with ETag tracking

This commit introduces an enhancement to the observation mechanism
in the network module by implementing ETag tracking. The latest ETag
value associated with each observation is now stored in the internal
representation.

With this update, each incoming message containing the ETag CoAP option
automatically updates the ETag value for the relevant observation.
When an observation is canceled, the stored ETag value is utilized.
When the server detects a valid ETag match, it now responds with a
VALID code and an empty payload instead of resending the content
of the resource. This optimization minimizes unnecessary data transfer
and reduces network load.

---------

Co-authored-by: Jozef Kralik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants