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 548B

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