github.com/aergoio/aergo@v1.3.1/p2p/reconnect.go (about) 1 /** @file 2 * @copyright defined in aergo/LICENSE.txt 3 */ 4 5 package p2p 6 7 import ( 8 "math" 9 "time" 10 ) 11 12 var ( 13 durations []time.Duration 14 maxTrial = 15 15 ) 16 17 func init() { 18 // It will get [20s 36s 1m6s 2m1s 3m40s 6m42s 12m12s 22m14s 40m30s 1h13m48s 2h14m29s 4h5m2s 7h26m29s 13h33m32s 24h42m21s] 19 // 20 sec for dpos 20 durations = generateExpDuration(20, 0.6, maxTrial) 21 // 3 sec for raft 22 //durations = generateExpDuration(3, 0.6, 20) 23 } 24 25 func getNextInterval(trial int) time.Duration { 26 if trial < maxTrial { 27 return durations[trial] 28 } 29 return durations[maxTrial-1] 30 } 31 32 func generateExpDuration(initSecs int, inc float64, count int) []time.Duration { 33 arr := make([]time.Duration, 0, count) 34 num := float64(0) 35 for i := 0; i < count; i++ { 36 x := math.Exp(num) * float64(initSecs) 37 arr = append(arr, time.Second*time.Duration(math.Round(x))) 38 num += inc 39 } 40 return arr 41 }