]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Move the implementation of connection.requestPiecePendingChunks out of Torrent
authorMatt Joiner <anacrolix@gmail.com>
Tue, 25 Oct 2016 03:58:17 +0000 (14:58 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 25 Oct 2016 03:58:17 +0000 (14:58 +1100)
connection.go
torrent.go

index a61d42a444d7b67b49fbf4872680324843aafb11..afd9d3a456e051417dc4ac3491e5005baffb2382 100644 (file)
@@ -18,6 +18,7 @@ import (
 
        "github.com/anacrolix/missinggo"
        "github.com/anacrolix/missinggo/bitmap"
+       "github.com/anacrolix/missinggo/itertools"
        "github.com/anacrolix/missinggo/prioritybitmap"
        "github.com/bradfitz/iter"
 
@@ -504,8 +505,15 @@ func (cn *connection) fillRequests() {
        })
 }
 
-func (cn *connection) requestPiecePendingChunks(piece int) (again bool) {
-       return cn.t.connRequestPiecePendingChunks(cn, piece)
+func (c *connection) requestPiecePendingChunks(piece int) (again bool) {
+       if !c.PeerHasPiece(piece) {
+               return true
+       }
+       chunkIndices := c.t.pieces[piece].undirtiedChunkIndices().ToSortedSlice()
+       return itertools.ForPerm(len(chunkIndices), func(i int) bool {
+               req := request{pp.Integer(piece), c.t.chunkIndexSpec(chunkIndices[i], piece)}
+               return c.Request(req)
+       })
 }
 
 func (cn *connection) stopRequestingPiece(piece int) {
index e458dbbd49ce254a8bcae66f0cf7a869e6585dfa..280850bb1cf508d857296ae50eef2221c18660e6 100644 (file)
@@ -17,7 +17,6 @@ import (
 
        "github.com/anacrolix/missinggo"
        "github.com/anacrolix/missinggo/bitmap"
-       "github.com/anacrolix/missinggo/itertools"
        "github.com/anacrolix/missinggo/perf"
        "github.com/anacrolix/missinggo/pubsub"
        "github.com/anacrolix/missinggo/slices"
@@ -966,17 +965,6 @@ func (t *Torrent) unpendPieceRange(begin, end int) {
        t.unpendPieces(&bm)
 }
 
-func (t *Torrent) connRequestPiecePendingChunks(c *connection, piece int) (more bool) {
-       if !c.PeerHasPiece(piece) {
-               return true
-       }
-       chunkIndices := t.pieces[piece].undirtiedChunkIndices().ToSortedSlice()
-       return itertools.ForPerm(len(chunkIndices), func(i int) bool {
-               req := request{pp.Integer(piece), t.chunkIndexSpec(chunkIndices[i], piece)}
-               return c.Request(req)
-       })
-}
-
 func (t *Torrent) pendRequest(req request) {
        ci := chunkIndex(req.chunkSpec, t.chunkSize)
        t.pieces[req.Index].pendChunkIndex(ci)