]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Remove unused request stuff for webseed peers
authorMatt Joiner <anacrolix@gmail.com>
Wed, 2 Jul 2025 05:10:20 +0000 (15:10 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 2 Jul 2025 05:12:59 +0000 (15:12 +1000)
client.go
peer-impl.go
peer.go
peerconn.go
requesting.go
torrent.go
webseed-peer.go

index 18919d9e5987f33f28389e2dfad15bfd717e50b8..a02c27d8dc1b2de1425985fde513c0166c62110d 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1927,12 +1927,3 @@ func (cl *Client) underWebSeedHttpRequestLimit(key webseedHostKeyHandle) bool {
        panicif.Zero(key)
        return cl.numWebSeedRequests[key] < defaultRequestsPerWebseedHost
 }
-
-func (cl *Client) countWebSeedHttpRequests() (num int) {
-       for t := range cl.torrents {
-               for _, p := range t.webSeeds {
-                       num += p.numRequests()
-               }
-       }
-       return
-}
index 98d3aa7cd24b0d144cdc8afe5f25d45d84fb756d..f1130c0e4e7c927bda458bf041c9f5e873c98b5b 100644 (file)
@@ -12,24 +12,20 @@ import (
 // with legacy PeerConn methods. New methods and calls that are fixed up should be migrated over to
 // newHotPeerImpl.
 type legacyPeerImpl interface {
-       // Trigger the actual request state to get updated
-       handleOnNeedUpdateRequests()
-       // Actually go ahead and modify the pending requests.
-       updateRequests()
+       // Notify that the peers requests should be updated for the provided reason.
+       onNeedUpdateRequests(reason updateRequestReason)
 
        // handleCancel initiates cancellation of a request
-       handleCancel(RequestIndex)
-       // The final piece to actually commit to a request. Typically, this sends or begins handling the
-       // request.
-       _request(Request) bool
+       handleCancel(ri RequestIndex)
        connectionFlags() string
        onClose()
-       onGotInfo(*metainfo.Info)
+       onGotInfo(info *metainfo.Info)
        // Drop connection. This may be a no-op if there is no connection.
        drop()
        // Rebuke the peer
        ban()
        String() string
+       // Per peer-impl lines for WriteStatus.
        peerImplStatusLines() []string
 
        // All if the peer should have everything, known if we know that for a fact. For example, we can
@@ -43,6 +39,9 @@ type legacyPeerImpl interface {
 // Abstract methods implemented by subclasses of Peer.
 type newHotPeerImpl interface {
        lastWriteUploadRate() float64
+       // Bookkeeping for a chunk being received and any specific checks.
        checkReceivedChunk(ri RequestIndex) error
+       // Whether we're expecting to receive chunks because we have outstanding requests. Used for
+       // example to calculate download rate.
        expectingChunks() bool
 }
diff --git a/peer.go b/peer.go
index 93116246afa3b34792cb2d951bd1904bafe373cc..b0fc2da8f2adb41a6b84b923a13658959e91d111 100644 (file)
--- a/peer.go
+++ b/peer.go
@@ -475,7 +475,7 @@ func (cn *PeerConn) request(r RequestIndex) (more bool, err error) {
        for _, f := range cn.callbacks.SentRequest {
                f(PeerRequestEvent{cn.peerPtr(), ppReq})
        }
-       return cn.legacyPeerImpl._request(ppReq), nil
+       return cn._request(ppReq), nil
 }
 
 func (me *Peer) cancel(r RequestIndex) {
@@ -490,7 +490,7 @@ func (me *Peer) cancel(r RequestIndex) {
 }
 
 // Sets a reason to update requests, and if there wasn't already one, handle it.
-func (cn *Peer) onNeedUpdateRequests(reason updateRequestReason) {
+func (cn *PeerConn) onNeedUpdateRequests(reason updateRequestReason) {
        if cn.needRequestUpdate != "" {
                return
        }
index 4386b22f2fef6d1dbc00dc4c71409f6cffb5af4b..8bac4f1f155072743e34ad9516a53344651e6f84 100644 (file)
@@ -335,6 +335,8 @@ func (pc *PeerConn) writeInterested(interested bool) bool {
        })
 }
 
+// The final piece to actually commit to a request. Typically, this sends or begins handling the
+// request.
 func (me *PeerConn) _request(r Request) bool {
        return me.write(pp.Message{
                Type:   pp.Request,
index f226e05aef5be93d6e791c50eb0f12326a4c17dc..5fc4a4fddda9fe3e7033cd6235a07bf0ba55c9da 100644 (file)
@@ -246,7 +246,7 @@ func (p *Peer) getDesiredRequestState() (desired desiredRequestState) {
 }
 
 // Update requests if there's a reason assigned.
-func (p *Peer) maybeUpdateActualRequestState() {
+func (p *PeerConn) maybeUpdateActualRequestState() {
        if p.needRequestUpdate == "" {
                return
        }
@@ -255,7 +255,7 @@ func (p *Peer) maybeUpdateActualRequestState() {
 
 // Updates requests right now with the given reason. Clobbers any deferred reason if there was one.
 // Does all the necessary checks and includes profiler tags to assign the overhead.
-func (p *Peer) updateRequestsWithReason(reason updateRequestReason) {
+func (p *PeerConn) updateRequestsWithReason(reason updateRequestReason) {
        if p.closed.IsSet() {
                return
        }
index 21b00514a1eaa91142abef3648e45ad386844379..ae90090a765d5f620d5c90d18febbb449bb859f7 100644 (file)
@@ -1471,9 +1471,6 @@ func (t *Torrent) updatePeerRequestsForPiece(piece pieceIndex, reason updateRequ
                return
        }
        t.iterPeers(func(c *Peer) {
-               // if c.requestState.Interested {
-               //      return
-               // }
                if !c.isLowOnRequests() {
                        return
                }
index c2543c5b8fcf6bb30cdec00abe11e7e7972da888..7bcc240c74a9cc6cee0f75309804f337f6ff50c8 100644 (file)
@@ -29,6 +29,9 @@ type webseedPeer struct {
        hostKey          webseedHostKeyHandle
 }
 
+// Webseed requests are issued globally so per-connection reasons or handling make no sense.
+func (me *webseedPeer) onNeedUpdateRequests(updateRequestReason) {}
+
 func (me *webseedPeer) expectingChunks() bool {
        return len(me.activeRequests) > 0
 }
@@ -42,18 +45,6 @@ func (me *webseedPeer) numRequests() int {
        return len(me.activeRequests)
 }
 
-func (me *webseedPeer) shouldUpdateRequests() bool {
-       return me.moreRequestsAllowed()
-}
-
-func (me *webseedPeer) moreRequestsAllowed() bool {
-       return me.numRequests() < me.client.MaxRequests && me.peer.t.cl.underWebSeedHttpRequestLimit(me.hostKey)
-}
-
-func (me *webseedPeer) updateRequests() {
-       return
-}
-
 func (me *webseedPeer) lastWriteUploadRate() float64 {
        // We never upload to webseeds.
        return 0
@@ -108,10 +99,6 @@ func (ws *webseedPeer) intoSpec(begin, end RequestIndex) webseed.RequestSpec {
        return webseed.RequestSpec{start, endOff - start}
 }
 
-func (ws *webseedPeer) _request(r Request) bool {
-       return true
-}
-
 func (ws *webseedPeer) spawnRequest(begin, end RequestIndex) {
        extWsReq := ws.client.StartNewRequest(ws.intoSpec(begin, end))
        wsReq := webseedRequest{
@@ -173,19 +160,6 @@ func (ws *webseedPeer) deleteActiveRequest(wr *webseedRequest) {
        ws.peer.updateExpectingChunks()
 }
 
-func (ws *webseedPeer) spawnRequests() {
-       next, stop := iter.Pull(ws.inactiveRequests())
-       defer stop()
-       for ws.moreRequestsAllowed() {
-               req, ok := next()
-               if !ok {
-                       break
-               }
-               end := seqLast(ws.iterConsecutiveInactiveRequests(req)).Unwrap()
-               ws.spawnRequest(req, end+1)
-       }
-}
-
 func (ws *webseedPeer) iterConsecutiveRequests(begin RequestIndex) iter.Seq[RequestIndex] {
        return func(yield func(RequestIndex) bool) {
                for {
@@ -249,10 +223,6 @@ func (cn *webseedPeer) ban() {
        cn.peer.close()
 }
 
-func (ws *webseedPeer) handleOnNeedUpdateRequests() {
-       ws.peer.maybeUpdateActualRequestState()
-}
-
 func (ws *webseedPeer) onClose() {
        // Just deleting them means we would have to manually cancel active requests.
        ws.peer.cancelAllRequests()