]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Reorder actions after a chunk is received
authorMatt Joiner <anacrolix@gmail.com>
Wed, 28 May 2014 16:44:27 +0000 (02:44 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 28 May 2014 16:44:27 +0000 (02:44 +1000)
client.go

index e86a93a96df412566210be74e4eecd7675ba51d8..fc4d48ff84bab1cbec02448f94b9a286516209a7 100644 (file)
--- a/client.go
+++ b/client.go
@@ -856,13 +856,6 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er
        }
        me.dataReady(dataSpec{t.InfoHash, req})
 
-       // Cancel pending requests for this chunk.
-       for _, c := range t.Conns {
-               if me.connCancel(t, c, req) {
-                       me.replenishConnRequests(t, c)
-               }
-       }
-
        // Record that we have the chunk.
        delete(t.Pieces[req.Index].PendingChunkSpecs, req.chunkSpec)
        if len(t.Pieces[req.Index].PendingChunkSpecs) == 0 {
@@ -878,6 +871,14 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er
                }
        }
 
+       // Cancel pending requests for this chunk.
+       for _, c := range t.Conns {
+               if me.connCancel(t, c, req) {
+                       log.Print("cancelled concurrent request for %s", req)
+                       me.replenishConnRequests(t, c)
+               }
+       }
+
        return nil
 }