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

sys: Add Link Format module #11189

Merged
merged 2 commits into from Oct 5, 2019

Conversation

leandrolanzieri
Copy link
Contributor

@leandrolanzieri leandrolanzieri commented Mar 14, 2019

Contribution description

This PR adds a simple CoRE Link Format module to encode and decode strings, together with a set of unit test cases.

It can be used for describing the registered CoAP resources (#11171) or registering them on a resource directory. It can be also useful for parsing the responses when looking up on a resource directory (#10222).

In this PR also the resource listing of gcoap is modified to use some of the basic functionalities of the module.

Testing procedure

  • Go to tests/unittests and run make tests-link_format test. For a detailed output add CFLAGS=-DTESTS_LINK_FORMAT_PRINT.
  • Run any application that uses gcoap and list the resources by sending a GET request to /.well-known/core.

Issues/PRs references

See also #11171
Could be of use in #10222

@leandrolanzieri leandrolanzieri added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Mar 14, 2019
@leandrolanzieri
Copy link
Contributor Author

Maybe @pokgak want to take a look?

Copy link
Contributor

@pokgak pokgak left a comment

Choose a reason for hiding this comment

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

Looks good to me. Left some comment on the changes in gcoap. Also maybe the behaviour of the module when passing NULL as output buffer should be mentioned. Had to look in gcoap for that one.

sys/net/application_layer/gcoap/gcoap.c Outdated Show resolved Hide resolved
sys/net/application_layer/gcoap/gcoap.c Outdated Show resolved Hide resolved
@kaspar030
Copy link
Contributor

Hm, "link format" is not specific enough as a name, but "core_link_format" is difficult in RIOT...

@leandrolanzieri
Copy link
Contributor Author

Also maybe the behaviour of the module when passing NULL as output buffer should be mentioned

@pokgak Added documentation on functions. Also fixed link_format_encode_link to follow that behavior, add added it on the unit test.

@smlng smlng added the Area: CoAP Area: Constrained Application Protocol implementations label Mar 21, 2019
@leandrolanzieri
Copy link
Contributor Author

Hm, "link format" is not specific enough as a name, but "core_link_format" is difficult in RIOT...

What about "coap_core_link_format"? @smlng @kb2ma any opinion on that?

Copy link
Contributor

@haukepetersen haukepetersen left a comment

Choose a reason for hiding this comment

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

Just did a quick scroll through the code, so no proper review. But I think this looks quite good to me.

One remark on the PR structure: it might make sense to cut the changes to gcoap out and PR them separately...

sys/include/link_format.h Outdated Show resolved Hide resolved
@haukepetersen
Copy link
Contributor

on the naming: how about clf_ (serious)? Or by my personal naming scheme it would be rosalinde (not) :-)

@haukepetersen
Copy link
Contributor

or core_lf_?

@leandrolanzieri
Copy link
Contributor Author

One remark on the PR structure: it might make sense to cut the changes to gcoap out and PR them separately...

Removed changes to gcoap, will open a separate PR

@leandrolanzieri
Copy link
Contributor Author

on the naming: how about clf_ (serious)? Or by my personal naming scheme it would be rosalinde (not) :-)

mmm Now I kind of like clif

@haukepetersen
Copy link
Contributor

+1 for clif, I like it!

