nkaje commented on a change in pull request #162:
URL: https://github.com/apache/mynewt-newtmgr/pull/162#discussion_r433177056



##########
File path: nmxact/xact/image.go
##########
@@ -185,33 +209,189 @@ func nextImageUploadReq(s sesn.Sesn, upgrade bool, data 
[]byte, off int, imageNu
        return r, nil
 }
 
+func (t *ImageUploadIntTracker) UpdateTracker(off int, status int) {
+       if status == IMAGE_UPLOAD_STATUS_MISSED {
+               /* Upon error, set the value to missed for retransmission */
+               t.RspMap[off] = IMAGE_UPLOAD_CHUNK_MISSED_WM
+       } else if status == IMAGE_UPLOAD_STATUS_EXPECTED {
+               /* When the chunk at a certain offset is transmitted,
+                  a response requesting the next offset is expected. This
+                  indicates that the chunk is successfully trasmitted. Wait
+                  on the chunk in response e.g when offset 0, len 100 is sent,
+                  expected offset in the ack is 100 etc. */
+               t.RspMap[off] = 1
+       } else if status == IMAGE_UPLOAD_STATUS_RQ {
+               /* If the chunk at this offset was already transmitted, value
+                  goes to zero and that KV pair gets cleaned up subsequently.
+                  If there is a repeated request for a certain offset,
+                  that offset is not received by the remote side. Decrement
+                  the value. Missed chunk processing routine retransmits it */
+               t.RspMap[off] -= 1
+       }
+}
+
+func (t *ImageUploadIntTracker) CheckWindow() bool {
+       t.Mutex.Lock()
+       defer t.Mutex.Unlock()
+
+       return t.CheckWindowUL()
+}
+
+// Unlocked version, when the mutex is already held
+func (t *ImageUploadIntTracker) CheckWindowUL() bool {
+       return t.WCount < t.WCap
+}
+
+func (t *ImageUploadIntTracker) ProcessMissedChunks() {
+       for o, c := range t.RspMap {
+               if c < -(IMAGE_UPLOAD_MAX_WS * 2) {
+                       delete(t.RspMap, o)
+                       t.Off = o
+                       log.Debugf("missed? off %d count %d", o, c)
+               }
+               // clean up done chunks
+               if c == 0 {
+                       delete(t.RspMap, o)
+               }
+       }
+}
+
+func (t *ImageUploadIntTracker) HandleResponse(c *ImageUploadCmd, off int, rsp 
nmp.NmpRsp, res *ImageUploadResult) bool {
+       var cmp int64
+       cmp = 1
+       wFull := false
+
+       irsp := rsp.(*nmp.ImageUploadRsp)
+       res.Rsps = append(res.Rsps, irsp)
+       t.UpdateTracker(int(irsp.Off), IMAGE_UPLOAD_STATUS_RQ)
+
+       if t.WCap == t.WCount {
+               wFull = true
+       }
+       if t.MaxRxOff < int64(irsp.Off) {
+               t.MaxRxOff = int64(irsp.Off)
+       }
+       if c.ProgressCb != nil {
+               c.ProgressCb(c, irsp)
+       }
+       if t.TuneWS && t.WCap < IMAGE_UPLOAD_MAX_WS {
+               atomic.AddInt64(&t.WCap, 1)

Review comment:
       Changed `HandleResponse()` and `HandleError()` as per comment.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to