]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make peerGotPiece a method on connection
authorMatt Joiner <anacrolix@gmail.com>
Mon, 21 Mar 2016 03:19:51 +0000 (14:19 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 21 Mar 2016 03:19:51 +0000 (14:19 +1100)
client.go
connection.go

index 447958e63ca35f7cad6870c32184c6d7d08cc1a2..673f6e5da6b017f4b12bb266e5fc7bbdde8b5b2a 100644 (file)
--- 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:
index 1db26869db248fed427fd9be5be6e992b5700991..fd64700249620526d965b3f023a12e97cd9f4406 100644 (file)
@@ -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) {