From: Matt Joiner Date: Mon, 4 Jan 2016 11:34:24 +0000 (+1100) Subject: Switch to int from peer_protocol.Integer for piece index in a lot of places X-Git-Tag: v1.0.0~951 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8346ff81f722241b0f78ee8c4184cadeacfa6264;p=btrtrc.git Switch to int from peer_protocol.Integer for piece index in a lot of places --- diff --git a/client.go b/client.go index ba2f03ce..0f7daccb 100644 --- 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. diff --git a/torrent.go b/torrent.go index 26335e18..b2478656 100644 --- a/torrent.go +++ b/torrent.go @@ -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()