connection.go | 12 ++++++++++-- torrent.go | 12 ------------ diff --git a/connection.go b/connection.go index a61d42a444d7b67b49fbf4872680324843aafb11..afd9d3a456e051417dc4ac3491e5005baffb2382 100644 --- a/connection.go +++ b/connection.go @@ -18,6 +18,7 @@ "time" "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 @@ return cn.requestPiecePendingChunks(piece) }) } -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) { diff --git a/torrent.go b/torrent.go index e458dbbd49ce254a8bcae66f0cf7a869e6585dfa..280850bb1cf508d857296ae50eef2221c18660e6 100644 --- a/torrent.go +++ b/torrent.go @@ -17,7 +17,6 @@ "time" "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" @@ -964,17 +963,6 @@ func (t *Torrent) unpendPieceRange(begin, end int) { var bm bitmap.Bitmap bm.AddRange(begin, end) 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) {