]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Move a few functions around
authorMatt Joiner <anacrolix@gmail.com>
Mon, 19 May 2025 04:51:49 +0000 (14:51 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 19 May 2025 04:51:49 +0000 (14:51 +1000)
iter.go
peer.go
peerconn.go
webseed-peer.go

diff --git a/iter.go b/iter.go
index 10cbafc73d7b9237c864a6f3c625bf9c74366b21..350011b1b59f6fd697815c507376e453be4457dc 100644 (file)
--- 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 113dcb31178235f547f34a709e83efca334c4306..c75577e2bb5d07bf0e93438e46d60684b8c7ae37 100644 (file)
--- 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() {
index 420af5be5b0e96abf41338828ab8c0251b0ca3aa..40450dcb87e26007dc71b66df6bed97d08b57ff7 100644 (file)
@@ -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))
+}
index 95fc2157620fd534df4d2896278e29b09e62f3db..fed0e8bd2ffafac0b91241d03105eee6c782229b 100644 (file)
@@ -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 {