From: Matt Joiner Date: Wed, 3 Dec 2014 00:43:05 +0000 (-0600) Subject: Harmless shortcut initing peer pieces when we have the torrent info X-Git-Tag: v1.0.0~1429 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=98400ab9c7f41194f763e41c7e1bbb1fb5099614;p=btrtrc.git Harmless shortcut initing peer pieces when we have the torrent info --- diff --git a/client.go b/client.go index cddb442f..7b3a8967 100644 --- 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) {