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

zephyr: coap: add cancel observations #468

Merged
merged 10 commits into from
May 20, 2024
Merged

Conversation

szczys
Copy link
Contributor

@szczys szczys commented Apr 29, 2024

Add ability to remove observations from the client coap_reqs lists, and mark the observation slots as not in_use. The cancellation process sends an "eager release" coap packet to the server indicating the observation has been cancelled.

This searches the coap_reqs linked list by matching the request message pointer which is why the coap_client.h header was included. I think a future improvement to how observations are handled should be storing crucial observation values instead of the the request message. If we store the coap token as one of those values, it can be used to search in the coap_reqs.

Copy link

github-actions bot commented Apr 29, 2024

Visit the preview URL for this PR (updated for commit 724cfae):

https://golioth-firmware-sdk-doxygen-dev--pr468-szczys-cancel-87so7hvd.web.app

(expires Mon, 27 May 2024 19:07:21 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: a9993e61697a3983f3479e468bcb0b616f9a0578

Copy link

github-actions bot commented Apr 29, 2024

Code Coverage

Type Coverage
lines 58.9% (1252 of 2125 lines)
functions 66.3% (124 of 187 functions)

@szczys szczys force-pushed the szczys/cancel_observations branch from 5ad8222 to db9d4c4 Compare May 1, 2024 14:31
@szczys szczys marked this pull request as draft May 1, 2024 14:38
@szczys szczys force-pushed the szczys/cancel_observations branch from db9d4c4 to 91ec330 Compare May 1, 2024 16:29
@szczys szczys changed the base branch from main to szczys/fix_add_observation May 1, 2024 16:30
@szczys szczys marked this pull request as ready for review May 1, 2024 16:30
@szczys szczys marked this pull request as draft May 1, 2024 19:32
@szczys szczys force-pushed the szczys/cancel_observations branch 3 times, most recently from f938d13 to cb62433 Compare May 2, 2024 21:44
@szczys szczys changed the base branch from szczys/fix_add_observation to main May 2, 2024 21:44
@szczys szczys force-pushed the szczys/cancel_observations branch from cb62433 to 161664d Compare May 2, 2024 21:50
@szczys szczys changed the base branch from main to szczys/fix_add_observation May 2, 2024 22:37
@szczys szczys marked this pull request as ready for review May 2, 2024 22:38
@szczys szczys force-pushed the szczys/fix_add_observation branch from 6ad8ec9 to 4b4040e Compare May 6, 2024 18:17
Base automatically changed from szczys/fix_add_observation to main May 7, 2024 20:52
@szczys szczys force-pushed the szczys/cancel_observations branch from 161664d to 26ecaa6 Compare May 7, 2024 20:59
Copy link
Contributor

@sam-golioth sam-golioth left a comment

Choose a reason for hiding this comment

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

Great work cutting through the cruft here @szczys!

The way zephyr_coap_req is interacting with coap_client_zephyr feels a little weird - can we see if there's a way to simplify that?

src/coap_client_zephyr.c Outdated Show resolved Hide resolved
src/coap_client_zephyr.c Show resolved Hide resolved
src/coap_client_zephyr.c Outdated Show resolved Hide resolved
src/zephyr_coap_req.c Outdated Show resolved Hide resolved
src/coap_client.c Show resolved Hide resolved
src/coap_client.c Show resolved Hide resolved
@szczys szczys force-pushed the szczys/cancel_observations branch from 26ecaa6 to 5752223 Compare May 9, 2024 20:25
@szczys szczys force-pushed the szczys/cancel_observations branch from 5752223 to 19334fc Compare May 10, 2024 16:56
src/coap_client.c Outdated Show resolved Hide resolved
src/coap_client.h Outdated Show resolved Hide resolved
src/coap_client.h Outdated Show resolved Hide resolved
src/zephyr_coap_req.c Outdated Show resolved Hide resolved
src/zephyr_coap_req.c Outdated Show resolved Hide resolved
Check that path length will fit into the path member of a
golioth_coap_request_msg_t before trying to copy the string.

Signed-off-by: Mike Szczys <[email protected]>
The golioth_coap_client_observe_async() command is renamed to
golioth_coap_client_observe(). This doesn't change functionality, but
merely makes the function name shorted as async is assumed for all
observations.

Signed-off-by: Mike Szczys <[email protected]>
Introduce function that adds a coap "eager release" for telling the server
we want to cancel an observation.

Signed-off-by: Mike Szczys <[email protected]>
Notify the server that we are cancelling an observation.

Signed-off-by: Mike Szczys <[email protected]>
Observe requests are stored in the client coap_reqs linked list. Walk the
coap_reqs list, comparing the user_data pointer to each client observe slot
address.

Observations are cancelled by setting the client observations slot as
!in_use, removing the request from the coap_reqs list, then sending an
"eager release" request to the server using the original token, path, etc.
Finally, the request memory is freed.

Signed-off-by: Mike Szczys <[email protected]>
Handle requests of the GOLIOTH_COAP_REQUEST_OBSERVE_CANCEL type by sending
an "eager release" to the server indicating an observation is being
cancelled.

Signed-off-by: Mike Szczys <[email protected]>
Observation updates are received from the server as unsolicited requests.
The token will always match the token used when the observation was
registered. The client observations list stores a copy of the original
request message that contains the token to compare against, as well as the
callback to notify.

Observations are cancelled by settings the client observations slot as
!in_use, then sending an "eager release" request to the server using the
original token, path, etc.

Signed-off-by: Mike Szczys <[email protected]>
Add wrapper function around the port-specific cancel functions.

Signed-off-by: Mike Szczys <[email protected]>
This tests that observations can be cancelled and reestablished. This is
currently an internal API which will be extended to service APIs in future
work.

Signed-off-by: Mike Szczys <[email protected]>
Correct the name of the board used in the build step for running tests
locally.

Signed-off-by: Mike Szczys <[email protected]>
@szczys szczys force-pushed the szczys/cancel_observations branch from 19334fc to 724cfae Compare May 20, 2024 19:06
@szczys szczys requested a review from sam-golioth May 20, 2024 19:11
Copy link
Contributor

@sam-golioth sam-golioth left a comment

Choose a reason for hiding this comment

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

Great work on this one @szczys! Quite the beast to wrangle.

@szczys szczys merged commit 19bedbe into main May 20, 2024
41 of 42 checks passed
@szczys szczys deleted the szczys/cancel_observations branch May 20, 2024 21:51
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.

None yet

3 participants