]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Switch to int from peer_protocol.Integer for piece index in a lot of places
authorMatt Joiner <anacrolix@gmail.com>
Mon, 4 Jan 2016 11:34:24 +0000 (22:34 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 4 Jan 2016 11:34:24 +0000 (22:34 +1100)
client.go
torrent.go

index ba2f03cec7e7abb1c43dace4e288b74da89eea9f..0f7daccb88cfef241adf6eb58c30c5f3c23e933a 100644 (file)
--- a/client.go
+++ b/client.go
@@ -109,14 +109,14 @@ const (
 )
 
 // 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
@@ -126,7 +126,7 @@ func (cl *Client) queueFirstHash(t *torrent, piece int) {
        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
@@ -2601,7 +2601,7 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er
        // 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 {
@@ -2631,7 +2631,7 @@ func (me *Client) reapPieceTouches(t *torrent, piece int) (ret []*connection) {
        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
@@ -2704,20 +2704,20 @@ func (me *Client) pieceChanged(t *torrent, piece int) {
        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:
@@ -2725,7 +2725,7 @@ func (cl *Client) verifyPiece(t *torrent, index pp.Integer) {
        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.
index 26335e18a51718df6de0c06b35f2f82f5ded3a3c..b2478656cc72d5fe7f4cf4d19dc662dc5956bf6b 100644 (file)
@@ -659,7 +659,7 @@ func (t *torrent) pieceLength(piece int) (len_ pp.Integer) {
        return
 }
 
-func (t *torrent) hashPiece(piece pp.Integer) (ps pieceSum) {
+func (t *torrent) hashPiece(piece int) (ps pieceSum) {
        hash := pieceHash.New()
        p := &t.Pieces[piece]
        p.pendingWritesMutex.Lock()