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
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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. }