// # 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 }
// run each host in hostnameSlice with the number of clients given func (hc *HostConfig) RunTimestamper(nclients int, hostnameSlice ...string) ([]*stamp.Server, []*stamp.Client, error) { //log.Println("RunTimestamper") hostnames := make(map[string]*sign.Node) // make a list of hostnames we want to run if hostnameSlice == nil { hostnames = hc.Hosts } else { for _, h := range hostnameSlice { sn, ok := hc.Hosts[h] if !ok { return nil, nil, errors.New("hostname given not in config file:" + h) } hostnames[h] = sn } } Clients := make([]*stamp.Client, 0, len(hostnames)*nclients) // for each client in stampers := make([]*stamp.Server, 0, len(hostnames)) for _, sn := range hc.SNodes { if _, ok := hostnames[sn.Name()]; !ok { log.Errorln("signing node not in hostnmaes") continue } stampers = append(stampers, stamp.NewServer(sn)) if hc.Dir == nil { //log.Println("listening for clients") stampers[len(stampers)-1].Listen() } } //log.Println("stampers:", stampers) clientsLists := make([][]*stamp.Client, len(hc.SNodes[1:])) for i, s := range stampers[1:] { // cant assume the type of connection clients := make([]*stamp.Client, nclients) h, p, err := net.SplitHostPort(s.Name()) if hc.Dir != nil { h = s.Name() } else if err != nil { log.Fatal("RunTimestamper: bad Tcp host") } pn, err := strconv.Atoi(p) if hc.Dir != nil { pn = 0 } else if err != nil { log.Fatal("port is not valid integer") } hp := net.JoinHostPort(h, strconv.Itoa(pn+1)) //log.Println("client connecting to:", hp) for j := range clients { clients[j] = stamp.NewClient("client" + strconv.Itoa((i-1)*len(stampers)+j)) var c coconet.Conn // if we are using tcp connections if hc.Dir == nil { // the timestamp server serves at the old port + 1 //log.Println("new tcp conn") c = coconet.NewTCPConn(hp) } else { //log.Println("new go conn") c, _ = coconet.NewGoConn(hc.Dir, clients[j].Name(), s.Name()) stoc, _ := coconet.NewGoConn(hc.Dir, s.Name(), clients[j].Name()) s.Clients[clients[j].Name()] = stoc } // connect to the server from the client clients[j].AddServer(s.Name(), c) //clients[j].Sns[s.Name()] = c //clients[j].Connect() } Clients = append(Clients, clients...) clientsLists[i] = clients } return stampers, Clients, nil }