Example #1
0
func main() {
	lsplog.SetVerbose(10)
	flag.Parse()
	if *storageMasterNodePort == "" {
		if *portnum == 0 {
			*portnum = 9009
		}
		// Single node execution
		*storageMasterNodePort = fmt.Sprintf("localhost:%d", *portnum)
		if *numNodes == 0 {
			*numNodes = 1
			log.Println("Self-mastering, setting nodes to 1")
		}
	}
	l, e := net.Listen("tcp", fmt.Sprintf(":%d", *portnum))
	if e != nil {
		log.Fatal("listen error:", e)
	}
	_, listenport, _ := net.SplitHostPort(l.Addr().String())
	log.Println("Server starting on ", listenport)
	*portnum, _ = strconv.Atoi(listenport)
	ss := storageimpl.NewStorageserver(*storageMasterNodePort, *numNodes, *portnum, uint32(*nodeID))

	srpc := storagerpc.NewStorageRPC(ss)
	rpc.Register(srpc)
	rpc.HandleHTTP()
	http.Serve(l, nil)
}
Example #2
0
func main() {
	var masterPort string = "127.0.0.1:9009"
	var numNodes int = 2
	var portnum int = 9011
	var nodeID uint32 = 1

	//create slave node
	l, e := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", portnum))
	if e != nil {
		log.Fatal("listen error:", e)
	}

	ss := storageimpl.NewStorageserver(masterPort, numNodes, portnum, nodeID)
	srpc := storagerpc.NewStorageRPC(ss)
	rpc.Register(srpc)
	rpc.HandleHTTP()
	http.Serve(l, nil)
}