From 172513311159f888ff59c4b3f6c5ff46611b6b8d Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 25 Oct 2016 14:58:17 +1100 Subject: [PATCH] Move the implementation of connection.requestPiecePendingChunks out of Torrent --- connection.go | 12 ++++++++++-- torrent.go | 12 ------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/connection.go b/connection.go index a61d42a4..afd9d3a4 100644 --- a/connection.go +++ b/connection.go @@ -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) { diff --git a/torrent.go b/torrent.go index e458dbbd..280850bb 100644 --- a/torrent.go +++ b/torrent.go @@ -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)