From: Matt Joiner Date: Mon, 21 Mar 2016 03:19:51 +0000 (+1100) Subject: Make peerGotPiece a method on connection X-Git-Tag: v1.0.0~827 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=99fa0c26aa30370c1c2f28ad370adbccb7ed70da;p=btrtrc.git Make peerGotPiece a method on connection --- diff --git a/client.go b/client.go index 447958e6..673f6e5d 100644 --- a/client.go +++ b/client.go @@ -1277,7 +1277,7 @@ func (cl *Client) peerHasAll(t *torrent, cn *connection) { cn.PeerPieces = nil if t.haveInfo() { for i := 0; i < t.numPieces(); i++ { - cl.peerGotPiece(t, cn, i) + cn.peerGotPiece(i) } } } @@ -1385,7 +1385,7 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error { c.PeerInterested = false c.Choke() case pp.Have: - me.peerGotPiece(t, c, int(msg.Index)) + c.peerGotPiece(int(msg.Index)) case pp.Request: if c.Choked { break @@ -1427,7 +1427,7 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error { c.PeerPieces = msg.Bitfield for index, has := range c.PeerPieces { if has { - me.peerGotPiece(t, c, index) + c.peerGotPiece(index) } } case pp.HaveAll: diff --git a/connection.go b/connection.go index 1db26869..fd647002 100644 --- a/connection.go +++ b/connection.go @@ -626,11 +626,11 @@ func (c *connection) discardPieceInclination() { c.pieceInclination = nil } -func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) error { +func (c *connection) peerGotPiece(piece int) error { if !c.peerHasAll { - if t.haveInfo() { + if c.t.haveInfo() { if c.PeerPieces == nil { - c.PeerPieces = make([]bool, t.numPieces()) + c.PeerPieces = make([]bool, c.t.numPieces()) } } else { for piece >= len(c.PeerPieces) {