mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
swarm/network/simulations: Improve overlay simulation
Signed-off-by: Lewis Marshall <lewis@lmars.net>
This commit is contained in:
parent
5307e1ea77
commit
c2efe3c366
1 changed files with 19 additions and 18 deletions
|
|
@ -112,8 +112,9 @@ func setupMocker(net *simulations.Network) []*adapters.NodeId {
|
||||||
conf := net.Config()
|
conf := net.Config()
|
||||||
conf.DefaultService = "overlay"
|
conf.DefaultService = "overlay"
|
||||||
|
|
||||||
ids := make([]*adapters.NodeId, 10)
|
nodeCount := 30
|
||||||
for i := 0; i < 10; i++ {
|
ids := make([]*adapters.NodeId, nodeCount)
|
||||||
|
for i := 0; i < nodeCount; i++ {
|
||||||
node, err := net.NewNode()
|
node, err := net.NewNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
|
|
@ -189,23 +190,23 @@ func randomMocker(net *simulations.Network) {
|
||||||
func startStopMocker(net *simulations.Network) {
|
func startStopMocker(net *simulations.Network) {
|
||||||
ids := setupMocker(net)
|
ids := setupMocker(net)
|
||||||
|
|
||||||
for i, id := range ids {
|
for range time.Tick(10 * time.Second) {
|
||||||
n := 3000 + i*1000
|
id := ids[rand.Intn(len(ids))]
|
||||||
go func(id *adapters.NodeId) {
|
go func() {
|
||||||
for {
|
log.Error("stopping node", "id", id)
|
||||||
// n := rand.Intn(5000)
|
if err := net.Stop(id); err != nil {
|
||||||
// n := 3000
|
log.Error("error stopping node", "id", id, "err", err)
|
||||||
time.Sleep(time.Duration(n) * time.Millisecond)
|
return
|
||||||
log.Debug(fmt.Sprintf("node %v shutting down", id))
|
|
||||||
net.Stop(id)
|
|
||||||
// n = rand.Intn(5000)
|
|
||||||
n = 2000
|
|
||||||
time.Sleep(time.Duration(n) * time.Millisecond)
|
|
||||||
log.Debug(fmt.Sprintf("node %v starting up", id))
|
|
||||||
net.Start(id)
|
|
||||||
n = 5000
|
|
||||||
}
|
}
|
||||||
}(id)
|
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
log.Error("starting node", "id", id)
|
||||||
|
if err := net.Start(id); err != nil {
|
||||||
|
log.Error("error starting node", "id", id, "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue