]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Tidy
authorMatt Joiner <anacrolix@gmail.com>
Thu, 31 Jul 2025 01:50:52 +0000 (11:50 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 31 Jul 2025 01:50:52 +0000 (11:50 +1000)
internal/request-strategy/order.go
torrent.go

index d3ede920ddf6a155a49202253dc1901c73341aa0..387b4db7cfb1bccce0f86fe629c6db956d682c18 100644 (file)
@@ -68,8 +68,8 @@ func GetRequestablePieces(
        )
        pro.tree.Scan(func(item PieceRequestOrderItem) bool {
                ih := item.Key.InfoHash
-               var t = input.Torrent(ih)
-               var piece = t.Piece(item.Key.Index)
+               t := input.Torrent(ih)
+               piece := t.Piece(item.Key.Index)
                pieceLength := t.PieceLength()
                // Storage limits will always apply against requestable pieces, since we need to keep the
                // highest priority pieces, even if they're complete or in an undesirable state.
index 3960d7d43f5439919c15937652ac0fb62669f5e8..e684360b71cc39a7f7af2f1061fc245584313704 100644 (file)
@@ -2406,20 +2406,14 @@ func (t *Torrent) newConnsAllowed() bool {
        if t.closed.IsSet() {
                return false
        }
-       if !t.needData() && (!t.seeding() || !t.haveAnyPieces()) {
-               return false
+       if t.needData() {
+               return true
        }
-       return true
+       return t.seeding() && t.haveAnyPieces()
 }
 
 func (t *Torrent) wantAnyConns() bool {
-       if !t.networkingEnabled.Bool() {
-               return false
-       }
-       if t.closed.IsSet() {
-               return false
-       }
-       if !t.needData() && (!t.seeding() || !t.haveAnyPieces()) {
+       if !t.newConnsAllowed() {
                return false
        }
        return len(t.conns) < t.maxEstablishedConns
@@ -2430,6 +2424,7 @@ func (t *Torrent) wantOutgoingConns() bool {
                return false
        }
        if len(t.conns) < t.maxEstablishedConns {
+               // Shortcut: We can take any connection direction right now.
                return true
        }
        numIncomingConns := len(t.conns) - t.numOutgoingConns()
@@ -2444,6 +2439,7 @@ func (t *Torrent) wantIncomingConns() bool {
                return false
        }
        if len(t.conns) < t.maxEstablishedConns {
+               // Shortcut: We can take any connection direction right now.
                return true
        }
        numIncomingConns := len(t.conns) - t.numOutgoingConns()