)
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
}
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
}
// 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) {
if c.deleteRequest(r) {
c.decPeakRequests()
} else if !c.requestState.Cancelled.CheckedRemove(r) {
+ // The request was already cancelled.
return false
}
if c.isLowOnRequests() {
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)
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")
}
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
)