Use intermediate t in Peer.getDesiredRequestState

This commit is contained in:
Matt Joiner 2022-05-11 14:14:25 +10:00
parent 9eb80abc29
commit 4eb6a49f27
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
1 changed files with 7 additions and 6 deletions

View File

@ -184,22 +184,23 @@ type desiredRequestState struct {
} }
func (p *Peer) getDesiredRequestState() (desired desiredRequestState) { func (p *Peer) getDesiredRequestState() (desired desiredRequestState) {
if !p.t.haveInfo() { t := p.t
if !t.haveInfo() {
return return
} }
if p.t.closed.IsSet() { if t.closed.IsSet() {
return return
} }
input := p.t.getRequestStrategyInput() input := t.getRequestStrategyInput()
requestHeap := desiredPeerRequests{ requestHeap := desiredPeerRequests{
peer: p, peer: p,
pieceStates: make(map[pieceIndex]request_strategy.PieceRequestOrderState), pieceStates: make(map[pieceIndex]request_strategy.PieceRequestOrderState),
} }
request_strategy.GetRequestablePieces( request_strategy.GetRequestablePieces(
input, input,
p.t.getPieceRequestOrder(), t.getPieceRequestOrder(),
func(ih InfoHash, pieceIndex int, pieceExtra request_strategy.PieceRequestOrderState) { func(ih InfoHash, pieceIndex int, pieceExtra request_strategy.PieceRequestOrderState) {
if ih != p.t.infoHash { if ih != t.infoHash {
return return
} }
if !p.peerHasPiece(pieceIndex) { if !p.peerHasPiece(pieceIndex) {
@ -231,7 +232,7 @@ func (p *Peer) getDesiredRequestState() (desired desiredRequestState) {
}) })
}, },
) )
p.t.assertPendingRequests() t.assertPendingRequests()
desired.Requests = requestHeap desired.Requests = requestHeap
return return
} }