next returns the delay before the next dial and sets giveUp once attempts exceed relayMaxRetries. Adapts the math from retry.Retrier.Wait (github.com/coder/retry/retrier.go) without blocking: the library's Wait returns 0 on the first call and sets Delay to Floor only after the sleep, so we clamp to
()
| 651 | // Delay to Floor only after the sleep, so we clamp to Floor up |
| 652 | // front. |
| 653 | func (s *relayRetryState) next() (delay time.Duration, giveUp bool) { |
| 654 | s.attempts++ |
| 655 | if s.attempts > relayMaxRetries { |
| 656 | return 0, true |
| 657 | } |
| 658 | r := s.retrier |
| 659 | d := time.Duration(float64(r.Delay) * r.Rate) |
| 660 | if d > r.Ceil { |
| 661 | d = r.Ceil |
| 662 | } |
| 663 | if d < r.Floor { |
| 664 | d = r.Floor |
| 665 | } |
| 666 | r.Delay = d |
| 667 | return d, false |
| 668 | } |
| 669 | |
| 670 | // reset returns the state to the floor delay and zero attempts. |
| 671 | // Called after a successful dial or a relay target change. |
no test coverage detected