diff --git a/backoff.go b/backoff.go index e31b7a4..ecd9470 100644 --- a/backoff.go +++ b/backoff.go @@ -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 } @@ -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) } @@ -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 } diff --git a/backoffcache.go b/backoffcache.go index 93b3db7..0e255e2 100644 --- a/backoffcache.go +++ b/backoffcache.go @@ -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 { diff --git a/backoffconnector.go b/backoffconnector.go index 8fe3c2d..6f6c58f 100644 --- a/backoffconnector.go +++ b/backoffconnector.go @@ -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 {