)
// Currently doesn't really queue, but should in the future.
-func (cl *Client) queuePieceCheck(t *torrent, pieceIndex pp.Integer) {
+func (cl *Client) queuePieceCheck(t *torrent, pieceIndex int) {
piece := &t.Pieces[pieceIndex]
if piece.QueuedForHash {
return
}
piece.QueuedForHash = true
t.publishPieceChange(int(pieceIndex))
- go cl.verifyPiece(t, pieceIndex)
+ go cl.verifyPiece(t, int(pieceIndex))
}
// Queue a piece check if one isn't already queued, and the piece has never
if p.EverHashed || p.Hashing || p.QueuedForHash || t.pieceComplete(piece) {
return
}
- cl.queuePieceCheck(t, pp.Integer(piece))
+ cl.queuePieceCheck(t, piece)
}
// Clients contain zero or more Torrents. A client manages a blocklist, the
// It's important that the piece is potentially queued before we check if
// the piece is still wanted, because if it is queued, it won't be wanted.
if piece.numPendingChunks() == 0 {
- me.queuePieceCheck(t, req.Index)
+ me.queuePieceCheck(t, int(req.Index))
}
if !t.wantPiece(int(req.Index)) {
for _, c := range t.Conns {
return
}
-func (me *Client) pieceHashed(t *torrent, piece pp.Integer, correct bool) {
+func (me *Client) pieceHashed(t *torrent, piece int, correct bool) {
p := &t.Pieces[piece]
if p.EverHashed {
// Don't score the first time a piece is hashed, it could be an
me.event.Broadcast()
}
-func (cl *Client) verifyPiece(t *torrent, index pp.Integer) {
+func (cl *Client) verifyPiece(t *torrent, piece int) {
cl.mu.Lock()
defer cl.mu.Unlock()
- p := &t.Pieces[index]
+ p := &t.Pieces[piece]
for p.Hashing || t.data == nil {
cl.event.Wait()
}
p.QueuedForHash = false
- if t.isClosed() || t.pieceComplete(int(index)) {
+ if t.isClosed() || t.pieceComplete(piece) {
return
}
p.Hashing = true
cl.mu.Unlock()
- sum := t.hashPiece(index)
+ sum := t.hashPiece(piece)
cl.mu.Lock()
select {
case <-t.closing:
default:
}
p.Hashing = false
- cl.pieceHashed(t, index, sum == p.Hash)
+ cl.pieceHashed(t, piece, sum == p.Hash)
}
// Returns handles to all the torrents loaded in the Client.