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)
}
示例#2
0
func (dmInst *DryMartiniInstruction) Execute(dm *drymartini.DryMartini) (status bool) {
	var err error

	switch {
	case dmInst.IsExit():
		if Verbose {
			log.Printf("Executing Exit Instruction\n")
		}
		return true
	case dmInst.IsSkip():
		if Verbose {
			log.Printf("Executing Skip Instruction: _%s_\n", dmInst.CmdStr)
		}
		return true
	case dmInst.IsPing():
		var success bool

		if Verbose {
			log.Printf("Executing Ping Instruction 'ping Addr:%s\n", dmInst.Addr)
		}
		remoteHost, remotePort, err := kademlia.AddrStrToHostPort(dmInst.Addr)
		if err != nil {
			log.Printf("Error converting AddrToHostPort, %s", err)
			os.Exit(1)
		}
		success = drymartini.MakeMartiniPing(dm, remoteHost, remotePort)

		return success
	case dmInst.IsJoin():
		if Verbose {
			log.Printf("Executing MartiniJoin Instruction\n")
		}
		//remoteHost, remotePort, err := kademlia.AddrStrToHostPort(dmInst.Addr)
		//drymartini.MakeJoin(dm, remoteHost, remotePort)
		//if err != nil {
		//	log.Printf("Error converting AddrToHostPort, %s", err)
		//	os.Exit(1)
		//}
		return true
	case dmInst.IsWhoami():
		if Verbose {
			log.Printf("Executing Whoami Instruction\n")
			fmt.Printf("Local Node ID: %s\n", dm.KademliaInst.ContactInfo.NodeID.AsString())
		} else {
			fmt.Printf("%s\n", dm.KademliaInst.ContactInfo.NodeID.AsString())
		}
		return true
	case dmInst.IsPrintLocalBuckets():
		log.Printf("Print Local Buckets!\n")
		kademlia.PrintLocalBuckets(dm.KademliaInst)
		return true
	case dmInst.IsPrintLocalData():
		log.Printf("Print Local Data!\n")
		//kademlia.PrintLocalData(dm.KademliaInst)
		drymartini.PrintLocalData(dm)
		return true
	case dmInst.IsPrintLocalFlowData():
		log.Printf("Print Local FlowData!\n")
		drymartini.PrintLocalFlowData(dm)
		return true
	case dmInst.IsGeneratePath():
		log.Printf("Generate Path\n")
		drymartini.GeneratePath(dm, dmInst.minNodes, dmInst.maxNodes)
		return true
	case dmInst.IsBarCrawl():
		log.Printf("Bar Crawl (negotiating symmkeys with nodes)")
		drymartini.BarCrawl(dm, dmInst.request, dmInst.minNodes, dmInst.maxNodes)
	case dmInst.IsFindValue():
		log.Printf("Find Value")
		var sucess bool
		//var nodes[]kademlia.FoundNode
		var value []byte
		sucess, _, value, err = kademlia.IterativeFind(dm.KademliaInst, dmInst.Key, 2)
		if err != nil {
			log.Printf("IterativeFind: error %s\n", err)
		}
		if sucess {
			if value != nil {
				log.Printf("IterativeFindValue err: success = true. value is nil\n")
			}
		}
	case dmInst.IsSend():
		log.Printf("Send %d %s\n", dmInst.FlowIndex, dmInst.request)
		drymartini.SendData(dm, dmInst.FlowIndex, dmInst.request)
	case dmInst.IsMakeSwarm():
		log.Printf("Making swarm: numNodes:%d\n", dmInst.minNodes)
		var swarm []*drymartini.DryMartini = drymartini.MakeSwarm(dmInst.minNodes, dmInst.maxNodes, time.Now().UnixNano())
		drymartini.WarmSwarm(dm, swarm, rand.New(rand.NewSource(time.Now().UnixNano())))
	case dmInst.IsRunTests():
		log.Printf("Running tests: numNodes:%d\n", dmInst.minNodes)
		drymartini.RunTests(dm, dmInst.minNodes, dmInst.maxNodes, time.Now().UnixNano(), 4, 4)
	case dmInst.IsSleep():
		log.Printf("Sleeping %d ms\n", dmInst.minNodes)
		time.Sleep(time.Millisecond * time.Duration(dmInst.minNodes))
	case dmInst.IsBlock():
		fmt.Printf("Blocking comm on node\n")
		log.Printf("Blocking comm on this node\n")
		dm.KademliaInst.KListener.Close()
	case dmInst.IsOpen():
		fmt.Printf("Accepting comm on node again\n")
		log.Printf("Accepting comms again\n")
		go http.Serve(dm.KademliaInst.KListener, nil)
	case dmInst.IsBCAndSend():
		log.Printf("bc and send\n")
		success, index := drymartini.FindGoodPath(dm)
		if !success {
			success, index = drymartini.BarCrawl(dm, dmInst.request, dmInst.minNodes, dmInst.maxNodes)
			if !success {
				log.Printf("Error: main. bcandsend; bc failed\n")
				return
			}
		}
		drymartini.SendData(dm, index, dmInst.request)
	}
	return false
}