From: Matt Joiner Date: Mon, 19 May 2025 04:51:49 +0000 (+1000) Subject: Move a few functions around X-Git-Tag: v1.59.0~134 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8e0cbc9ab2dd00f8d64c57d8e767af868f939786;p=btrtrc.git Move a few functions around --- diff --git a/iter.go b/iter.go index 10cbafc7..350011b1 100644 --- a/iter.go +++ b/iter.go @@ -1 +1,15 @@ package torrent + +import ( + "iter" + + g "github.com/anacrolix/generics" +) + +// Returns Some of the last item in a iter.Seq, or None if the sequence is empty. +func seqLast[V any](seq iter.Seq[V]) (last g.Option[V]) { + for item := range seq { + last.Set(item) + } + return +} diff --git a/peer.go b/peer.go index 113dcb31..c75577e2 100644 --- a/peer.go +++ b/peer.go @@ -387,12 +387,6 @@ var ( maxLocalToRemoteRequests = (writeBufferHighWaterLen - writeBufferLowWaterLen - interestedMsgLen) / requestMsgLen ) -// The actual value to use as the maximum outbound requests. -func (cn *PeerConn) nominalMaxRequests() maxRequests { - // TODO: This should differ for webseeds... - return max(1, min(cn.PeerMaxRequests, cn.peakRequests*2, maxLocalToRemoteRequests)) -} - func (cn *Peer) totalExpectingTime() (ret time.Duration) { ret = cn.cumulativeExpectedToReceiveChunks if !cn.lastStartedExpectingToReceiveChunks.IsZero() { diff --git a/peerconn.go b/peerconn.go index 420af5be..40450dcb 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1452,3 +1452,8 @@ func hashRequestFromMessage(m pp.Message) hashRequest { func (me *PeerConn) peerPtr() *Peer { return &me.Peer } + +// The actual value to use as the maximum outbound requests. +func (cn *PeerConn) nominalMaxRequests() maxRequests { + return max(1, min(cn.PeerMaxRequests, cn.peakRequests*2, maxLocalToRemoteRequests)) +} diff --git a/webseed-peer.go b/webseed-peer.go index 95fc2157..fed0e8bd 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -176,14 +176,6 @@ func (ws *webseedPeer) spawnRequests() { } } -// Returns Some of the last item in a iter.Seq, or None if the sequence is empty. -func seqLast[V any](seq iter.Seq[V]) (last g.Option[V]) { - for item := range seq { - last.Set(item) - } - return -} - func (ws *webseedPeer) iterConsecutiveRequests(begin RequestIndex) iter.Seq[RequestIndex] { return func(yield func(RequestIndex) bool) { for {