* @brief Link format parameter descriptor
*/
typedef struct {
clif_param_type_t type; /**< type of parameter */
Copy link
Member

Choose a reason for hiding this comment

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

Is it worthwhile to include this here and generate it with each call to clif_get_param()? Maybe create a separate unsigned clif_get_param_type(const char *key) and let the user decide when to use it.

In this case the char *ext attribute becomes char *key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable, I will change this.

sys/include/clif.h Outdated Show resolved Hide resolved
kb2ma
kb2ma previously requested changes Apr 1, 2019
Copy link
Member

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

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

I agree that the additions to the link format implementation warrant the separate module in this PR. It also makes sense for gcoap and nanocoap to use this API, and it's proably worth a separate PR for that work.

I added a comment to #11171 on extending CoAP resources. Given the use cases there, I favor the lower level aspects of the clif API. The functions provide a stream-like API where the client provides or collects the input, and then loops through it to execute the functions to read/write the target and params.

For encoding, clif_add_target(), clif_add_param(), and clif_add_link_separator() are necessary. gcoap_get_resource_list() provides an example of looping through the resources, but it needs clif_add_param_list(const char *list) since it likely already is encoded for each coap_resource_t as suggested in #11171.

For decoding, use clif_get_target() and clif_get_param() over an input string. For resource lookup in #10222, the source string could be collected with cord_lc_res_raw().

Beyond these functions, for clif_decode_links(), how to predict the number of links and params to expect, and why use all that memory up front? Maybe just a singular clif_decode_link() is sufficient. This logically matches to clif_encode_link().

See other inline comments, too.

@leandrolanzieri
Copy link
Contributor Author

but it needs clif_add_param_list(const char *list)

Would this only append to a buffer the ';' character and the given string?

@kb2ma I removed the type from the structure, also modified the decoding function do it one link at a time and accept a NULL as param array and return the needed amount of parameters.

@leandrolanzieri
Copy link
Contributor Author

@kb2ma are you ok with the changes?

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

first review round mostly on documentation, there should also be a reference to RFC 6690 which this is implementing

sys/clif/Makefile Outdated Show resolved Hide resolved
sys/clif/include/clif_internal.h Outdated Show resolved Hide resolved
@leandrolanzieri
Copy link
Contributor Author

first review round mostly on documentation, there should also be a reference to RFC 6690 which this is implementing

@smlng Thanks for reviewing, I addressed the comments and added the RFC 6690 reference.

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

some more reviewing

sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Show resolved Hide resolved
@kb2ma kb2ma dismissed their stale review June 27, 2019 02:50

Revising review after fixups

@kb2ma kb2ma added Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines labels Sep 23, 2019
sys/include/clif.h Outdated Show resolved Hide resolved
sys/include/clif.h Outdated Show resolved Hide resolved
sys/include/clif.h Outdated Show resolved Hide resolved
sys/include/clif.h Outdated Show resolved Hide resolved
@kb2ma kb2ma added Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Sep 23, 2019
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 23, 2019
@kb2ma
Copy link
Member

kb2ma commented Sep 23, 2019

This all looks good now, @leandrolanzieri! The decoding logic is easy to follow. If you can address the const parameters and the parameter documentation, I'm ready to approve. Let's try to get this in for 2019.10 if you've got the time.

@kb2ma
Copy link
Member

kb2ma commented Sep 23, 2019

@smlng, would you please confirm your concerns have been addressed.

@leandrolanzieri
Copy link
Contributor Author

@kb2ma Thanks for the review! I went over the API fixing the constant parameters, also I fixed doc errors I found, including the example snippet.

sys/clif/clif.c Outdated Show resolved Hide resolved
sys/include/clif.h Outdated Show resolved Hide resolved
@kb2ma
Copy link
Member

kb2ma commented Sep 26, 2019

@leandrolanzieri, I apologize for not being more specific in my earlier comments about making elements const. My thinking was that for clif_decode_link() it was reasonable to say we would not modify the input buffer. I agree this reasoning carries through to clif_get_attr().

I don't think we can carry this through to the clif_attr_t struct in general through because it may be created or used in other contexts besides reading an input string. I'm OK with the const on the 'key' attribute for reasons we discussed earlier.

Honestly I am not an expert at use of const though, so let me know if you agree.

@leandrolanzieri
Copy link
Contributor Author

@leandrolanzieri, I apologize for not being more specific in my earlier comments about making elements const. My thinking was that for clif_decode_link() it was reasonable to say we would not modify the input buffer. I agree this reasoning carries through to clif_get_attr().

I don't think we can carry this through to the clif_attr_t struct in general through because it may be created or used in other contexts besides reading an input string. I'm OK with the const on the 'key' attribute for reasons we discussed earlier.

Honestly I am not an expert at use of const though, so let me know if you agree.

@kb2ma Sure, sorry about that. It makes sense that the value can be created by the application so it should not be const. Changed!

@kb2ma
Copy link
Member

kb2ma commented Sep 26, 2019

Looks good to me! Please squash. I really like the detailed unit tests. Let's get some real world use now and see how it works.

ping @smlng to reconsider review

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

I would generally opt for single condition in assert not combining 2 (or more), also would avoid goto especially where I pointed out there is no specific benefit.

sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/clif/clif.c Outdated Show resolved Hide resolved
sys/include/clif.h Outdated Show resolved Hide resolved
@leandrolanzieri
Copy link
Contributor Author

@smlng thanks for the review.

I would generally opt for single condition in assert not combining 2 (or more),

Changed.

also would avoid goto especially where I pointed out there is no specific benefit.

I usually tend to prioritize having a single point of return and the flow seemed clear to me to use the gotos, but I don't really have a strong opinion in this case.

All comments should be addressed now.

@smlng
Copy link
Member

smlng commented Oct 2, 2019

please squash

@leandrolanzieri leandrolanzieri added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 2, 2019
This module implements a simple encoder and decoder of CoRE Link Format
(RFC 6690).
@kb2ma kb2ma merged commit 033b60b into RIOT-OS:master Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants