mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-06 01:51:20 +00:00
random dialing
This commit is contained in:
parent
5971617ac3
commit
ae171ba134
@ -95,6 +95,10 @@ func RandUint64Exp() uint64 {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandFloat32() float32 {
|
||||||
|
return rand.Float32()
|
||||||
|
}
|
||||||
|
|
||||||
func RandTime() time.Time {
|
func RandTime() time.Time {
|
||||||
return time.Unix(int64(RandUint64Exp()), 0)
|
return time.Unix(int64(RandUint64Exp()), 0)
|
||||||
}
|
}
|
||||||
|
14
node/node.go
14
node/node.go
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
@ -152,6 +153,7 @@ func (n *Node) AddListener(l p2p.Listener) {
|
|||||||
n.book.AddOurAddress(l.ExternalAddress())
|
n.book.AddOurAddress(l.ExternalAddress())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: Blocking
|
||||||
func (n *Node) DialSeed() {
|
func (n *Node) DialSeed() {
|
||||||
// if the single seed node is available, use only it
|
// if the single seed node is available, use only it
|
||||||
prioritySeed := config.App().GetString("SeedNode")
|
prioritySeed := config.App().GetString("SeedNode")
|
||||||
@ -161,14 +163,16 @@ func (n *Node) DialSeed() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// permute the list, dial half of them
|
// permute the list, dial them in random order.
|
||||||
seeds := config.App().GetStringSlice("SeedNodes")
|
seeds := config.App().GetStringSlice("SeedNodes")
|
||||||
perm := rand.Perm(len(seeds))
|
perm := rand.Perm(len(seeds))
|
||||||
// TODO: we shouldn't necessarily connect to all of them every time ...
|
|
||||||
for i := 0; i < len(perm); i++ {
|
for i := 0; i < len(perm); i++ {
|
||||||
j := perm[i]
|
go func(i int) {
|
||||||
addr := p2p.NewNetAddressString(seeds[j])
|
time.Sleep(time.Duration(rand.Int63n(3000)) * time.Millisecond)
|
||||||
n.dialSeed(addr)
|
j := perm[i]
|
||||||
|
addr := p2p.NewNetAddressString(seeds[j])
|
||||||
|
n.dialSeed(addr)
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -130,6 +131,9 @@ func (pexR *PEXReactor) SendAddrs(peer *Peer, addrs []*NetAddress) {
|
|||||||
|
|
||||||
// Ensures that sufficient peers are connected. (continuous)
|
// Ensures that sufficient peers are connected. (continuous)
|
||||||
func (pexR *PEXReactor) ensurePeersRoutine() {
|
func (pexR *PEXReactor) ensurePeersRoutine() {
|
||||||
|
// Randomize when routine starts
|
||||||
|
time.Sleep(time.Duration(rand.Int63n(500*ensurePeersPeriodSeconds)) * time.Millisecond)
|
||||||
|
|
||||||
// fire once immediately.
|
// fire once immediately.
|
||||||
pexR.ensurePeers()
|
pexR.ensurePeers()
|
||||||
// fire periodically
|
// fire periodically
|
||||||
|
Loading…
x
Reference in New Issue
Block a user