github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/verification/requester/qualifier.go (about)

     1  package requester
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // RequestQualifierFunc is a function type that on receiving the number of attempts a chunk has been requested with,
     8  // the last time it has been requested, and the duration at which the chunk can be retried after, returns either true or false.
     9  //
    10  // The return value of this function determines whether the chunk request can be dispatched to the network.
    11  type RequestQualifierFunc func(attempts uint64, lastRequested time.Time, retryAfter time.Duration) bool
    12  
    13  // MaxAttemptQualifier only qualifies a chunk request if it has been requested less than the specified number of attempts.
    14  func MaxAttemptQualifier(maxAttempts uint64) RequestQualifierFunc {
    15  	return func(attempts uint64, _ time.Time, _ time.Duration) bool {
    16  		return attempts < maxAttempts
    17  	}
    18  }
    19  
    20  // RetryAfterQualifier only qualifies a chunk request if its retryAfter duration has been elapsed since the last time this
    21  // request has been dispatched.
    22  func RetryAfterQualifier(_ uint64, lastAttempt time.Time, retryAfter time.Duration) bool {
    23  	nextTry := lastAttempt.Add(retryAfter)
    24  	return nextTry.Before(time.Now())
    25  }