]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Harmless shortcut initing peer pieces when we have the torrent info
authorMatt Joiner <anacrolix@gmail.com>
Wed, 3 Dec 2014 00:43:05 +0000 (18:43 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 3 Dec 2014 00:43:05 +0000 (18:43 -0600)
client.go

index cddb442f305b0303a627bc6723be6f363e695879..7b3a8967513fddae41f0894bb7769e5347fe4e9e 100644 (file)
--- a/client.go
+++ b/client.go
@@ -920,8 +920,14 @@ func (t *torrent) initRequestOrdering(c *connection) {
 }
 
 func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) {
-       for piece >= len(c.PeerPieces) {
-               c.PeerPieces = append(c.PeerPieces, false)
+       if t.haveInfo() {
+               if c.PeerPieces == nil {
+                       c.PeerPieces = make([]bool, t.NumPieces())
+               }
+       } else {
+               for piece >= len(c.PeerPieces) {
+                       c.PeerPieces = append(c.PeerPieces, false)
+               }
        }
        c.PeerPieces[piece] = true
        if t.wantPiece(piece) {