mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 17:04:02 +03:00
FILE / ScuroNeko/mtg
mtglib/internal/relay/timeouts.go
Исходный файл и его история в репозитории.
23 lines
548 B
Go
23 lines
548 B
Go
package relay
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
func getConnectionTimeToLive() time.Duration {
|
|
return getTime(ConnectionTimeToLiveMin, ConnectionTimeToLiveMax)
|
|
}
|
|
|
|
func getTimeout() time.Duration {
|
|
return getTime(TimeoutMin, TimeoutMax)
|
|
}
|
|
|
|
func getTime(minDuration, maxDuration time.Duration) time.Duration {
|
|
minDurationInSeconds := int(minDuration.Seconds())
|
|
maxDurationInSeconds := int(maxDuration.Seconds())
|
|
number := minDurationInSeconds + rand.Intn(maxDurationInSeconds-minDurationInSeconds)
|
|
|
|
return time.Duration(number) * time.Second
|
|
}
|