func Run(server string, nmsgs int, name string, rate int, debug bool) { c := stamp.NewClient(name) msgs := genRandomMessages(nmsgs + 20) servers := strings.Split(server, ",") // connect to all the servers listed for _, s := range servers { h, p, err := net.SplitHostPort(s) if err != nil { log.Fatal("improperly formatted host") } pn, _ := strconv.Atoi(p) c.AddServer(s, coconet.NewTCPConn(net.JoinHostPort(h, strconv.Itoa(pn+1)))) } // if rate specified send out one message every rate milliseconds if rate > 0 { // Stream time stamp requests streamMessgs(c, servers, rate) return } // rounds based messaging r := 0 s := 0 // ROUNDS BASED IS DEPRECATED log.Fatal("ROUNDS BASED RATE LIMITING DEPRECATED") for { //start := time.Now() var wg sync.WaitGroup for i := 0; i < nmsgs; i++ { wg.Add(1) go func(i, s int) { defer wg.Done() err := c.TimeStamp(msgs[i], servers[s]) if err == io.EOF { log.WithFields(log.Fields{ "file": logutils.File(), "type": "client_msg_stats", "buck": make([]int64, 0), "roundsAfter": make([]int64, 0), }).Info("") log.Fatal("EOF: terminating time client") } }(i, s) s = (s + 1) % len(servers) } wg.Wait() //elapsed := time.Since(start) log.Println("client done with round") //log.WithFields(log.Fields{ //"file": logutils.File(), //"type": "client_round", //"round": r, //"time": elapsed, //}).Info("client round") r++ } }
// 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 }