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 updates the send_request() API to conditionally
generate and set a message ID in the non-block transfer path. The intent
is to make the API consistent with the block transfer path, which always
generates and overrides the message ID, but preserve the previous
behavior of allowing callers to provide their own non-zero message IDs
(e.g. allow an observer to manage its own 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 8b4c6a4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,9 @@ 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 {
if 0 == request.message.header.message_id {
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 +872,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 8b4c6a4

Please sign in to comment.