예제 #1
0
func getPeers() {
	var rpcServ alt.RPCService
	rpcServ.Init()
	firstPeer := alt.Peer{ID: alt.GenID(Config.firstPort), Address: "127.0.0.1:" + Config.firstPort}
	err := rpcServ.MakeRemoteCall(&firstPeer, "GetMembers", struct{}{}, &peers)
	if err != nil {
		fmt.Println("Failed to get members from first node!")
		os.Exit(1)
	}
}
예제 #2
0
func main() {
	flag.BoolVar(&Config.diego, "diego", false, "assumes diego's linux environment, which has nice properties ;)")
	flag.IntVar(&Config.nNodes, "n", 8, "number of entries to be inserted")
	flag.StringVar(&Config.firstPort, "first", "46626", "number of the port of the first port")
	flag.Parse()

	if Config.nNodes < 1 {
		os.Exit(1)
	}

	rand.Seed(time.Now().UTC().UnixNano())
	rpcServ.Init()
	entryMap = make(map[string][]byte)

	// Start first
	if Config.diego {
		exec.Command("i3-msg", "workspace", "next").Run()
	}
	startNode("0", Config.firstPort)
	time.Sleep(200 * time.Millisecond)
	if Config.diego {
		exec.Command("i3-msg", "workspace", "prev").Run()
	}

	// Launch other nodes
	launchNodes(Config.nNodes - 1)
	getPeers()

	var peers []alt.Peer
	firstPeer := alt.Peer{ID: alt.GenID(Config.firstPort), Address: "127.0.0.1:" + Config.firstPort}
	err := rpcServ.MakeRemoteCall(&firstPeer, "GetMembers", struct{}{}, &peers)
	if err != nil {
		fmt.Println("Failed to get members from first node!")
		os.Exit(1)
	}

	scanner := bufio.NewScanner(os.Stdin)
	fmt.Println("Please execute a command:")
	for scanner.Scan() {
		args := strings.Split(scanner.Text(), " ")
		switch args[0] {
		case "create":
			if len(args) < 2 {
				fmt.Println("Usage: create [int]")
				break
			}
			n, err := strconv.Atoi(args[1])
			if checkErr("Usage: create [int]", err) {
				break
			}
			launchNodes(n)
			time.Sleep(5000 * time.Millisecond)
			getPeers()
		case "insert":
			if len(args) < 2 {
				fmt.Println("Usage: insert [int]")
				break
			}
			n, err := strconv.Atoi(args[1])
			if checkErr("Usage: insert [int]", err) {
				break
			}
			getPeers()
			putKeys(n)
		case "insertseq":
			if len(args) < 2 {
				fmt.Println("Usage: insertseq [int]")
				break
			}
			n, err := strconv.Atoi(args[1])
			if checkErr("Usage: insert [int]", err) {
				break
			}
			getPeers()
			putKeysSeq(n)
		case "dumpdata":
			getPeers()
			dumpData()
		case "dumpmeta":
			getPeers()
			dumpMetadata()
		case "test":
			getPeers()
			testKeys()
		}
		fmt.Println("Please execute a command:")
	}
}