Remove peer piece inclination and piece request order
These are vestigial data structures used with old request strategy implementations.
This commit is contained in:
parent
0f53cbf07e
commit
30b99e7102
65
peerconn.go
65
peerconn.go
|
@ -17,7 +17,6 @@ import (
|
||||||
"github.com/anacrolix/log"
|
"github.com/anacrolix/log"
|
||||||
"github.com/anacrolix/missinggo/iter"
|
"github.com/anacrolix/missinggo/iter"
|
||||||
"github.com/anacrolix/missinggo/v2/bitmap"
|
"github.com/anacrolix/missinggo/v2/bitmap"
|
||||||
"github.com/anacrolix/missinggo/v2/prioritybitmap"
|
|
||||||
"github.com/anacrolix/multiless"
|
"github.com/anacrolix/multiless"
|
||||||
|
|
||||||
"github.com/anacrolix/chansync"
|
"github.com/anacrolix/chansync"
|
||||||
|
@ -127,9 +126,6 @@ type Peer struct {
|
||||||
PeerExtensionIDs map[pp.ExtensionName]pp.ExtensionNumber
|
PeerExtensionIDs map[pp.ExtensionName]pp.ExtensionNumber
|
||||||
PeerClientName string
|
PeerClientName string
|
||||||
|
|
||||||
pieceInclination []int
|
|
||||||
_pieceRequestOrder prioritybitmap.PriorityBitmap
|
|
||||||
|
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,8 +400,6 @@ func (p *Peer) close() {
|
||||||
if !p.closed.Set() {
|
if !p.closed.Set() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.discardPieceInclination()
|
|
||||||
p._pieceRequestOrder.Clear()
|
|
||||||
p.peerImpl.onClose()
|
p.peerImpl.onClose()
|
||||||
if p.t != nil {
|
if p.t != nil {
|
||||||
p.t.decPeerPieceAvailability(p)
|
p.t.decPeerPieceAvailability(p)
|
||||||
|
@ -662,7 +656,6 @@ func (cn *PeerConn) postBitfield() {
|
||||||
|
|
||||||
func (cn *PeerConn) updateRequests() {
|
func (cn *PeerConn) updateRequests() {
|
||||||
if peerRequesting {
|
if peerRequesting {
|
||||||
cn.nextRequestState = cn.getDesiredRequestState()
|
|
||||||
cn.tickleWriter()
|
cn.tickleWriter()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -692,54 +685,8 @@ func iterBitmapsDistinct(skip *bitmap.Bitmap, bms ...bitmap.Bitmap) iter.Func {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check callers updaterequests
|
|
||||||
func (cn *Peer) stopRequestingPiece(piece pieceIndex) bool {
|
|
||||||
return cn._pieceRequestOrder.Remove(piece)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is distinct from Torrent piece priority, which is the user's
|
|
||||||
// preference. Connection piece priority is specific to a connection and is
|
|
||||||
// used to pseudorandomly avoid connections always requesting the same pieces
|
|
||||||
// and thus wasting effort.
|
|
||||||
func (cn *Peer) updatePiecePriority(piece pieceIndex) bool {
|
|
||||||
tpp := cn.t.piecePriority(piece)
|
|
||||||
if !cn.peerHasPiece(piece) {
|
|
||||||
tpp = PiecePriorityNone
|
|
||||||
}
|
|
||||||
if tpp == PiecePriorityNone {
|
|
||||||
return cn.stopRequestingPiece(piece)
|
|
||||||
}
|
|
||||||
prio := cn.getPieceInclination()[piece]
|
|
||||||
return cn._pieceRequestOrder.Set(piece, prio)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cn *Peer) getPieceInclination() []int {
|
|
||||||
if cn.pieceInclination == nil {
|
|
||||||
cn.pieceInclination = cn.t.getConnPieceInclination()
|
|
||||||
}
|
|
||||||
return cn.pieceInclination
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cn *Peer) discardPieceInclination() {
|
|
||||||
if cn.pieceInclination == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cn.t.putPieceInclination(cn.pieceInclination)
|
|
||||||
cn.pieceInclination = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cn *Peer) peerPiecesChanged() {
|
func (cn *Peer) peerPiecesChanged() {
|
||||||
if cn.t.haveInfo() {
|
cn.updateRequests()
|
||||||
prioritiesChanged := false
|
|
||||||
for i := pieceIndex(0); i < cn.t.numPieces(); i++ {
|
|
||||||
if cn.updatePiecePriority(i) {
|
|
||||||
prioritiesChanged = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if prioritiesChanged {
|
|
||||||
cn.updateRequests()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cn.t.maybeDropMutuallyCompletePeer(cn)
|
cn.t.maybeDropMutuallyCompletePeer(cn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,10 +708,7 @@ func (cn *PeerConn) peerSentHave(piece pieceIndex) error {
|
||||||
cn.t.incPieceAvailability(piece)
|
cn.t.incPieceAvailability(piece)
|
||||||
}
|
}
|
||||||
cn._peerPieces.Add(uint32(piece))
|
cn._peerPieces.Add(uint32(piece))
|
||||||
cn.t.maybeDropMutuallyCompletePeer(&cn.Peer)
|
cn.peerPiecesChanged()
|
||||||
if cn.updatePiecePriority(piece) {
|
|
||||||
cn.updateRequests()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1470,7 +1414,10 @@ func (cn *Peer) netGoodPiecesDirtied() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Peer) peerHasWantedPieces() bool {
|
func (c *Peer) peerHasWantedPieces() bool {
|
||||||
return !c._pieceRequestOrder.IsEmpty()
|
// TODO: Can this be done just with AndCardinality?
|
||||||
|
missingPeerHas := c.newPeerPieces()
|
||||||
|
missingPeerHas.AndNot(&c.t._completedPieces)
|
||||||
|
return !missingPeerHas.IsEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Peer) deleteRequest(r RequestIndex) bool {
|
func (c *Peer) deleteRequest(r RequestIndex) bool {
|
||||||
|
|
|
@ -262,7 +262,7 @@ func (p *Peer) getDesiredRequestState() (desired requestState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) applyNextRequestState() bool {
|
func (p *Peer) applyNextRequestState() bool {
|
||||||
next := p.nextRequestState
|
next := p.getDesiredRequestState()
|
||||||
current := p.actualRequestState
|
current := p.actualRequestState
|
||||||
if !p.setInterested(next.Interested) {
|
if !p.setInterested(next.Interested) {
|
||||||
return false
|
return false
|
||||||
|
|
13
torrent.go
13
torrent.go
|
@ -923,7 +923,8 @@ func (t *Torrent) havePiece(index pieceIndex) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) maybeDropMutuallyCompletePeer(
|
func (t *Torrent) maybeDropMutuallyCompletePeer(
|
||||||
// I'm not sure about taking peer here, not all peer implementations actually drop. Maybe that's okay?
|
// I'm not sure about taking peer here, not all peer implementations actually drop. Maybe that's
|
||||||
|
// okay?
|
||||||
p *Peer,
|
p *Peer,
|
||||||
) {
|
) {
|
||||||
if !t.cl.config.DropMutuallyCompletePeers {
|
if !t.cl.config.DropMutuallyCompletePeers {
|
||||||
|
@ -1096,13 +1097,11 @@ func (t *Torrent) maybeNewConns() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) piecePriorityChanged(piece pieceIndex) {
|
func (t *Torrent) piecePriorityChanged(piece pieceIndex) {
|
||||||
// t.logger.Printf("piece %d priority changed", piece)
|
if true || t._pendingPieces.Contains(piece) {
|
||||||
t.iterPeers(func(c *Peer) {
|
t.iterPeers(func(c *Peer) {
|
||||||
if c.updatePiecePriority(piece) {
|
|
||||||
// log.Print("conn piece priority changed")
|
|
||||||
c.updateRequests()
|
c.updateRequests()
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
t.maybeNewConns()
|
t.maybeNewConns()
|
||||||
t.publishPieceChange(piece)
|
t.publishPieceChange(piece)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue