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

Generic subject observer (RFC 7641) support #68

Closed
jasta opened this issue Feb 18, 2022 · 5 comments
Closed

Generic subject observer (RFC 7641) support #68

jasta opened this issue Feb 18, 2022 · 5 comments

Comments

@jasta
Copy link
Contributor

jasta commented Feb 18, 2022

The observer support today is a very useful start however it's missing a few key APIs to customize it to work similar to other CoAP implementations and, more importantly, generalized to the use cases described in RFC 7641. For example, the support requires that PUT request be issued in order for the system to work, even though we wouldn't normally expect read-only endpoints to have such a feature. Further, the implementation is just a limited replaying of the last PUT payload without any of the handling consideration that you'd get with a GET request (like if the GET response included ContentFormat options, the resulting notification for this resource path would not include that information).

I believe this can be addressed relatively easily but the easy way will break a few implementation assumptions and change the public API. For those reasons I wanted to open a dialog to make sure my assumptions are correct and my goals are consistent with the projects before proceeding to a pull request. Specifically, the following changes should make this possible:

  1. A limited portion of the Observer features becomes visible from the Server object such that stateless components can invoke an API like server.resource_changed(path).
  2. PUT would no longer automatically affect resources or perform caching, but instead a synthetic GET request would be injected and handled in response to server.resource_changed(path). This response would be cached instead and copied to all observing clients.
  3. Resource observing eligibility would be based on the response issued when handling the initial GET {Observe:0} request rather than being assumed valid in response to a PUT. For example, if the initial GET request yields a 4.xx error, the observe would be rejected.

What do you think of these changes? Are you interested in me proceeding with a possible PR?

Thanks for the great project, this is really helping me get a cool project of mine off the ground using an ultra low powered old Lego EV3 brick as the hub!

@Covertness
Copy link
Owner

I'm glad to hear that the repository can help you.

The first change is wonderful. The observer feature will be easier to use. But the other changes will break the origin definition from RFC 7641. I think they are not fit for the coap library. please correct me if i misunderstood.

@jasta
Copy link
Contributor Author

jasta commented Feb 20, 2022

I'm interested to learn more about your concerns on the other changes. I informed my original recommendation by reading RFC 7641 and other CoAP server implementations and as I understand it the intention of RFC 7641 is that observe notifications should be identical with the exception of the Observe/Token options to simply re-issuing a GET request. More formally, an observed GET request should yield a stream of updates that are eventually consistent with any future regular GET request. Thus logically saying that a resource changed is most consistent with simply presuming that to be the same as making a GET request and sending the response with the Observe/Token options synthesized onto the response.

Also note regarding #3, I meant to say that a failed GET request would logically deny observation and that it would not be tied to the PUT request at all (currently coap-rs simply yields a 4.04 if you issue a GET Observe:0 request to something that you have not previously PUT into). I wrongly implied that the coap-rs implementation would require all GET requests to be observable. That said, a handler should be able to deny observability in the current implementation by simply yielding a 4.xx code if the Observe flag is set which should cover our bases.

Do you have an example of something you'd prefer to see that better matches how RFC 7641 is defined?

@Covertness
Copy link
Owner

You are right. Some functions are not implement. But I think the former actions should be reserved, e.g. the PUT request automatically affect resources.

@jasta
Copy link
Contributor Author

jasta commented Feb 20, 2022

PUT, POST, and DELETE can automatically trigger a resource change event, however we have to be careful there because only certain response codes would indicate that a change indeed occurred. For example, a PUT request that is rejected with 4.xx should not trigger notifications. I think I can come up with a best effort set of cases that should cover common uses but still be flexible for developers to control how it works.

@jasta
Copy link
Contributor Author

jasta commented Apr 28, 2022

Unfortunately after trying pretty hard to make Observe support integration work I've decided I need to go a different direction and start a new project with a higher level API goal for cleaner integration: https://github.com/jasta/coap-server-rs. While coap-rs has been extremely useful in getting me started there are some pretty significant architectural challenges that would need to be overcome for good generic support for more advanced features and that would end up taking the project in a very different direction with potentially a lot of disruption to current users. For now I'm choosing to incubate a more experimental but convenient approach in the linked repo above (which does have transparent Observe and Block-wise support)

For an example of how this new API I'm using supports observe, see: https://github.com/jasta/coap-server-rs/blob/main/examples/app_observable.rs

@jasta jasta closed this as completed Apr 28, 2022
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

No branches or pull requests

2 participants