You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/05/09 00:40:45 UTC
[mynewt-newtmgr] branch master updated: image: Multiple rounds of
chunklen reduction
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git
The following commit(s) were added to refs/heads/master by this push:
new c953418 image: Multiple rounds of chunklen reduction
new fdbcd95 Merge pull request #122 from ccollins476ad/request-too-big
c953418 is described below
commit c953418041768cf957a61e3131903f27641b4804
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed May 8 17:32:23 2019 -0700
image: Multiple rounds of chunklen reduction
Prior to this commit, newtmgr determined how many bytes of image data to
include in an upload request as follows:
1. Choose a large number to start (512).
2. Encode the upload request into CoAP (+ optional security).
3. Compare the size of request to the transport's MTU. If the request is
too large, subtract the difference from the chunk length.
This commit changes the above procedure such that it runs in a loop.
After reducing the chunk length, a new request is encoded and its length
is compared to the MTU. The loop executes until the encoded request
fits within the MTU.
---
nmxact/xact/image.go | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/nmxact/xact/image.go b/nmxact/xact/image.go
index 534856e..bb09442 100644
--- a/nmxact/xact/image.go
+++ b/nmxact/xact/image.go
@@ -90,17 +90,14 @@ func min(a, b int) int {
return b
}
-func findChunkLen(s sesn.Sesn, hash []byte, upgrade bool, data []byte,
- off int) (int, error) {
+func encodeUploadReq(s sesn.Sesn, hash []byte, upgrade bool, data []byte,
+ off int, chunklen int) ([]byte, error) {
- // Let's start by encoding max allowed chunk len and we will see how many
- // bytes we need to cut
- chunklen := min(len(data)-off, IMAGE_UPLOAD_MAX_CHUNK)
r := buildImageUploadReq(len(data), hash, upgrade, data[off:off+chunklen],
off)
enc, err := mgmt.EncodeMgmt(s, r.Msg())
if err != nil {
- return 0, err
+ return nil, err
}
// If encoded length is larger than MTU, we need to make chunk shorter
@@ -109,6 +106,32 @@ func findChunkLen(s sesn.Sesn, hash []byte, upgrade bool, data []byte,
chunklen -= overflow
}
+ return enc, nil
+}
+
+func findChunkLen(s sesn.Sesn, hash []byte, upgrade bool, data []byte,
+ off int) (int, error) {
+
+ // Let's start by encoding max allowed chunk len and we will see how many
+ // bytes we need to cut
+ chunklen := min(len(data)-off, IMAGE_UPLOAD_MAX_CHUNK)
+
+ // Keep reducing the chunk size until the request fits the MTU.
+ for {
+ enc, err := encodeUploadReq(s, hash, upgrade, data, off, chunklen)
+ if err != nil {
+ return 0, err
+ }
+
+ if len(enc) <= s.MtuOut() {
+ break
+ }
+
+ // Encoded length is larger than MTU, we need to make chunk shorter
+ overflow := len(enc) - s.MtuOut()
+ chunklen -= overflow
+ }
+
return chunklen, nil
}