func runTreeSmallConfig(signType sign.Type, RoundsPerView int, suite abstract.Suite, failureRate int, faultyNodes ...int) error {
	var hc *oldconfig.HostConfig
	var err error
	opts := oldconfig.ConfigOptions{Suite: suite}

	if len(faultyNodes) > 0 {
		opts.Faulty = true
	}
	hc, err = oldconfig.LoadConfig("../test/data/exconf.json", opts)
	if err != nil {
		return err
	}

	for _, fh := range faultyNodes {
		fmt.Println("Setting", hc.SNodes[fh].Name(), "as faulty")
		if failureRate == 100 {
			hc.SNodes[fh].Host.(*coconet.FaultyHost).SetDeadFor("commit", true)

		}
		// hc.SNodes[fh].Host.(*coconet.FaultyHost).Die()
	}

	if len(faultyNodes) > 0 {
		for i := range hc.SNodes {
			hc.SNodes[i].FailureRate = failureRate
		}
	}
	for _, sn := range hc.SNodes {
		sn.RoundsPerView = RoundsPerView
	}

	err = hc.Run(false, signType)
	if err != nil {
		return err
	}

	for _, sn := range hc.SNodes {
		defer sn.Close()
	}
	// Have root node initiate the signing protocol via a simple annoucement
	hc.SNodes[0].LogTest = []byte("Hello World")
	hc.SNodes[0].StartAnnouncement(&sign.AnnouncementMessage{LogTest: hc.SNodes[0].LogTest, Round: 1})

	return nil
}
Exemple #2
0
// # Messages per round, # rounds, failure rate[0..100], list of faulty nodes
func runTSSIntegration(RoundsPerView, nMessages, nRounds, failureRate, failAsRootEvery, failAsFollowerEvery int, faultyNodes ...int) error {
	//stamp.ROUND_TIME = 1 * time.Second
	var hostConfig *oldconfig.HostConfig
	var err error

	// load config with faulty or healthy hosts
	opts := oldconfig.ConfigOptions{}
	if len(faultyNodes) > 0 {
		opts.Faulty = true
	}
	hostConfig, err = oldconfig.LoadConfig("../test/data/exconf.json", opts)
	if err != nil {
		return err
	}
	log.Printf("load config returned dir: %p", hostConfig.Dir)

	// set FailureRates as pure percentages
	if len(faultyNodes) > 0 {
		for i := range hostConfig.SNodes {
			hostConfig.SNodes[i].FailureRate = failureRate
		}
	}

	// set root failures
	if failAsRootEvery > 0 {
		for i := range hostConfig.SNodes {
			hostConfig.SNodes[i].FailAsRootEvery = failAsRootEvery

		}
	}
	// set followerfailures
	for _, f := range faultyNodes {
		hostConfig.SNodes[f].FailAsFollowerEvery = failAsFollowerEvery
	}

	for _, n := range hostConfig.SNodes {
		n.RoundsPerView = RoundsPerView
	}

	err = hostConfig.Run(true, sign.MerkleTree)
	if err != nil {
		return err
	}

	// Connect all TSServers to their clients, except for root TSServer
	ncps := 3 // # clients per TSServer
	stampers := make([]*stamp.Server, len(hostConfig.SNodes))
	for i := range stampers {
		stampers[i] = stamp.NewServer(hostConfig.SNodes[i])
		defer func() {
			hostConfig.SNodes[i].Close()
			time.Sleep(1 * time.Second)
		}()
	}

	clientsLists := make([][]*stamp.Client, len(hostConfig.SNodes[1:]))
	for i, s := range stampers[1:] {
		clientsLists[i] = createClientsForTSServer(ncps, s, hostConfig.Dir, 0+i+ncps)
	}

	for i, s := range stampers[1:] {
		go s.Run("regular", nRounds)
		go s.ListenToClients()
		go func(clients []*stamp.Client, nRounds int, nMessages int, s *stamp.Server) {
			log.Println("clients Talk")
			time.Sleep(1 * time.Second)
			clientsTalk(clients, nRounds, nMessages, s)
			log.Println("Clients done Talking")
		}(clientsLists[i], nRounds, nMessages, s)

	}

	log.Println("RUNNING ROOT")
	stampers[0].ListenToClients()
	stampers[0].Run("root", nRounds)
	log.Println("Done running root")
	// After clients receive messages back we need a better way
	// of waiting to make sure servers check ElGamal sigs
	// time.Sleep(1 * time.Second)
	log.Println("DONE with test")
	return nil
}
Exemple #3
0
func Run(hostname, cfg, app string, rounds int, rootwait int, debug, testConnect bool, failureRate, rFail, fFail int, logger, suite string) {
	if debug {
		coco.DEBUG = true
	}

	// fmt.Println("EXEC TIMESTAMPER: " + hostname)
	if hostname == "" {
		fmt.Println("hostname is empty")
		log.Fatal("no hostname given")
	}

	// load the configuration
	//log.Println("loading configuration")
	var hc *oldconfig.HostConfig
	var err error
	s := GetSuite(suite)
	opts := oldconfig.ConfigOptions{ConnType: "tcp", Host: hostname, Suite: s}
	if failureRate > 0 || fFail > 0 {
		opts.Faulty = true
	}
	hc, err = oldconfig.LoadConfig(cfg, opts)
	if err != nil {
		fmt.Println(err)
		log.Fatal(err)
	}

	// set FailureRates
	if failureRate > 0 {
		for i := range hc.SNodes {
			hc.SNodes[i].FailureRate = failureRate
		}
	}

	// set root failures
	if rFail > 0 {
		for i := range hc.SNodes {
			hc.SNodes[i].FailAsRootEvery = rFail

		}
	}
	// set follower failures
	// a follower fails on %ffail round with failureRate probability
	for i := range hc.SNodes {
		hc.SNodes[i].FailAsFollowerEvery = fFail
	}

	// run this specific host
	// log.Println("RUNNING HOST CONFIG")
	err = hc.Run(app != "sign", sign.MerkleTree, hostname)
	if err != nil {
		log.Fatal(err)
	}

	defer func(sn *sign.Node) {
		log.Panicln("program has terminated:", hostname)
		sn.Close()
	}(hc.SNodes[0])

	if app == "sign" {
		//log.Println("RUNNING Node")
		// if I am root do the announcement message
		if hc.SNodes[0].IsRoot(0) {
			time.Sleep(3 * time.Second)
			start := time.Now()
			iters := 10

			for i := 0; i < iters; i++ {
				start = time.Now()
				//fmt.Println("ANNOUNCING")
				hc.SNodes[0].LogTest = []byte("Hello World")
				err = hc.SNodes[0].Announce(0,
					&sign.AnnouncementMessage{
						LogTest: hc.SNodes[0].LogTest,
						Round:   i})
				if err != nil {
					log.Println(err)
				}
				elapsed := time.Since(start)
				log.WithFields(log.Fields{
					"file":  logutils.File(),
					"type":  "root_announce",
					"round": i,
					"time":  elapsed,
				}).Info("")
			}

		} else {
			// otherwise wait a little bit (hopefully it finishes by the end of this)
			time.Sleep(30 * time.Second)
		}
	} else if app == "stamp" || app == "vote" {
		// log.Println("RUNNING TIMESTAMPER")
		stampers, _, err := hc.RunTimestamper(0, hostname)
		// get rid of the hc information so it can be GC'ed
		hc = nil
		if err != nil {
			log.Fatal(err)
		}
		for _, s := range stampers {
			// only listen if this is the hostname specified
			if s.Name() == hostname {
				s.Logger = logger
				s.Hostname = hostname
				s.App = app
				if s.IsRoot(0) {
					log.Println("RUNNING ROOT SERVER AT:", hostname, rounds)
					log.Printf("Waiting: %d s\n", rootwait)
					// wait for the other nodes to get set up
					time.Sleep(time.Duration(rootwait) * time.Second)

					log.Println("STARTING ROOT ROUND")
					s.Run("root", rounds)
					// log.Println("\n\nROOT DONE\n\n")

				} else if !testConnect {
					log.Println("RUNNING REGULAR AT:", hostname)
					s.Run("regular", rounds)
					// log.Println("\n\nREGULAR DONE\n\n")
				} else {
					// testing connection
					log.Println("RUNNING TEST_CONNNECT AT:", hostname)
					s.Run("test_connect", rounds)
				}
			}
		}
	}

}