From: Matt Joiner Date: Wed, 2 Jul 2025 05:10:20 +0000 (+1000) Subject: Remove unused request stuff for webseed peers X-Git-Tag: v1.59.0~51 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8acdd80e5833e0d0e3a6a97f54808f849499ea0e;p=btrtrc.git Remove unused request stuff for webseed peers --- diff --git a/client.go b/client.go index 18919d9e..a02c27d8 100644 --- 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 -} diff --git a/peer-impl.go b/peer-impl.go index 98d3aa7c..f1130c0e 100644 --- a/peer-impl.go +++ b/peer-impl.go @@ -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 93116246..b0fc2da8 100644 --- 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 } diff --git a/peerconn.go b/peerconn.go index 4386b22f..8bac4f1f 100644 --- a/peerconn.go +++ b/peerconn.go @@ -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, diff --git a/requesting.go b/requesting.go index f226e05a..5fc4a4fd 100644 --- a/requesting.go +++ b/requesting.go @@ -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 } diff --git a/torrent.go b/torrent.go index 21b00514..ae90090a 100644 --- a/torrent.go +++ b/torrent.go @@ -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 } diff --git a/webseed-peer.go b/webseed-peer.go index c2543c5b..7bcc240c 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -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()