Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
more documentation and function argument coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Oct 29, 2019
1 parent 21c82cd commit 91c9842
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type BackoffStrategy interface {
// Jitter implementations taken roughly from https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

// Jitter must return a duration between min and max. Min must be lower than, or equal to, max.
type Jitter func(duration time.Duration, min, max time.Duration, rng *rand.Rand) time.Duration
type Jitter func(duration, min, max time.Duration, rng *rand.Rand) time.Duration

// FullJitter returns a random number uniformly chose from the range [min, boundedDur].
// boundedDur is the duration bounded between min and max.
func FullJitter(duration time.Duration, min, max time.Duration, rng *rand.Rand) time.Duration {
func FullJitter(duration, min, max time.Duration, rng *rand.Rand) time.Duration {
if duration <= min {
return min
}
Expand All @@ -34,7 +34,7 @@ func FullJitter(duration time.Duration, min, max time.Duration, rng *rand.Rand)
}

// NoJitter returns the duration bounded between min and max
func NoJitter(duration time.Duration, min, max time.Duration, rng *rand.Rand) time.Duration {
func NoJitter(duration, min, max time.Duration, rng *rand.Rand) time.Duration {
return boundedDuration(duration, min, max)
}

Expand All @@ -48,7 +48,7 @@ func (b *randomizedBackoff) BoundedDelay(duration time.Duration) time.Duration {
return boundedDuration(duration, b.min, b.max)
}

func boundedDuration(d time.Duration, min, max time.Duration) time.Duration {
func boundedDuration(d, min, max time.Duration) time.Duration {
if d < min {
return min
}
Expand Down
2 changes: 1 addition & 1 deletion backoffcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (d *BackoffDiscovery) FindPeers(ctx context.Context, ns string, opts ...dis
timeExpired := time.Now().After(c.nextDiscover)

// If it's not yet time to search again and no searches are in progress then return cached peers
if !(timeExpired || c.ongoing){
if !(timeExpired || c.ongoing) {
chLen := options.Limit

if chLen == 0 {
Expand Down
4 changes: 3 additions & 1 deletion backoffconnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ type connCacheData struct {
strat BackoffStrategy
}

// Connect attemps to connect to the peers passed in by peerCh. Will not connect to peers if they are within the backoff period.
// Connect attempts to connect to the peers passed in by peerCh. Will not connect to peers if they are within the backoff period.
// As Connect will attempt to dial peers as soon as it learns about them, the caller should try to keep the number,
// and rate, of inbound peers manageable.
func (c *BackoffConnector) Connect(ctx context.Context, peerCh <-chan peer.AddrInfo) {
for {
select {
Expand Down

0 comments on commit 91c9842

Please sign in to comment.