]> Sergey Matveev's repositories - btrtrc.git/commitdiff
requesting: Filter peers that can't be allocated chunks
authorMatt Joiner <anacrolix@gmail.com>
Thu, 16 Sep 2021 00:47:27 +0000 (10:47 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 16 Sep 2021 00:47:27 +0000 (10:47 +1000)
request-strategy/order.go

index c0814df66355b1509865320591b14bfd2c15fb1a..9b81a94858fcfed2c7b6133f83ce8a1807e4ea6d 100644 (file)
@@ -297,6 +297,13 @@ func (me *peersForPieceSorter) Less(_i, _j int) bool {
 func allocatePendingChunks(p requestablePiece, peers []*requestsPeer) {
        peersForPiece := makePeersForPiece(len(peers))
        for _, peer := range peers {
+               if !peer.canRequestPiece(p.index) {
+                       continue
+               }
+               if !peer.canFitRequest() {
+                       peer.requestablePiecesRemaining--
+                       continue
+               }
                peersForPiece = append(peersForPiece, &peersForPieceRequests{
                        requestsInPiece: 0,
                        requestsPeer:    peer,
@@ -317,7 +324,7 @@ func allocatePendingChunks(p requestablePiece, peers []*requestsPeer) {
        sortPeersForPiece := func(req *Request) {
                peersForPieceSorter.req = req
                sort.Sort(&peersForPieceSorter)
-               //ensureValidSortedPeersForPieceRequests(peersForPieceSorter)
+               //ensureValidSortedPeersForPieceRequests(&peersForPieceSorter)
        }
        // Chunks can be preassigned several times, if peers haven't been able to update their "actual"
        // with "next" request state before another request strategy run occurs.