Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
558B

  1. package icecast
  2. import "time"
  3. type ReconnectConfig struct {
  4. Enabled bool
  5. InitialBackoffMs int
  6. MaxBackoffMs int
  7. }
  8. func (c ReconnectConfig) nextBackoff(attempt int) time.Duration {
  9. if !c.Enabled {
  10. return 0
  11. }
  12. initial := c.InitialBackoffMs
  13. if initial <= 0 {
  14. initial = 1000
  15. }
  16. max := c.MaxBackoffMs
  17. if max <= 0 {
  18. max = 15000
  19. }
  20. d := time.Duration(initial) * time.Millisecond
  21. for i := 1; i < attempt; i++ {
  22. d *= 2
  23. if d >= time.Duration(max)*time.Millisecond {
  24. return time.Duration(max) * time.Millisecond
  25. }
  26. }
  27. return d
  28. }