]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Remove peer piece inclination and piece request order
authorMatt Joiner <anacrolix@gmail.com>
Fri, 8 Oct 2021 01:41:25 +0000 (12:41 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 19 Oct 2021 03:08:13 +0000 (14:08 +1100)
These are vestigial data structures used with old request strategy implementations.

peerconn.go
requesting.go
torrent.go

index dc172e6d336841faa38448716402d2be471aa07b..c1c02a8289237347ff58e53ea1044d90c0302799 100644 (file)
@@ -17,7 +17,6 @@ import (
        "github.com/anacrolix/log"
        "github.com/anacrolix/missinggo/iter"
        "github.com/anacrolix/missinggo/v2/bitmap"
-       "github.com/anacrolix/missinggo/v2/prioritybitmap"
        "github.com/anacrolix/multiless"
 
        "github.com/anacrolix/chansync"
@@ -127,9 +126,6 @@ type Peer struct {
        PeerExtensionIDs map[pp.ExtensionName]pp.ExtensionNumber
        PeerClientName   string
 
-       pieceInclination   []int
-       _pieceRequestOrder prioritybitmap.PriorityBitmap
-
        logger log.Logger
 }
 
@@ -404,8 +400,6 @@ func (p *Peer) close() {
        if !p.closed.Set() {
                return
        }
-       p.discardPieceInclination()
-       p._pieceRequestOrder.Clear()
        p.peerImpl.onClose()
        if p.t != nil {
                p.t.decPeerPieceAvailability(p)
@@ -662,7 +656,6 @@ func (cn *PeerConn) postBitfield() {
 
 func (cn *PeerConn) updateRequests() {
        if peerRequesting {
-               cn.nextRequestState = cn.getDesiredRequestState()
                cn.tickleWriter()
                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() {
-       if cn.t.haveInfo() {
-               prioritiesChanged := false
-               for i := pieceIndex(0); i < cn.t.numPieces(); i++ {
-                       if cn.updatePiecePriority(i) {
-                               prioritiesChanged = true
-                       }
-               }
-               if prioritiesChanged {
-                       cn.updateRequests()
-               }
-       }
+       cn.updateRequests()
        cn.t.maybeDropMutuallyCompletePeer(cn)
 }
 
@@ -761,10 +708,7 @@ func (cn *PeerConn) peerSentHave(piece pieceIndex) error {
                cn.t.incPieceAvailability(piece)
        }
        cn._peerPieces.Add(uint32(piece))
-       cn.t.maybeDropMutuallyCompletePeer(&cn.Peer)
-       if cn.updatePiecePriority(piece) {
-               cn.updateRequests()
-       }
+       cn.peerPiecesChanged()
        return nil
 }
 
@@ -1470,7 +1414,10 @@ func (cn *Peer) netGoodPiecesDirtied() int64 {
 }
 
 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 {
index 4513ea3dfbbc904d6917aca3dd957bd26f3d6b19..c6dd6415de1a91b235e34faf1c20cfaa72333ef7 100644 (file)
@@ -262,7 +262,7 @@ func (p *Peer) getDesiredRequestState() (desired requestState) {
 }
 
 func (p *Peer) applyNextRequestState() bool {
-       next := p.nextRequestState
+       next := p.getDesiredRequestState()
        current := p.actualRequestState
        if !p.setInterested(next.Interested) {
                return false
index 32b1d720d3a1ab266619c1d5bb83ac7894f83911..b99e4d18afe080522ee98bd7629cf755a9239934 100644 (file)
@@ -923,7 +923,8 @@ func (t *Torrent) havePiece(index pieceIndex) bool {
 }
 
 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,
 ) {
        if !t.cl.config.DropMutuallyCompletePeers {
@@ -1096,13 +1097,11 @@ func (t *Torrent) maybeNewConns() {
 }
 
 func (t *Torrent) piecePriorityChanged(piece pieceIndex) {
-       // t.logger.Printf("piece %d priority changed", piece)
-       t.iterPeers(func(c *Peer) {
-               if c.updatePiecePriority(piece) {
-                       // log.Print("conn piece priority changed")
+       if true || t._pendingPieces.Contains(piece) {
+               t.iterPeers(func(c *Peer) {
                        c.updateRequests()
-               }
-       })
+               })
+       }
        t.maybeNewConns()
        t.publishPieceChange(piece)
 }