[riot-notifications] [RIOT-OS/RIOT] net/nanocoap: Buffer API Block implementation (#11002)

Ken Bannister notifications at github.com
Tue Feb 12 14:17:05 CET 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.

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()<br>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](https://github.com/kb2ma/riot-coap-pytest) repository. If you run coap_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

However, the new implementation does not generate the warning.
$ ./block1_client.py -r[${TAP_LLADDR_SUT}] -b 32
Result: 2.04 Changed

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](https://github.com/kb2ma/riot-apps/blob/kb2ma-master/nano-block-client/block_client.c) app.

### Issues/PRs references
Partially implements #10732. Depends on #10876.

You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * net/nanocoap: add inline function for Content-Format
  * net/gcoap: use coap_opt_finish within gcoap
  * net/gcoap: use coap_opt_finish in unit tests
  * net/gcoap: update module doc for coap_opt_finish
  * examples/gcoap: use coap_opt_finish()
  * examples/cord_epsim: use coap_opt_finish()
  * examples/cord_ep: use coap_opt_finish()
  * net/nanocoap: Return error from coap_opt_add_xxx() if no space
  * net/nanocoap: return error from coap_opt_finish if no space
  * net/nanocoap: clarify API buffer space doc
  * tests/nanocoap: verify error when overfill buffer
  * net/gcoap: verify error when overfill on coap_opt_finish
  * net/nanocoap: create function groups in module doc
  * net/nanocoap: reference new function sections
  * net/nanocoap: rename Options APIs for clarity
  * net/nanocoap: move detailed module doc to nanocoap_sock
  * net/nanocoap: refactor block option put
  * net/nanocoap: refactor block option control use
  * examples/nanocoap: use refactored block control function

-- File Changes --

    M examples/cord_ep/main.c (8)
    M examples/cord_epsim/main.c (4)
    M examples/gcoap/gcoap_cli.c (40)
    M examples/nanocoap_server/coap_handler.c (4)
    M sys/include/net/gcoap.h (85)
    M sys/include/net/nanocoap.h (1181)
    M sys/include/net/nanocoap_sock.h (104)
    M sys/net/application_layer/cord/ep/cord_ep.c (4)
    M sys/net/application_layer/cord/epsim/cord_epsim.c (2)
    M sys/net/application_layer/gcoap/gcoap.c (35)
    M sys/net/application_layer/nanocoap/nanocoap.c (38)
    M tests/unittests/tests-gcoap/tests-gcoap.c (46)
    M tests/unittests/tests-nanocoap/tests-nanocoap.c (12)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190212/7df8b2d9/attachment-0001.html>

More information about the notifications mailing list