-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sys: net: add nanocoap #8123
Conversation
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... |
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). 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? |
I've reinstated this for now, as we should discuss/fix that apart from this integration PR. |
one general question: why keeping the name |
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. |
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 By keeping unique names for modules (e.g. |
+1 |
There was a problem hiding this 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.
sys/include/net/nanocoap_sock.h
Outdated
int nanocoap_server(sock_udp_ep_t *local, uint8_t *buf, size_t bufsize); | ||
|
||
/** | ||
* @brief simple synchronous CoAP get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple?!
sys/include/net/nanocoap_sock.h
Outdated
* @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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sys/include/net/nanocoap.h
Outdated
#define COAP_PORT (5683) | ||
|
||
/** | ||
* @name nanocoap specific maximum values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capitalize first word
sys/include/net/nanocoap.h
Outdated
typedef ssize_t (*coap_handler_t)(coap_pkt_t* pkt, uint8_t *buf, size_t len); | ||
|
||
/** | ||
* @brief Type for CoAP resource entry |
There was a problem hiding this comment.
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
sys/include/net/nanocoap.h
Outdated
* | ||
* 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 |
There was a problem hiding this comment.
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...)
sys/include/net/nanocoap.h
Outdated
unsigned code, | ||
uint8_t *buf, size_t len, | ||
unsigned ct, | ||
const uint8_t *payload, uint8_t payload_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indention
sys/include/net/nanocoap.h
Outdated
* | ||
* @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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. | ||
*/ | ||
|
There was a problem hiding this comment.
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?
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 ? |
More generic than what? And where do you get the notion than stuff in "sys/" "should be generic"?
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.
We decided to move it to the main RIOT repo because it sucks to keep PRs in sync with two interdependant repositories. |
@haukepetersen I think I got all the style comments, and changed _sock to be a submodule. |
except the missing doxygen blocks in the c-files... |
There was a problem hiding this 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...
185d925
to
3367840
Compare
* @name Timing parameters | ||
* @{ | ||
*/ | ||
#define COAP_ACK_TIMEOUT (2U) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
This PR removes the nanocoap package and imports the code instead.