Пример #1
0
func main() {
	flag.Parse()

	sig := sighandler.New()
	sig.RegisterExitHandler(sigexitfunc)

	/*
	   console.RegisterCommand ("info", "Show info about node", nodeinfo)
	   console.RegisterCommand ("leave", "Gracefully leave the ring", leave)
	   go console.RunConsole(exitfunc)
	*/
	storage = nil
	runtime.GOMAXPROCS(2)

	storage = dht.New(&alive, port, orga, orgp, httpport, 3, 0)

	if alive && storage != nil {
		for alive {
			time.Sleep(2 * time.Second)
		}
	}
	if storage != nil {
		storage.Chord.Organizer.ReportDead(storage.Chord.Node.ID)
	}
}
Пример #2
0
func main() {
	var ALIVE = true
	exitfunc := func() {
		ALIVE = false
	}
	flag.Parse()

	sighandler := sighandler.New()

	n = node.New()
	netutils.RPCRegisterName("Node", n)
	host, listener := host.SetupHost(port)
	if host == nil || listener == nil {
		panic(nil)
	}
	fmt.Println("Serving from: " + host.Address())

	sighandler.RegisterExitHandler(exitfunc)

	http.HandleFunc("/Nodes", handleNodeReq)

	go netutils.RPCServe(listener)
	go graphServe()
	go startconsole(exitfunc)
	go func() {
		for {
			n.ControlPresenceOfRandomNode()
			time.Sleep(1 * time.Second)
		}
	}()
	for ALIVE {
		time.Sleep(100 * time.Millisecond)
	}
	if *killnodesonexit {
		err := killnode([]string{"ALL"})
		if err != nil {
			fmt.Println(err.Error())
		}
	}
}