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

nanocoap_sock: split generic request function of from nanocoap_get #9086

Merged
merged 1 commit into from
Jun 20, 2018

Conversation

bergzand
Copy link
Member

@bergzand bergzand commented May 6, 2018

Contribution description

The nanocoap_get function is refactored to split of the request part
into a separate function for reuse by other modules. Support for
retransmissions when the received frame is malformed is dropped as it
was broken anyway.

Issues/PRs references

None

@bergzand bergzand added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking labels May 6, 2018
@bergzand bergzand requested a review from kaspar030 May 6, 2018 12:46
@kb2ma
Copy link
Member

kb2ma commented May 6, 2018

I agree that it makes sense to separate the generic packet sending mechanism from sending/handling a simple GET.

Use of the coap_pkt_t for the nanocoap_request() meshes well with #9085, which provides a mechanism for building the packet struct. That PR will further simplify the packet building code in nanocoap_get().

I expect it's also nice to save that memmove() in the response handling if you have other plans. :-)

@bergzand
Copy link
Member Author

bergzand commented May 8, 2018

I want to add the local sock_udp_ep_t endpoint to the arguments as well. Mostly because some CoAP servers use the tuple of addresses and udp ports to correlate requests. Most use cases can just leave it to NULL, but for example when sending a sequence of block2 requests, it can be useful to reuse the local endpoint.

I expect it's also nice to save that memmove() in the response handling if you have other plans. :-)

Yeah, but I don't think I can remove it without changing the current nanocoap_get api.

@kb2ma
Copy link
Member

kb2ma commented May 10, 2018

Koen, I reused your nanocoap_request() function in a nanocoap-based CLI app. See my riot-nano-cli repository. Thanks for making that separation from nanocoap_get()!

Please consider reworking how the request function determines the length of the outgoing PDU. Presently you are using the payload_len attribute of the struct, but it's really not the payload length. If you set the payload attribute in nanocoap_get() you can determine the length with the code below, assuming payload_len is set to the length of the actual payload.

(pkt->payload - (uint8_t *)pkt->hdr) + pkt->payload_len

/**
* @brief Simple synchronous CoAP request
*
* @param[inout] pkt Packet struct containing the request. Is reused for
Copy link
Member

Choose a reason for hiding this comment

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

IIRC use comma: in,out

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack


res = nanocoap_request(&pkt, remote, len);
if (res < 0)
{
Copy link
Member

Choose a reason for hiding this comment

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

coding style

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops :(

return res;
}
else {
res = coap_get_code(&pkt);
Copy link
Member

Choose a reason for hiding this comment

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

IMHO better use coap_get_code_class() and then compare res != COAP_CLASS_SUCCESS

Copy link
Member

Choose a reason for hiding this comment

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

oh, I see its copy paste from before and my suggestion would be an API change ... mhm

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe in a follow up then?

@bergzand
Copy link
Member Author

Koen, I reused your nanocoap_request() function in a nanocoap-based CLI app. See my riot-nano-cli repository. Thanks for making that separation from nanocoap_get()!

Nice!

Please consider reworking how the request function determines the length of the outgoing PDU. Presently you are using the payload_len attribute of the struct, but it's really not the payload length. If you set the payload attribute in nanocoap_get() you can determine the length with the code below, assuming payload_len is set to the length of the actual payload.

Thanks, I wasn't sure whether I was using all the struct members correctly, thanks for clarifying. Could you please verify whether the current code is behaving correctly with respect to the struct members.

@smlng Thanks for the review, I've fixed your issues except for the API change.

@kb2ma kb2ma self-requested a review May 25, 2018 03:53
kb2ma
kb2ma previously approved these changes May 25, 2018
Copy link
Member

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

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

Thanks for the improvement to the packet length calculation. I tested nanocoap_request() and nanocoap_get() in my CLI app, and they work as expected.

Funny what you learn when you test things though. ;-) I posted #9191 on some pre-existing logic errors, including the item @smlng pointed out. These should not hold up this PR though.

Copy link
Member

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

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

I approved too quickly though, will dismiss. Needs squash if @smlng agrees we're ready.

@kb2ma kb2ma dismissed their stale review May 25, 2018 04:43

Need to squash first

@bergzand
Copy link
Member Author

Forgot to change the doxygen issue, is fixed now :(

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

minor nit, please amend and squash directly

/**
* @brief Simple synchronous CoAP request
*
* @param[in,out] pkt Packet struct containing the request. Is reused for
Copy link
Member

Choose a reason for hiding this comment

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

indention slightly of

Copy link
Member Author

Choose a reason for hiding this comment

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

😢

The nanocoap_get function is refactored to split of the request part
into a separate function for reuse by other modules. Support for
retransmissions when the received frame is malformed is dropped as it
was broken anyway.
@bergzand bergzand force-pushed the pr/nanocoap_sock/client_split branch from 8019928 to 6bb8a5c Compare May 25, 2018 07:40
@bergzand
Copy link
Member Author

amended and squashed!

@smlng
Copy link
Member

smlng commented May 25, 2018

@kaspar030 could you please look this over, too? Note the changed behaviour when a mal formed response is received, before this would trigger a retransmit now it returns with the appropriate error.

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 25, 2018
@bergzand bergzand added the Area: CoAP Area: Constrained Application Protocol implementations label May 25, 2018
@bergzand
Copy link
Member Author

@kaspar030 ping!

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

ACK.

@kaspar030 kaspar030 merged commit ddfc584 into RIOT-OS:master Jun 20, 2018
@bergzand
Copy link
Member Author

Thanks!

@bergzand bergzand deleted the pr/nanocoap_sock/client_split branch June 21, 2018 05:58
@cladmi cladmi added this to the Release 2018.07 milestone Jul 10, 2018
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 Area: network Area: Networking 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