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: net: add nanocoap #8123

Merged
merged 6 commits into from
Dec 1, 2017
Merged

sys: net: add nanocoap #8123

merged 6 commits into from
Dec 1, 2017

Conversation

kaspar030
Copy link
Contributor

This PR removes the nanocoap package and imports the code instead.

@kaspar030 kaspar030 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 23, 2017
@haukepetersen
Copy link
Contributor

Awesome, will review later today. So as I was involved in getting the code ready to be PRed, I think it makes sense to have at least one other review...

@kaspar030
Copy link
Contributor Author

Hm. The imported nanocoap has some (minor) changes. One is that it now doesn't ignore the CoAP host option anymore (see kaspar030/sock#5, kaspar030/sock#22).
That is not a problem per-se, but the (binary) packet used in gcoap's unittests contains that option, thus the unittests fails.

Either we again ignore that option (as in current master, but against specs), or we change the packet in the unittests.

@kb2ma what do you think?

@kaspar030
Copy link
Contributor Author

Either we again ignore that option (as in current master, but against specs)

I've reinstated this for now, as we should discuss/fix that apart from this integration PR.

@aabadie
Copy link
Contributor

aabadie commented Nov 23, 2017

one general question: why keeping the name nanocoap ? and not just simply rename to coap ?

@kb2ma
Copy link
Member

kb2ma commented Nov 23, 2017

IIRC, the unit test was written from libcoap as it worked at the time. I suggest removing the Uri-Host option from the unit test. I agree it's simplest to ignore Uri-Host and merge nanocoap first, and then fix this issue separately.

@haukepetersen
Copy link
Contributor

one general question: why keeping the name nanocoap ? and not just simply rename to coap ?

Because it is good practice to give modules a unique name, independent of what they implement. So say there is a new coap implementation by someone popping up tomorrow, what reasoning should we have to call nanocaop coap, but force the new implementation to have a different name and not make that the coap named implementation?

By keeping unique names for modules (e.g. gcoap, nanocaop, or same for emcute), we allow for multiple implementations of the same protocol(s) without ever getting in trouble naming them...

@haukepetersen
Copy link
Contributor

I've reinstated this for now, as we should discuss/fix that apart from this integration PR.

+1

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.

Mostly picky things. The only non-trivial thing I noticed concerns making nanocaop_sock a sub-module.

int nanocoap_server(sock_udp_ep_t *local, uint8_t *buf, size_t bufsize);

/**
* @brief simple synchronous CoAP get
Copy link
Contributor

Choose a reason for hiding this comment

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

Simple?!

* @returns length of response on success
* @returns <0 on error
*/
ssize_t nanocoap_get(sock_udp_ep_t *remote, const char *path, uint8_t *buf, size_t len);
Copy link
Contributor

Choose a reason for hiding this comment

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

line length

@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now nanocoap_sock.c is always build, but not always needed (e.g. for gcoap), right? I think it would make much sense to make nanocoap_sock a sub-module of nanocoap, so that I must be enabled explicitly by using USEMODULE += nanocoap_sock e.g. in the example application above. Makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

#define COAP_PORT (5683)

/**
* @name nanocoap specific maximum values
Copy link
Contributor

Choose a reason for hiding this comment

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

capitalize first word

typedef ssize_t (*coap_handler_t)(coap_pkt_t* pkt, uint8_t *buf, size_t len);

/**
* @brief Type for CoAP resource entry
Copy link
Contributor

Choose a reason for hiding this comment

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

should be 3 spaces after @brief

*
* This function can be used to create a reply to any CoAP request packet. It
* will create the reply packet header based on parameters from the request
* (e.g., id, token). Passing a nonzero @p payload_len will ensure the payload
Copy link
Contributor

Choose a reason for hiding this comment

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

I think non-zero is the more common spelling (according to google...)

unsigned code,
uint8_t *buf, size_t len,
unsigned ct,
const uint8_t *payload, uint8_t payload_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

indention

*
* @returns length of resulting header
*/
ssize_t coap_build_hdr(coap_hdr_t *hdr, unsigned type, uint8_t *token, size_t token_len, unsigned code, uint16_t id);
Copy link
Contributor

Choose a reason for hiding this comment

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

line length

* @param[in] uri ptr to source URI
* @param[in] optnum option number to use (e.g., COAP_OPT_URI_PATH)
*
* @returns amount of bytes written to @p buf
Copy link
Contributor

Choose a reason for hiding this comment

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

Although @returns and @return do the same thing, at least inside a single file we should be consistent in the usage... Further check the indention after the @return(s) statements, we have also two styles in this file...

* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

No doxygen block in this file. I know it is not parsed anyway, but still useful e.g. for the author tags etc and AFAIK it is standard that we put it in every C file, is it not?

@aabadie
Copy link
Contributor

aabadie commented Nov 27, 2017

what reasoning should we have to call nanocaop coap, but force the new implementation to have a different name and not make that the coap named implementation?

I think this is a more global question. nanocoap is going in the sys/ of RIOT so for me it should be generic, e.g it should provide and be compatible with CoAP standard with core functionalities (type of messages, error codes, etc) and basic functions. Maybe we could also consider merging gcoap and nanocoap ?
nanocoap was initially designed to be a package on its own, why not providing it on a separate repo on GitHub: nanocoap/nanocoap => this may increase its visibility and it could still be integrated in RIOT as a package. The situation now is different since nanocoap is a subfolder of a personal repository, which gives less visibility IMHO.

@kaspar030
Copy link
Contributor Author

I think this is a more global question. nanocoap is going in the sys/ of RIOT so for me it should be generic

More generic than what? And where do you get the notion than stuff in "sys/" "should be generic"?

Maybe we could also consider merging gcoap and nanocoap ?

There's been a lot of discussion around this, both online and offline. Short answer: one stays with focus on minimal resource usage, the other re-uses as much code as possible but provides all features.

nanocoap was initially designed to be a package on its own, why not providing it on a separate repo on GitHub: nanocoap/nanocoap => this may increase its visibility and it could still be integrated in RIOT as a package. The situation now is different since nanocoap is a subfolder of a personal repository, which gives less visibility IMHO.

We decided to move it to the main RIOT repo because it sucks to keep PRs in sync with two interdependant repositories.

@kaspar030
Copy link
Contributor Author

@haukepetersen I think I got all the style comments, and changed _sock to be a submodule.

@haukepetersen
Copy link
Contributor

except the missing doxygen blocks in the c-files...

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.

ACK anyway - fix doxygen blocks in the c files at will, I won't block this PR because of that...

@haukepetersen haukepetersen added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 30, 2017
@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 1, 2017
@kaspar030 kaspar030 merged commit 830d968 into RIOT-OS:master Dec 1, 2017
@kaspar030 kaspar030 deleted the add_nanocoap branch December 1, 2017 12:25
@aabadie aabadie added this to the Release 2018.01 milestone Jan 18, 2018
* @name Timing parameters
* @{
*/
#define COAP_ACK_TIMEOUT (2U)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was such a large timeout value chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

/* if code is COAP_CODE_EMPTY (zero), use RST as type, else RESP */
unsigned type = code ? COAP_RESP : COAP_RST;
Copy link
Contributor

@benpicco benpicco Jan 9, 2024

Choose a reason for hiding this comment

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

What about separate response where we reply with an empty ACK?
This will always turn this into a RST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR 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.

5 participants