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

Observe implementation #2

Merged
merged 9 commits into from
Dec 6, 2020
Merged

Conversation

jiayihu
Copy link
Contributor

@jiayihu jiayihu commented Dec 4, 2020

This is an implementation of the Observe RFC 7252 based on the one in coap-rs/observe.rs with some noticeable differences.

  • Naming: I've used the official names from the RFC, which are Observer and Subject for the subscribing client and the struct holding the subscriptions for the resources. The original impl calls them "register" and "Observer".
  • Simplified data structure: instead of having 3 maps for observers, subjects and (observer, resource) pairs, I've kept only one map BTreeMap<ResourcePath, Resource<Endpoint>>
  • ACK behaviour
    • afaik the original impl expects an ack for each notification message of a resource change. If the ack is not received it will poll a timer and repeat the notification until a limit of 10 times by default. Also an ack is accepted only if it has the same message id of the last message
    • my impl is simpler and thus also less complete. The lib user sends a notification only when there is an actual change in the resource and it keeps track of how many updates haven't received an ack yet. If the observer sends an ack with a matching token then the counter is reset. It doesn't matter if the message id is the same of the last notification, it's fine to receive an ack for some previous update. The packet could have been delayed in the network, but it means that the client is still interested in the resource. It also avoids the device sending multiple updates if the client is not answering.
  • Scope: my impl doesn't handle packet handling and generation. It also doesn't store the state of the resources. It's just a struct to keep the state of the observers. Packet handling is done externally. As example for anyone interested in future, I've wrote an implementation of a simple Server which uses smoltcp here. The implementation could actually be moved here in future if someone else needs it.

@martindisch give me some more time to test the implementation but the initial tests are promising 😄

@martindisch
Copy link
Owner

Very nice!

@jiayihu jiayihu changed the title Observe implementation (WIP) Observe implementation Dec 5, 2020
@jiayihu
Copy link
Contributor Author

jiayihu commented Dec 5, 2020

I think it can be merged now, I've tested today that the basic flow works with an actual connection. I may open more PRs if I'll notice issues when I'll have more time in future to use it more exhaustively

@martindisch
Copy link
Owner

Thank you, I appreciate that you took the time to explain the differences of your implementation and to document the exported types.

@martindisch martindisch merged commit a8ec4b5 into martindisch:master Dec 6, 2020
@jiayihu jiayihu deleted the observe branch December 6, 2020 17:21
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

2 participants