예제 #1
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")
}
예제 #2
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)
		}
	}

}