Exemple #1
0
// Run starts the simulation on the simulation-side
func (e *Simulation) Run(config *onet.SimulationConfig) error {
	msg := []byte(e.Message)
	size := config.Tree.Size()
	log.Lvl2("Size is:", size, "rounds:", e.Rounds)
	for round := 0; round < e.Rounds; round++ {
		log.Lvl1("Starting round", round, "with message", string(msg))
		round := monitor.NewTimeMeasure("round")

		p, err := config.Overlay.CreateProtocolOnet("NaiveTree", config.Tree)
		if err != nil {
			log.Error("Quitting the simulation....", err)
			return err
		}
		pi := p.(*Protocol)
		pi.Message = msg
		pi.verifySignature = e.Checking

		done := make(chan bool)
		pi.TreeNodeInstance.OnDoneCallback(func() bool {
			done <- true
			return true
		})
		err = pi.Start()
		if err != nil {
			log.Error("Quitting the simulation....", err)
			return err
		}
		<-done
		round.Record()
	}
	return nil
}
Exemple #2
0
// Run initiates a RandHound simulation
func (rhs *RHSimulation) Run(config *onet.SimulationConfig) error {
	randM := monitor.NewTimeMeasure("tgen-randhound")
	bandW := monitor.NewCounterIOMeasure("bw-randhound", config.Conode)
	client, err := config.Overlay.CreateProtocolOnet("RandHound", config.Tree)
	if err != nil {
		return err
	}
	rh, _ := client.(*RandHound)
	err = rh.Setup(rhs.Hosts, rhs.Faulty, rhs.Groups, rhs.Purpose)
	if err != nil {
		return err
	}
	if err := rh.StartProtocol(); err != nil {
		log.Error("Error while starting protcol:", err)
	}

	select {
	case <-rh.Done:
		log.Lvlf1("RandHound - done")
		random, transcript, err := rh.Random()
		if err != nil {
			return err
		}
		randM.Record()
		bandW.Record()
		log.Lvlf1("RandHound - collective randomness: ok")

		verifyM := monitor.NewTimeMeasure("tver-randhound")
		err = rh.Verify(rh.Suite(), random, transcript)
		if err != nil {
			return err
		}
		verifyM.Record()
		log.Lvlf1("RandHound - verification: ok")

		//case <-time.After(time.Second * time.Duration(rhs.Hosts) * 5):
		//log.Print("RandHound - time out")
	}

	return nil

}
Exemple #3
0
// sendAndMeasureViewChange is a method that creates the viewchange request,
// broadcast it and measures the time it takes to accept it.
func (bz *ByzCoin) sendAndMeasureViewchange() {
	log.Lvl3(bz.Name(), "Created viewchange measure")
	bz.vcMeasure = monitor.NewTimeMeasure("viewchange")
	vc := newViewChange()
	var err error
	for _, n := range bz.Tree().List() {
		// don't send to ourself
		if n.ID.Equal(bz.TreeNode().ID) {
			continue
		}
		err = bz.SendTo(n, vc)
		if err != nil {
			log.Error(bz.Name(), "Error sending view change", err)
		}
	}
}
Exemple #4
0
// Run implements onet.Simulation interface
func (e *Simulation) Run(onetConf *onet.SimulationConfig) error {
	log.Lvl2("Naive Tree Simulation starting with: Rounds=", e.Rounds)
	server := NewNtreeServer(e.Blocksize)
	for round := 0; round < e.Rounds; round++ {
		client := byzcoin.NewClient(server)
		err := client.StartClientSimulation(blockchain.GetBlockDir(), e.Blocksize)
		if err != nil {
			log.Error("ClientSimulation:", err)
		}

		log.Lvl1("Starting round", round)
		// create an empty node
		node := onetConf.Overlay.NewTreeNodeInstanceFromProtoName(onetConf.Tree, "ByzCoinNtree")
		// instantiate a byzcoin protocol
		rComplete := monitor.NewTimeMeasure("round")
		pi, err := server.Instantiate(node)
		if err != nil {
			return err
		}
		onetConf.Overlay.RegisterProtocolInstance(pi)

		nt := pi.(*Ntree)
		// Register when the protocol is finished (all the nodes have finished)
		done := make(chan bool)
		nt.RegisterOnDone(func(sig *NtreeSignature) {
			rComplete.Record()
			log.Lvl3("Done")
			done <- true
		})

		go func() {
			if err := nt.Start(); err != nil {
				log.Error("Couldn't start ntree protocol:", err)
			}
		}()
		// wait for the end
		<-done
		log.Lvl3("Round", round, "finished")

	}
	return nil
}
Exemple #5
0
// Run is used on the destination machines and runs a number of
// rounds
func (e *simulation) Run(config *onet.SimulationConfig) error {
	size := config.Tree.Size()
	log.Lvl2("Size is:", size, "rounds:", e.Rounds)
	for round := 0; round < e.Rounds; round++ {
		log.Lvl1("Starting round", round)
		round := monitor.NewTimeMeasure("round")
		p, err := config.Overlay.CreateProtocolOnet("Count", config.Tree)
		if err != nil {
			return err
		}
		go p.Start()
		children := <-p.(*ProtocolCount).Count
		round.Record()
		if children != size {
			return errors.New("Didn't get " + strconv.Itoa(size) +
				" children")
		}
	}
	return nil
}
Exemple #6
0
// Run initiates a JVSS simulation
func (jvs *Simulation) Run(config *onet.SimulationConfig) error {

	size := config.Tree.Size()
	msg := []byte("Test message for JVSS simulation")

	log.Lvl1("Size:", size, "rounds:", jvs.Rounds)

	p, err := config.Overlay.CreateProtocolOnet("JVSS", config.Tree)
	if err != nil {
		return err
	}
	proto := p.(*JVSS)

	log.Lvl1("Starting setup")
	proto.Start()
	log.Lvl1("Setup done")

	for round := 0; round < jvs.Rounds; round++ {
		log.Lvl1("Starting signing round", round)
		r := monitor.NewTimeMeasure("round")
		log.Lvl2("Requesting signature")
		sig, err := proto.Sign(msg)
		if err != nil {
			log.Error("Could not create signature")
			return err
		}
		if jvs.Verify {
			log.Lvl2("Signature received")
			if err := proto.Verify(msg, sig); err != nil {
				log.Error("Signature invalid")
				return err
			}
			log.Lvl2("Signature valid")
		}
		r.Record()
	}

	return nil
}
Exemple #7
0
// Run implements onet.Simulation.
func (cs *Simulation) Run(config *onet.SimulationConfig) error {
	size := len(config.Roster.List)
	msg := []byte("Hello World Cosi Simulation")
	log.Lvl2("Simulation starting with: Size=", size, ", Rounds=", cs.Rounds)
	for round := 0; round < cs.Rounds; round++ {
		log.Lvl1("Starting round", round)
		roundM := monitor.NewTimeMeasure("round")
		// create the node with the protocol, but do NOT start it yet.
		node, err := config.Overlay.CreateProtocolOnet(Name, config.Tree)
		if err != nil {
			return err
		}
		// the protocol itself
		proto := node.(*CoSimul)
		// give the message to sign
		proto.SigningMessage(msg)
		// tell us when it is done
		done := make(chan bool)
		fn := func(sig []byte) {
			roundM.Record()
			publics := proto.Publics()
			if err := cosi.VerifySignature(network.Suite, publics,
				msg, sig); err != nil {
				log.Lvl1("Round", round, " => fail verification")
			} else {
				log.Lvl2("Round", round, " => success")
			}
			done <- true
		}
		proto.RegisterSignatureHook(fn)
		if err := proto.Start(); err != nil {
			log.Error("Couldn't start protocol in round", round)
		}
		<-done
	}
	log.Lvl1("Simulation finished")
	return nil
}
Exemple #8
0
// Run runs the simulation
func (e *Simulation) Run(onetConf *onet.SimulationConfig) error {
	doneChan := make(chan bool)
	doneCB := func() {
		doneChan <- true
	}
	// FIXME use client instead
	dir := blockchain.GetBlockDir()
	parser, err := blockchain.NewParser(dir, magicNum)
	if err != nil {
		log.Error("Error: Couldn't parse blocks in", dir)
		return err
	}
	transactions, err := parser.Parse(0, e.Blocksize)
	if err != nil {
		log.Error("Error while parsing transactions", err)
		return err
	}

	// FIXME c&p from byzcoin.go
	trlist := blockchain.NewTransactionList(transactions, len(transactions))
	header := blockchain.NewHeader(trlist, "", "")
	trblock := blockchain.NewTrBlock(trlist, header)

	// Here we first setup the N^2 connections with a broadcast protocol
	pi, err := onetConf.Overlay.CreateProtocolOnet("Broadcast", onetConf.Tree)
	if err != nil {
		log.Error(err)
	}
	proto := pi.(*manage.Broadcast)
	// channel to notify we are done
	broadDone := make(chan bool)
	proto.RegisterOnDone(func() {
		broadDone <- true
	})

	// ignore error on purpose: Start always returns nil
	_ = proto.Start()

	// wait
	<-broadDone
	log.Lvl3("Simulation can start!")
	for round := 0; round < e.Rounds; round++ {
		log.Lvl1("Starting round", round)
		p, err := onetConf.Overlay.CreateProtocolOnet("ByzCoinPBFT", onetConf.Tree)
		if err != nil {
			return err
		}
		proto := p.(*Protocol)

		proto.trBlock = trblock
		proto.onDoneCB = doneCB

		r := monitor.NewTimeMeasure("round_pbft")
		err = proto.Start()
		if err != nil {
			log.Error("Couldn't start PrePrepare")
			return err
		}

		// wait for finishing pbft:
		<-doneChan
		r.Record()

		log.Lvl2("Finished round", round)
	}
	return nil
}
// Run implements onet.Simulation interface
func (e *Simulation) Run(onetConf *onet.SimulationConfig) error {
	log.Lvl2("Simulation starting with: Rounds=", e.Rounds)
	server := NewByzCoinServer(e.Blocksize, e.TimeoutMs, e.Fail)

	pi, err := onetConf.Overlay.CreateProtocolOnet("Broadcast", onetConf.Tree)
	if err != nil {
		return err
	}
	proto, _ := pi.(*manage.Broadcast)
	// channel to notify we are done
	broadDone := make(chan bool)
	proto.RegisterOnDone(func() {
		broadDone <- true
	})
	// ignore error on purpose: Broadcast.Start() always returns nil
	_ = proto.Start()
	// wait
	<-broadDone

	for round := 0; round < e.Rounds; round++ {
		client := NewClient(server)
		err := client.StartClientSimulation(blockchain.GetBlockDir(), e.Blocksize)
		if err != nil {
			log.Error("Error in ClientSimulation:", err)
			return err
		}

		log.Lvl1("Starting round", round)
		// create an empty node
		tni := onetConf.Overlay.NewTreeNodeInstanceFromProtoName(onetConf.Tree, "ByzCoin")
		if err != nil {
			return err
		}
		// instantiate a byzcoin protocol
		rComplete := monitor.NewTimeMeasure("round")
		pi, err := server.Instantiate(tni)
		if err != nil {
			return err
		}
		onetConf.Overlay.RegisterProtocolInstance(pi)

		bz := pi.(*ByzCoin)
		// Register callback for the generation of the signature !
		bz.RegisterOnSignatureDone(func(sig *BlockSignature) {
			rComplete.Record()
			if err := verifyBlockSignature(tni.Suite(), tni.Roster().Aggregate, sig); err != nil {
				log.Error("Round", round, "failed:", err)
			} else {
				log.Lvl2("Round", round, "success")
			}
		})

		// Register when the protocol is finished (all the nodes have finished)
		done := make(chan bool)
		bz.RegisterOnDone(func() {
			done <- true
		})
		if e.Fail > 0 {
			go func() {
				err := bz.startAnnouncementPrepare()
				if err != nil {
					log.Error("Error while starting "+
						"announcment prepare:", err)
				}
			}()
			// do not run bz.startAnnouncementCommit()
		} else {
			go func() {
				if err := bz.Start(); err != nil {
					log.Error("Couldn't start protocol",
						err)
				}
			}()
		}
		// wait for the end
		<-done
		log.Lvl3("Round", round, "finished")

	}
	return nil
}
Exemple #10
0
func (m *monitorMut) NewMeasure(id string) {
	m.Lock()
	defer m.Unlock()
	m.TimeMeasure = monitor.NewTimeMeasure(id)
}