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)
}
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")
}
Beispiel #3
0
func main() {
	var err error
	var args []string
	var listenStr string
	//var listenKadem string
	var stdInReader *bufio.Reader

	// Get the bind and connect connection strings from command-line arguments.
	flag.Parse()
	args = flag.Args()
	if len(args) != 1 {
		log.Fatal("Must be invoked with exactly one arguments!\n")
	}
	listenStr = args[0]
	//listenKadem = args[1]

	rand.Seed(time.Now().UnixNano())

	//instantiate
	var drymart *drymartini.DryMartini
	drymart = drymartini.NewDryMartini(listenStr, 4096)

	//fmt.Printf("%s", drymart.KeyPair)

	stdInReader = 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 {
			if err.Error() != "EOF" {
				log.Printf("Error at Scanf: %s\n", err)
				panic(1)
			} else {
				fmt.Printf("node:%s done. sleeping 10 secs, then exiting\n", drymart.KademliaInst.ContactInfo.AsString())
				time.Sleep(10 * time.Second)
				instStr = "exit"
			}
		}

		//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(drymart)

		if drymart.KademliaInst.DoJoinFlag {
			go drymartini.DoJoin(drymart)
		}
	}

}