Add Torrent.pieceIndexOfRequestIndex
This commit is contained in:
parent
9b9a37eee6
commit
78c36e4c2f
|
@ -578,7 +578,7 @@ type messageWriter func(pp.Message) bool
|
|||
// This function seems to only used by Peer.request. It's all logic checks, so maybe we can no-op it
|
||||
// when we want to go fast.
|
||||
func (cn *Peer) shouldRequest(r RequestIndex) error {
|
||||
pi := pieceIndex(r / cn.t.chunksPerRegularPiece())
|
||||
pi := cn.t.pieceIndexOfRequestIndex(r)
|
||||
if cn.requestState.Cancelled.Contains(r) {
|
||||
return errors.New("request is cancelled and waiting acknowledgement")
|
||||
}
|
||||
|
|
10
torrent.go
10
torrent.go
|
@ -1257,7 +1257,7 @@ func (t *Torrent) piecePriority(piece pieceIndex) piecePriority {
|
|||
}
|
||||
|
||||
func (t *Torrent) pendRequest(req RequestIndex) {
|
||||
t.piece(int(req / t.chunksPerRegularPiece())).pendChunkIndex(req % t.chunksPerRegularPiece())
|
||||
t.piece(t.pieceIndexOfRequestIndex(req)).pendChunkIndex(req % t.chunksPerRegularPiece())
|
||||
}
|
||||
|
||||
func (t *Torrent) pieceCompletionChanged(piece pieceIndex, reason string) {
|
||||
|
@ -2437,10 +2437,10 @@ func (t *Torrent) peerIsActive(p *Peer) (active bool) {
|
|||
}
|
||||
|
||||
func (t *Torrent) requestIndexToRequest(ri RequestIndex) Request {
|
||||
index := ri / t.chunksPerRegularPiece()
|
||||
index := t.pieceIndexOfRequestIndex(ri)
|
||||
return Request{
|
||||
pp.Integer(index),
|
||||
t.piece(int(index)).chunkIndexSpec(ri % t.chunksPerRegularPiece()),
|
||||
t.piece(index).chunkIndexSpec(ri % t.chunksPerRegularPiece()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2494,3 +2494,7 @@ func (t *Torrent) hasStorageCap() bool {
|
|||
_, ok := (*f)()
|
||||
return ok
|
||||
}
|
||||
|
||||
func (t *Torrent) pieceIndexOfRequestIndex(ri RequestIndex) pieceIndex {
|
||||
return pieceIndex(ri / t.chunksPerRegularPiece())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue