func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
	nodes, err := connectNodesInRing(net, nodeCount)
	if err != nil {
		panic("Could not startup node network for mocker")
	}
	for {
		select {
		case <-quit:
			log.Info("Terminating simulation loop")
			return
		default:
		}
		var lowid, highid int
		var wg sync.WaitGroup
		randWait := time.Duration(rand.Intn(5000)+1000) * time.Millisecond
		rand1 := rand.Intn(nodeCount - 1)
		rand2 := rand.Intn(nodeCount - 1)
		if rand1 < rand2 {
			lowid = rand1
			highid = rand2
		} else if rand1 > rand2 {
			highid = rand1
			lowid = rand2
		} else {
			if rand1 == 0 {
				rand2 = 9
			} else if rand1 == 9 {
				rand1 = 0
			}
			lowid = rand1
			highid = rand2
		}
		var steps = highid - lowid
		wg.Add(steps)
		for i := lowid; i < highid; i++ {
			select {
			case <-quit:
				log.Info("Terminating simulation loop")
				return
			case <-time.After(randWait):
			}
			log.Debug(fmt.Sprintf("node %v shutting down", nodes[i]))
			err := net.Stop(nodes[i])
			if err != nil {
				log.Error(fmt.Sprintf("Error stopping node %s", nodes[i]))
				wg.Done()
				continue
			}
			go func(id discover.NodeID) {
				time.Sleep(randWait)
				err := net.Start(id)
				if err != nil {
					log.Error(fmt.Sprintf("Error starting node %s", id))
				}
				wg.Done()
			}(nodes[i])
		}
		wg.Wait()
	}

}
//The probabilistic mocker func has a more probabilistic pattern
//(the implementation could probably be improved):
//nodes are connected in a ring, then a varying number of random nodes is selected,
//mocker then stops and starts them in random intervals, and continues the loop
The probabilistic mocker func has a more probabilistic pattern
(the implementation could probably be improved):
nodes are connected in a ring, then a varying number of random nodes is selected,
mocker then stops and starts them in random intervals, and continues the loop
// The probabilistic mocker func has a more probabilistic pattern // ( the implementation could probably be improved ) : // nodes are connected in a ring then a varying number of random nodes is selected // mocker then stops and starts them in random intervals and continues the loop
func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
	nodes, err := connectNodesInRing(net, nodeCount)
	if err != nil {
		panic("Could not startup node network for mocker")
	}
	for {
		select {
		case <-quit:
			log.Info("Terminating simulation loop")
			return
		default:
		}
		var lowid, highid int
		var wg sync.WaitGroup
		randWait := time.Duration(rand.Intn(5000)+1000) * time.Millisecond
		rand1 := rand.Intn(nodeCount - 1)
		rand2 := rand.Intn(nodeCount - 1)
		if rand1 < rand2 {
			lowid = rand1
			highid = rand2
		} else if rand1 > rand2 {
			highid = rand1
			lowid = rand2
		} else {
			if rand1 == 0 {
				rand2 = 9
			} else if rand1 == 9 {
				rand1 = 0
			}
			lowid = rand1
			highid = rand2
		}
		var steps = highid - lowid
		wg.Add(steps)
		for i := lowid; i < highid; i++ {
			select {
			case <-quit:
				log.Info("Terminating simulation loop")
				return
			case <-time.After(randWait):
			}
			log.Debug(fmt.Sprintf("node %v shutting down", nodes[i]))
			err := net.Stop(nodes[i])
			if err != nil {
				log.Error(fmt.Sprintf("Error stopping node %s", nodes[i]))
				wg.Done()
				continue
			}
			go func(id discover.NodeID) {
				time.Sleep(randWait)
				err := net.Start(id)
				if err != nil {
					log.Error(fmt.Sprintf("Error starting node %s", id))
				}
				wg.Done()
			}(nodes[i])
		}
		wg.Wait()
	}
}
func probabilistic ( net * Network , quit chan struct { } , nodeCount int ) { nodes , err := connectNodesInRing ( net , nodeCount ) if err != nil { panic ( " " ) } for { select { case <- quit : log . Info ( " " ) return default : } var lowid , highid int var wg sync . WaitGroup randWait := time . Duration ( rand . Intn ( 5000 ) + 1000 ) * time . Millisecond rand1 := rand . Intn ( nodeCount - 1 ) rand2 := rand . Intn ( nodeCount - 1 ) if rand1 < rand2 { lowid = rand1 highid = rand2 } else if rand1 > rand2 { highid = rand1 lowid = rand2 } else { if rand1 == 0 { rand2 = 9 } else if rand1 == 9 { rand1 = 0 } lowid = rand1 highid = rand2 } var steps = highid - lowid wg . Add ( steps ) for i := lowid ; i < highid ; i ++ { select { case <- quit : log . Info ( " " ) return case <- time . After ( randWait ) : } log . Debug ( fmt . Sprintf ( " " , nodes [ i ] ) ) err := net . Stop ( nodes [ i ] ) if err != nil { log . Error ( fmt . Sprintf ( " " , nodes [ i ] ) ) wg . Done ( ) continue } go func ( id discover . NodeID ) { time . Sleep ( randWait ) err := net . Start ( id ) if err != nil { log . Error ( fmt . Sprintf ( " " , id ) ) } wg . Done ( ) } ( nodes [ i ] ) } wg . Wait ( ) } }
The probabilistic mocker func has a more probabilistic pattern
(the implementation could probably be improved):
nodes are connected in a ring, then a varying number of random nodes is selected,
mocker then stops and starts them in random intervals, and continues the loop
The probabilistic mocker func has a more probabilistic pattern ( the implementation could probably be improved ) : nodes are connected in a ring then a varying number of random nodes is selected mocker then stops and starts them in random intervals and continues the loop