示例#1
0
func TestRandHound(t *testing.T) {

	var name = "RandHound"
	var nodes int = 28
	var faulty int = 2
	var groups int = 4
	var purpose string = "RandHound test run"

	local := onet.NewLocalTest()
	_, _, tree := local.GenTree(int(nodes), true)
	defer local.CloseAll()

	// Setup and start RandHound

	log.Lvlf1("RandHound - starting")
	protocol, err := local.CreateProtocol(name, tree)
	if err != nil {
		t.Fatal("Couldn't initialise RandHound protocol:", err)
	}
	rh := protocol.(*randhound.RandHound)
	err = rh.Setup(nodes, faulty, groups, purpose)
	if err != nil {
		t.Fatal("Couldn't initialise RandHound protocol:", err)
	}
	if err := protocol.Start(); err != nil {
		t.Fatal(err)
	}

	select {
	case <-rh.Done:
		log.Lvlf1("RandHound - done")

		random, transcript, err := rh.Random()
		if err != nil {
			t.Fatal(err)
		}
		log.Lvlf1("RandHound - collective randomness: ok")

		//log.Lvlf1("RandHound - collective randomness: %v", random)

		err = rh.Verify(rh.Suite(), random, transcript)
		if err != nil {
			t.Fatal(err)
		}
		log.Lvlf1("RandHound - verification: ok")

	case <-time.After(time.Second * time.Duration(nodes) * 2):
		t.Fatal("RandHound – time out")
	}

}
示例#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

}