]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Misc tidy
authorMatt Joiner <anacrolix@gmail.com>
Thu, 15 May 2025 04:55:32 +0000 (14:55 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 15 May 2025 04:55:32 +0000 (14:55 +1000)
misc.go
peer.go
requesting.go
torrent.go
types/types.go
webseed-request.go [new file with mode: 0644]

diff --git a/misc.go b/misc.go
index b657d104288b4fbc6fcda64508bc0ef5ce00270e..12a454de1deccf7593f67556d47a897be352207f 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -15,6 +15,7 @@ import (
 )
 
 type (
+       // TODO: Make this private. Use types.Request in the (one?) place it's exposed here.
        Request       = types.Request
        ChunkSpec     = types.ChunkSpec
        PiecePriority = types.PiecePriority
@@ -104,7 +105,7 @@ func validateInfo(info *metainfo.Info) error {
 }
 
 func chunkIndexSpec(index, pieceLength, chunkSize pp.Integer) ChunkSpec {
-       ret := ChunkSpec{pp.Integer(index) * chunkSize, chunkSize}
+       ret := ChunkSpec{index * chunkSize, chunkSize}
        if ret.Begin+ret.Length > pieceLength {
                ret.Length = pieceLength - ret.Begin
        }
diff --git a/peer.go b/peer.go
index 649634b255da328a0fbd5e9c53a25a256cd3a50b..69681e920b022932d81c79079a983d626361ece9 100644 (file)
--- a/peer.go
+++ b/peer.go
@@ -388,7 +388,8 @@ var (
 
 // The actual value to use as the maximum outbound requests.
 func (cn *Peer) nominalMaxRequests() maxRequests {
-       return maxInt(1, minInt(cn.PeerMaxRequests, cn.peakRequests*2, maxLocalToRemoteRequests))
+       // TODO: This should differ for webseeds...
+       return max(1, min(cn.PeerMaxRequests, cn.peakRequests*2, maxLocalToRemoteRequests))
 }
 
 func (cn *Peer) totalExpectingTime() (ret time.Duration) {
@@ -592,6 +593,7 @@ func (c *Peer) remoteRejectedRequest(r RequestIndex) bool {
        if c.deleteRequest(r) {
                c.decPeakRequests()
        } else if !c.requestState.Cancelled.CheckedRemove(r) {
+               // The request was already cancelled.
                return false
        }
        if c.isLowOnRequests() {
@@ -616,7 +618,8 @@ func (c *Peer) doChunkReadStats(size int64) {
        c.allStats(func(cs *ConnStats) { cs.receivedChunk(size) })
 }
 
-// Handle a received chunk from a peer.
+// Handle a received chunk from a peer. TODO: Break this out into non-wire protocol specific
+// handling. Avoid shoehorning into a pp.Message.
 func (c *Peer) receiveChunk(msg *pp.Message) error {
        ChunksReceived.Add("total", 1)
 
@@ -795,6 +798,7 @@ func (c *Peer) deleteRequest(r RequestIndex) bool {
                f(PeerRequestEvent{c, c.t.requestIndexToRequest(r)})
        }
        c.updateExpectingChunks()
+       // TODO: Can't this happen if a request is stolen?
        if c.t.requestingPeer(r) != c {
                panic("only one peer should have a given request at a time")
        }
index cf69f08b55beceff5543830289df294ddadc10b0..958e11b887c5e8685591c29e4a03b6eb42487537 100644 (file)
@@ -75,7 +75,7 @@ func (p *peerId) GobDecode(b []byte) error {
 
 type (
        // A request index is a chunk indexed across the entire torrent. It's a single integer and can
-       // be converted to a protocol request.
+       // be converted to a protocol request. TODO: This should be private.
        RequestIndex   = requestStrategy.RequestIndex
        chunkIndexType = requestStrategy.ChunkIndex
 )
index bc6a597701833ffd59eaf542f7b912fc7ad349e8..b59202a8abc9663b831e579d38caa35381729f9a 100644 (file)
@@ -3010,6 +3010,7 @@ func (t *Torrent) peerIsActive(p *Peer) (active bool) {
        return
 }
 
+// TODO: It's more of a RequestStruct really.
 func (t *Torrent) requestIndexToRequest(ri RequestIndex) Request {
        index := t.pieceIndexOfRequestIndex(ri)
        return Request{
index 977f1f551a42f1cb52cd0a6eb622dfeff8b4c56a..d87844a4057bd1c5241d698e683db2440f17679b 100644 (file)
@@ -10,6 +10,7 @@ import (
 
 type PieceIndex = int
 
+// TODO: Where is the doc/spec calling it this?
 type ChunkSpec struct {
        Begin, Length pp.Integer
 }
diff --git a/webseed-request.go b/webseed-request.go
new file mode 100644 (file)
index 0000000..10cbafc
--- /dev/null
@@ -0,0 +1 @@
+package torrent