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/nanocoap: Buffer API Block implementation #11002

Merged
merged 3 commits into from
Jul 30, 2019

Conversation

kb2ma
Copy link
Member

@kb2ma kb2ma commented Feb 12, 2019

Contribution description

Presently, the nanocoap Buffer API includes server side implementation of Block options. In other words, it includes block2 descriptive use (sends blockwise content) and block1 control use (receives/acks blockwise content). This PR extends the API to include block2 control use and block1 descriptive use for client side requests.

At the same time, this PR standardizes block function names to include "control" for control use, as shown in the table below.

Old Function New Function Notes
coap_opt_put_block2() coap_opt_put_block2() no change
N/A coap_opt_put_block2_control() new
coap_put_option_block1()
coap_put_block1_ok()
coap_opt_put_block1_control() coap_put_block1_ok() is a convenience function to only call coap_put_option_block1() if the more attribute is 1. This approach is in error; see below.
N/A coap_opt_put_block1() accepts a slicer struct, like coap_opt_put_block2()

Testing procedure

For this PR our main focus is refactoring the current implementation, so testing is for regression. Ensure the nanocoap_server example /sha256 and /riot/ver resources still work.

FWIW, I have functional tests in the riot-coap-pytest repository. If you run block1_client.py, which is a script for aiocoap to POST /sha256, you will see that the old implementation generates the warning below. This is due to coap_put_block1_ok() omitting the block option in the last ACK, as described in the table above. RFC 7959, sec. 3.2 also shows that the final response is expected to include the option in the final ACK.

$ ./block1_client.py -r[${TAP_LLADDR_SUT}] -b 32
WARNING:coap.blockwise-requester:Block1 option completely ignored by server, assuming it knows what it is doing.
Result: 2.04 Changed
b'C496DF5946783990BEC5EFDC2999530EEB9175B83094BAE66170FF2431FC896E'

However, the new implementation does not generate the warning.

$ ./block1_client.py -r[${TAP_LLADDR_SUT}] -b 32
Result: 2.04 Changed
b'C496DF5946783990BEC5EFDC2999530EEB9175B83094BAE66170FF2431FC896E'

The next PR in the sequence includes a couple of helper functions to make the new client side functions easy to use. We will add tests for those uses with that PR, but you can get a preview in the nano-block-client app.

Issues/PRs references

Partially implements #10732. Depends on #10876.

@kb2ma kb2ma added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: CoAP Area: Constrained Application Protocol implementations labels Feb 12, 2019
@kb2ma kb2ma added this to the Release 2019.04 milestone Feb 24, 2019
@kb2ma
Copy link
Member Author

kb2ma commented May 1, 2019

Now that #10876 has been merged, I will rebase here.

@kb2ma kb2ma force-pushed the coap/block_finish_proto branch from fb1b8aa to 0b56f2d Compare May 4, 2019 12:50
@kb2ma
Copy link
Member Author

kb2ma commented May 4, 2019

Rebased.

@kb2ma
Copy link
Member Author

kb2ma commented Jul 25, 2019

Rebased

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

Tested the nanocoap_server example, /riot/ver is working just as before. But with /shah I'm not getting the shah as a reply:

on master:

→ coap-client -m post coap://[2001:db8::7b7c:91a:4eaa:52de]/sha256 -f examples/nanocoap_server/README.md -b 64
93C814D956114A7FCF4C53580F3D5501AA04C0961C5C035C80C65AECBAE089DF

with this pr:

  ~/workspace/RIOT  |pr-11002 {119} ✓|
→ coap-client -m post coap://[2001:db8::7b7c:91a:4eaa:52de]/sha256 -f examples/nanocoap_server/README.md -b 64
  ~/workspace/RIOT  |pr-11002 {119} ✓|

@fjmolinas fjmolinas added the Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines label Jul 25, 2019
@fjmolinas
Copy link
Contributor

Tested the nanocoap_server example, /riot/ver is working just as before. But with /shah I'm not getting the shah as a reply:

I replicated the test using nano-block-client and I get the shah, but no payload is sent. I also get the shah when no payload is sent with coap-client:

coap-client -m post coap://[2001:db8::7b7c:91a:4eaa:52de]/sha256 -f examples/nanocoap_server/README.mda
cmdline_input_from_file: fopen: No such file or directory
E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855

@kb2ma
Copy link
Member Author

kb2ma commented Jul 26, 2019

I can recreate your results with the lastest libcoap master branch as client. However, it looks to me that the difference in the results is solely a feature of libcoap's text output. The sha256 output is included in the payload of the final ACK from the code in this PR's branch. The only difference in the final ACK is the addition of the block1 option. This addition is explained above in the description.

I think the change in the final ACK is the right thing to do, but I will take another look to confirm.

@kb2ma
Copy link
Member Author

kb2ma commented Jul 26, 2019

I am convinced that the fix to add the block1 option on the final response is correct. I also created obgm/libcoap#383 to output the response in this case.

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

I tested that there was no regression and although I had some unexpected output when testing with libcoap, it seems to be a problem with the upstream library and not the refactoring done with this PR. ACK

@fjmolinas fjmolinas 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 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 CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jul 29, 2019
@kb2ma
Copy link
Member Author

kb2ma commented Jul 29, 2019

Thanks, @fjmolinas! I'll wait a day before merging to give anyone else a chance to speak up.

@kb2ma kb2ma merged commit f4df9d7 into RIOT-OS:master Jul 30, 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: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants