Skip to content

Commit

Permalink
client: Generate message ID for all block transfer
Browse files Browse the repository at this point in the history
Generate and set the message ID when handling a Block2 Option in the
response (such as a 2.05 response for GET). When using either Block1 or
Block2 options, a single operation can be split into multiple CoAP
message exchanges. As specified in [RFC7252], each of these message
exchanges uses their own CoAP Message ID.

This commit also generates and sets a message ID in the non-block
transfer path for send_request() API. This is to make the API consistent
with the block transfer path, which always generates and overrides the
message ID.

https://datatracker.ietf.org/doc/html/rfc7959#section-2.3
https://datatracker.ietf.org/doc/html/rfc7252#section-4
  • Loading branch information
jloxfo2 committed Nov 4, 2024
1 parent a5afd77 commit 5eb9580
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ impl<T: ClientTransport + 'static> CoAPClient<T> {
async fn send_request(&self, request: &mut CoapRequest<SocketAddr>) -> IoResult<CoapResponse> {
let request_length = request.message.payload.len();
if request_length <= self.block1_size {
request.message.header.message_id = self.gen_message_id();
return self.send_single_request(request).await;
}
let payload = std::mem::take(&mut request.message.payload);
Expand Down Expand Up @@ -869,6 +870,7 @@ impl<T: ClientTransport + 'static> CoAPClient<T> {
loop {
match Self::intercept_response(request, &mut block2_state) {
Ok(true) => {
request.message.header.message_id = self.gen_message_id();
let resp = self.send_single_request(request).await?;
request.response = Some(resp);
}
Expand Down

0 comments on commit 5eb9580

Please sign in to comment.