Exemplo n.º 1
0
func main() {
	var args []string
	var numNodes int
	var firstPort int
	var seed int64
	flag.IntVar(&numNodes, "n", 10, "number of nodes to generate")
	flag.IntVar(&firstPort, "p", 8000, "port to assign first DryMartini to listen on (continguous range for remaining DM's)")
	flag.Int64Var(&seed, "s", time.Now().UnixNano(), "seed to use for random generation")
	flag.Parse()
	args = flag.Args()

	rand.Seed(seed) //seed generic rand anyway, cause i'm too lazy to refactor everything to use the rand generated here. and we still want randomness, even at the expense of easy replication of errors
	log.Printf("using seed:%d\n", seed)
	numNodes = strConv(args[0])
	firstPort = strConv(args[1])
	log.Printf("Running tests: numNodes:%d\n", numNodes)
	kademlia.TestStartTime = time.Now().Local()
	logfile, err := os.Create("./logs/complete_log_" + kademlia.TestStartTime.String())
	if err != nil {
		log.Printf("error creating main log:%s\n", err)
		panic(1)
	}
	dbg.InitDbgOut(logfile)

	//instantiate
	var dm *drymartini.DryMartini
	listenStr := string(strconv.AppendInt([]byte("localhost:"), int64(firstPort-1), 10))
	dm = drymartini.NewDryMartini(listenStr, 4096)

	drymartini.RunTests(dm, numNodes, firstPort, seed, 4, 4)
	log.Printf("seed was:%d\n", seed)
}
Exemplo n.º 2
0
func main() {
	var err error
	var listenStr = flag.String("proxy", "8888", "Proxy listen port (the port you point your browser to)")
	var dmListenStr = flag.String("d", "localhost:8000", "DryMartini listen address")
	var connectStr = flag.String("c", "", "DryMartini node to connect to")
	var isTest = flag.Bool("test", false, "Indicate this node will be used for running test suite")
	var seed int64
	flag.Int64Var(&seed, "s", time.Now().UnixNano(), "seed to use for random generation")

	// Get the bind and connect connection strings from command-line arguments.

	flag.Parse()

	log.Printf("proxy listening on:%s\n", *listenStr)
	log.Printf("DryMartini opening on:%s\n", *dmListenStr)
	log.Printf("DryMartini node connecting to:%s\n", *connectStr)
	log.Printf("is Test:%t\n", *isTest)

	kademlia.RunningTests = *isTest
	kademlia.TestStartTime = time.Now().Local()
	err = os.Mkdir("./logs/", os.ModeDir)
	logfile, err := os.Create("./logs/complete_log_" + kademlia.TestStartTime.String())
	if err != nil {
		log.Printf("error creating main log:%s\n", err)
		panic(1)
	}
	dbg.InitDbgOut(logfile)

	rand.Seed(seed)

	//instantiate
	myDryMartini = drymartini.NewDryMartini(*dmListenStr, 4096)

	if *connectStr != "" {
		success, err := MakePing(myDryMartini, *connectStr)
		if !success {
			log.Printf("connect to %s failed. err:%s\n", connectStr, err)
			panic(1)
		}
		drymartini.DoJoin(myDryMartini)
	}

	/*
		host, port, errr := kademlia.AddrStrToHostPort(connectStr)
		var swarm []*drymartini.DryMartini = drymartini.MakeSwarm(8, int(port))
		drymartini.WarmSwarm(myDryMartini, swarm)
	*/

	kademlia.PrintLocalBuckets(myDryMartini.KademliaInst)

	proxy := goproxy.NewProxyHttpServer()
	proxy.OnRequest().DoFunc(DoHTTPRequest)
	log.Fatal(http.ListenAndServe(":"+*listenStr, proxy))
	/*
			var stdInReader *bufio.Reader = bufio.NewReader(os.Stdin)
			var instStr string
			var inst *DryMartiniInstruction
			for ;; {
				fmt.Printf("δώσε:")//Print prompt

		        //read new instruction
				//ret, err := fmt.Scanln(&instStr)
				instStr, err = stdInReader.ReadString('\n')
				if err != nil {
					log.Printf("Error at Scanf: %s\n", err)
					panic(1)
				}

				//parse line input and create command struct
				inst = NewDryMartiniInstruction(instStr)

				if inst.IsExit() {
					log.Printf("DryMartini exiting.\n\n\nOne for the road, maybe?");
					break;
				}

				//execute new instruction
				inst.Execute(myDryMartini)

				if (myDryMartini.KademliaInst.DoJoinFlag) {
					log.Printf("DoingJoin!\n")
					go drymartini.DoJoin(myDryMartini)
				}
			}
	*/
	log.Printf("end of main\n")
}
Exemplo n.º 3
0
func main() {
	var numNodes = flag.Int("n", 10, "number of nodes to create for test")
	var firstPort = flag.Int("p", 8000, "port for first node in test swarm to listen on")
	var seed = flag.Int64("seed", time.Now().UnixNano(), "seed to use for random gen")

	flag.Parse()
	rand.Seed(*seed) //seed generic rand anyway, cause i'm too lazy to refactor everything to use the rand generated here. and we still want randomness, even at the expense of easy replication of errors
	log.Printf("using seed:%d\n", *seed)
	log.Printf("Running tests: numNodes:%d\n", *numNodes)
	kademlia.TestStartTime = time.Now().Local()
	err := os.MkdirAll(fileDirStr, os.ModeDir|os.ModePerm)

	var logfile *os.File
	logfile, err = os.Create(fileDirStr + "/complete_log_" + kademlia.TestStartTime.String())
	if err != nil {
		log.Printf("error creating main log:%s\n", err)
		panic(1)
	}
	dbg.InitDbgOut(logfile)

	var outfiles []*os.File
	outfiles = initOutputFiles(*numNodes)

	cmds := make([]*exec.Cmd, *numNodes, *numNodes)
	//	cmds[0] = exec.Command("../../bin/main", "localhost:"+strconv.Itoa(*firstPort))
	//var out bytes.Buffer
	/*
		cmds[0].Stdin = strings.NewReader("ping localhost:"+strconv.Itoa(*firstPort -1))
		cmds[0].Stdout = outfiles[0]
		cmds[0].Stderr = outfiles[0]
	*/

	//	err = cmds[0].Start()
	//	log.Printf("first node started!\n")
	for i := 0; i < *numNodes; i++ {
		cmds[i] = exec.Command("../../bin/main", "localhost:"+strconv.Itoa((*firstPort)+i))
		cmds[i].Stdout = os.Stdout
		cmds[i].Stderr = outfiles[i]
		//generate cmd sequence for DM's
		cmds[i].Stdin = drymartini.GenerateDmCmdSeq(fileDirStr, *firstPort, *numNodes, (*firstPort)+i)
		//cmds[i].Stdin = file.open("ping localhost:"+strconv.Itoa(*firstPort -1))
		err = cmds[i].Start()
		if err != nil {
			log.Printf("error running cmd:%s\n", err)
			panic(1)
		}
		log.Printf("node:%d started!\n", i)
	}
	for i := 0; i < *numNodes; i++ {
		log.Printf("%d nodes finished\n", i)
		err = cmds[i].Wait()
		if err != nil {
			log.Printf("node number:%d finished with error:%s\n", i, err.Error())
		}
	}
	/*
			//instantiate
			var dm *drymartini.DryMartini
			listenStr := string(strconv.AppendInt([]byte("localhost:"), int64(firstPort-1), 10))
		    dm = drymartini.NewDryMartini(listenStr, 4096)

			drymartini.RunTests(dm, numNodes, firstPort, seed, 4, 4)
			log.Printf("seed was:%d\n", seed)
	*/
}