"unsafe"
"github.com/RoaringBitmap/roaring"
- g "github.com/anacrolix/generics"
- "github.com/anacrolix/generics/heap"
"github.com/anacrolix/log"
"github.com/anacrolix/multiless"
+ g "github.com/anacrolix/generics"
+ "github.com/anacrolix/generics/heap"
+
"github.com/anacrolix/torrent/metainfo"
requestStrategy "github.com/anacrolix/torrent/request-strategy"
typedRoaring "github.com/anacrolix/torrent/typed-roaring"
return
}
+// Update requests if there's a reason assigned.
func (p *Peer) maybeUpdateActualRequestState() {
- if p.closed.IsSet() {
+ if p.needRequestUpdate == "" {
return
}
- if p.needRequestUpdate == "" {
+ p.updateRequestsWithReason(p.needRequestUpdate)
+}
+
+// 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) {
+ if p.closed.IsSet() {
return
}
- if p.needRequestUpdate == peerUpdateRequestsTimerReason {
+ if reason == peerUpdateRequestsTimerReason {
since := time.Since(p.lastRequestUpdate)
if since < updateRequestsTimerDuration {
panic(since)
}
pprof.Do(
context.Background(),
- pprof.Labels("update request", string(p.needRequestUpdate)),
+ pprof.Labels("update request", string(reason)),
func(_ context.Context) {
p.updateRequests()
},
)
+ // Is there any chance we should leave this to run again, and have the caller clear it if they
+ // called with this reason?
p.needRequestUpdate = ""
p.lastRequestUpdate = time.Now()
if enableUpdateRequestsTimer {