Move peerGotPiece
This commit is contained in:
parent
125c864a8c
commit
1508e02935
20
client.go
20
client.go
|
@ -1147,26 +1147,6 @@ func (me *Client) sendInitialMessages(conn *connection, torrent *torrent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) error {
|
|
||||||
if !c.peerHasAll {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if piece >= len(c.PeerPieces) {
|
|
||||||
return errors.New("peer got out of range piece index")
|
|
||||||
}
|
|
||||||
c.PeerPieces[piece] = true
|
|
||||||
}
|
|
||||||
c.updatePiecePriority(piece)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (me *Client) peerUnchoked(torrent *torrent, conn *connection) {
|
func (me *Client) peerUnchoked(torrent *torrent, conn *connection) {
|
||||||
conn.updateRequests()
|
conn.updateRequests()
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,3 +625,23 @@ func (c *connection) discardPieceInclination() {
|
||||||
c.t.putPieceInclination(c.pieceInclination)
|
c.t.putPieceInclination(c.pieceInclination)
|
||||||
c.pieceInclination = nil
|
c.pieceInclination = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) error {
|
||||||
|
if !c.peerHasAll {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if piece >= len(c.PeerPieces) {
|
||||||
|
return errors.New("peer got out of range piece index")
|
||||||
|
}
|
||||||
|
c.PeerPieces[piece] = true
|
||||||
|
}
|
||||||
|
c.updatePiecePriority(piece)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue