Move the implementation of connection.requestPiecePendingChunks out of Torrent

This commit is contained in:
Matt Joiner 2016-10-25 14:58:17 +11:00
parent 559afcd0a9
commit 1725133111
2 changed files with 10 additions and 14 deletions

View 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) {

View 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)