示例#1
0
func FindTarget(name string, leader string) (target string) {
	l := client.NewNameServiceProxy(leader)
	for {
		locations := l.Find(name)
		if len(locations) > 0 {
			target = locations[rand.Intn(len(locations))]
		}
		if target != "" {
			break
		} else {
			time.Sleep(time.Second)
			// print("z")
		}
	}
	return
}
示例#2
0
func getCommandConnection(tlsConfig *tls.Config, leader string, agentName string) (io.ReadWriteCloser, error) {
	l := client.NewNameServiceProxy(leader)

	// looking for the agentName
	var target string
	for {
		locations := l.Find(agentName)
		if len(locations) > 0 {
			target = locations[0]
		}
		if target != "" {
			break
		} else {
			time.Sleep(time.Second)
			print("z")
		}
	}

	return getDirectCommandConnection(tlsConfig, target)
}