Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
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.

timeouts.go 677B

1234567891011121314151617181920212223242526
  1. package relay
  2. import (
  3. "math"
  4. "math/rand"
  5. "time"
  6. )
  7. func getConnectionTimeToLive() time.Duration {
  8. return getTime(ConnectionTimeToLiveMin, ConnectionTimeToLiveMax)
  9. }
  10. func getTimeout() time.Duration {
  11. return getTime(TimeoutMin, TimeoutMax)
  12. }
  13. func getTime(minDuration, maxDuration time.Duration) time.Duration {
  14. minDurationInSeconds := minDuration.Seconds()
  15. maxDurationInSeconds := maxDuration.Seconds()
  16. middle := minDurationInSeconds + (maxDurationInSeconds-minDurationInSeconds)/2 // nolint: gomnd
  17. number := minDurationInSeconds + rand.ExpFloat64()*middle
  18. number = math.Round(math.Min(maxDurationInSeconds, number))
  19. return time.Duration(number) * time.Second
  20. }