-
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/nanocoap: Introduce coap_build_pkt_t and use it #17544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ | |
* this by uncommenting the appropriate lines in gcoap's make file. | ||
* | ||
* gcoap allows an application to specify a collection of request resource paths | ||
* it wants to be notified about. Create an array of resources (coap_resource_t | ||
* it wants to be notified about. Create an array of resources (gcoap_resource_t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you move that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same might be done for the link_encoder (i like these changes as they clearup where a structure is defined) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #17804 there you go There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this causes some issues with the Rust wrappers which in turn require a CI upgrade :( So if you don't insist on splitting this, could we move forward with this as a single PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't this PR trigger the same issue (if we restart murdock now) until rust is upgraded There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This section also provides a link to an example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
no, the rust wrapper uses the presence of
Maybe I miss something, but those are not using any of the functions that makes use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gcoap is using the nanocoap functions to generate the header coap_pkgs, while most of these generator functions do not make any use of I am no sure about the state of #17168 and #16855 especial in looking at block-transfers. May be this API change is also welcome to gcoap. While this PR tries to break just nanocoaps-API it implicitly also breaks gcoaps-API (@block-transfers). maybe @chrysn or @miri64 have some insight into what changes are going to happen in gcoap maybe this API-change is welcome and should just be forwarded to gcoap ( which might be easier since it may not need the introduction of 'gcoap_rescource_t'). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #17801 implements caching for gcoap and somehow also for nanocoap (using the old buf an len but introducing a nanocoap_-prefix) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please explain to me which function(s) you mean. If Gcoap would use on of the converted nanocoap functions, that would be a compilation error as Gcoap does not yet make use of There are functions in Blockwise GET is still working in |
||
* structs) ordered by the resource path, specifically the ASCII encoding of | ||
* the path characters (digit and capital precede lower case). Use | ||
* gcoap_register_listener() at application startup to pass in these resources, | ||
|
@@ -649,6 +649,32 @@ extern "C" { | |
|
||
/** @} */ | ||
|
||
/** | ||
* @brief Resource handler type | ||
* | ||
* Functions that implement this must be prepared to be called multiple times | ||
* for the same request, as the server implementations do not perform message | ||
* deduplication. That optimization is [described in the CoAP | ||
* specification](https://tools.ietf.org/html/rfc7252#section-4.5). | ||
* | ||
* This should be trivial for requests of the GET, PUT, DELETE, FETCH and | ||
* iPATCH methods, as they are defined as idempotent methods in CoAP. | ||
* | ||
* For POST, PATCH and other non-idempotent methods, this is an additional | ||
* requirement introduced by the contract of this type. | ||
*/ | ||
typedef ssize_t (*gcoap_handler_t)(coap_pkt_t *pkt, uint8_t *rbuf, size_t rlen, void *context); | ||
|
||
/** | ||
* @brief Type for CoAP resource entry | ||
*/ | ||
typedef struct { | ||
const char *path; /**< URI path of resource */ | ||
coap_method_flags_t methods; /**< OR'ed methods this resource allows */ | ||
gcoap_handler_t handler; /**< ptr to resource handler */ | ||
void *context; /**< ptr to user defined context data */ | ||
} gcoap_resource_t; | ||
|
||
/** | ||
* @brief Context information required to write a resource link | ||
*/ | ||
|
@@ -670,7 +696,7 @@ typedef struct { | |
* @return count of bytes written to @p buf (or writable if @p buf is null) | ||
* @return -1 on error | ||
*/ | ||
typedef ssize_t (*gcoap_link_encoder_t)(const coap_resource_t *resource, char *buf, | ||
typedef ssize_t (*gcoap_link_encoder_t)(const gcoap_resource_t *resource, char *buf, | ||
size_t maxlen, coap_link_encoder_ctx_t *context); | ||
|
||
/** | ||
|
@@ -701,7 +727,7 @@ typedef struct gcoap_listener gcoap_listener_t; | |
* @return GCOAP_RESOURCE_ERROR on processing failure of the request | ||
*/ | ||
typedef int (*gcoap_request_matcher_t)(gcoap_listener_t *listener, | ||
const coap_resource_t **resource, | ||
const gcoap_resource_t **resource, | ||
coap_pkt_t *pdu); | ||
|
||
/** | ||
|
@@ -738,7 +764,7 @@ typedef struct { | |
* @brief A modular collection of resources for a server | ||
*/ | ||
struct gcoap_listener { | ||
const coap_resource_t *resources; /**< First element in the array of | ||
const gcoap_resource_t *resources; /**< First element in the array of | ||
* resources; must order alphabetically */ | ||
size_t resources_len; /**< Length of array */ | ||
/** | ||
|
@@ -816,7 +842,7 @@ struct gcoap_request_memo { | |
*/ | ||
typedef struct { | ||
sock_udp_ep_t *observer; /**< Client endpoint; unused if null */ | ||
const coap_resource_t *resource; /**< Entity being observed */ | ||
const gcoap_resource_t *resource; /**< Entity being observed */ | ||
uint8_t token[GCOAP_TOKENLEN_MAX]; /**< Client token for notifications */ | ||
unsigned token_len; /**< Actual length of token attribute */ | ||
gcoap_socket_t socket; /**< Transport type to observer */ | ||
|
@@ -1020,7 +1046,7 @@ static inline ssize_t gcoap_response(coap_pkt_t *pdu, uint8_t *buf, | |
* @return GCOAP_OBS_INIT_UNUSED if no observer for resource | ||
*/ | ||
int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, | ||
const coap_resource_t *resource); | ||
const gcoap_resource_t *resource); | ||
|
||
/** | ||
* @brief Sends a buffer containing a CoAP Observe notification to the | ||
|
@@ -1036,7 +1062,7 @@ int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, | |
* @return 0 if cannot send | ||
*/ | ||
size_t gcoap_obs_send(const uint8_t *buf, size_t len, | ||
const coap_resource_t *resource); | ||
const gcoap_resource_t *resource); | ||
|
||
/** | ||
* @brief Provides important operational statistics | ||
|
@@ -1112,7 +1138,7 @@ static inline int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf) | |
* @return count of bytes written to @p buf (or writable if @p buf is null) | ||
* @return -1 on error | ||
*/ | ||
ssize_t gcoap_encode_link(const coap_resource_t *resource, char *buf, | ||
ssize_t gcoap_encode_link(const gcoap_resource_t *resource, char *buf, | ||
size_t maxlen, coap_link_encoder_ctx_t *context); | ||
|
||
#if IS_USED(MODULE_GCOAP_DTLS) || defined(DOXYGEN) | ||
|
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.
This clearly is an improvement in regard to usability :)
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.
And it can be used to avoid having to copy the payload into a separate buffer #17559