From 8b4c6a49e2032e8c45a935912273f37e88de959e Mon Sep 17 00:00:00 2001 From: jloxfo2 Date: Mon, 4 Nov 2024 10:24:08 -0800 Subject: [PATCH] client: Generate message ID for all block transfer 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 --- src/client.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client.rs b/src/client.rs index 5ffa9f700..2e4cc6d08 100644 --- a/src/client.rs +++ b/src/client.rs @@ -816,6 +816,9 @@ impl CoAPClient { async fn send_request(&self, request: &mut CoapRequest) -> IoResult { 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); @@ -869,6 +872,7 @@ impl CoAPClient { 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); }