Beispiel #1
0
func main() {
	*buri = os.Getenv("DOOZER_BOOT_URI")

	flag.Usage = Usage
	flag.Parse()

	if *showVersion {
		fmt.Println("doozerd", peer.Version)
		return
	}

	if *laddr == "" {
		fmt.Fprintln(os.Stderr, "require a listen address")
		flag.Usage()
		os.Exit(1)
	}

	log.SetPrefix("DOOZER ")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	tsock, err := net.Listen("tcp", *laddr)
	if err != nil {
		panic(err)
	}

	usock, err := net.ListenPacket("udp", *laddr)
	if err != nil {
		panic(err)
	}

	var wsock net.Listener
	if *webAddr != "" {
		wsock, err = net.Listen("tcp", *webAddr)
		if err != nil {
			panic(err)
		}
	}

	id := randId()
	var cl *doozer.Conn
	switch {
	case len(aaddrs) > 0 && *buri != "":
		cl = attach(*name, aaddrs)
		if cl == nil {
			cl = boot(*name, id, *laddr, *buri)
		}
	case len(aaddrs) > 0:
		cl = attach(*name, aaddrs)
		if cl == nil {
			panic("failed to attach")
		}
	case *buri != "":
		cl = boot(*name, id, *laddr, *buri)
	}

	peer.Main(*name, id, *buri, secret, cl, usock, tsock, wsock, ns(*pi), ns(*fd), ns(*kt))
	panic("main exit")
}
Beispiel #2
0
func main() {
	*buri = os.Getenv("DOOZER_BOOT_URI")

	flag.Usage = Usage
	flag.Parse()

	if *showVersion {
		fmt.Println("doozerd", peer.Version)
		return
	}

	if *laddr == "" {
		fmt.Fprintln(os.Stderr, "require a listen address")
		flag.Usage()
		os.Exit(1)
	}

	log.SetPrefix("DOOZER ")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	tsock, err := net.Listen("tcp", *laddr)
	if err != nil {
		panic(err)
	}

	if *certFile != "" || *keyFile != "" {
		tsock = tlsWrap(tsock, *certFile, *keyFile)
	}

	uaddr, err := net.ResolveUDPAddr("udp", *laddr)
	if err != nil {
		panic(err)
	}

	usock, err := net.ListenUDP("udp", uaddr)
	if err != nil {
		panic(err)
	}

	var wsock net.Listener
	if *waddr == "" {
		wa, err := net.ResolveTCPAddr("tcp", *laddr)
		if err != nil {
			panic(err)
		}
		wa.Port = defWebPort
		*waddr = wa.String()
	}
	if b, err := strconv.Atob(*waddr); err != nil && !b {
		wsock, err = net.Listen("tcp", *waddr)
		if err != nil {
			panic(err)
		}
	}

	id := randId()
	var cl *doozer.Conn
	switch {
	case len(aaddrs) > 0 && *buri != "":
		cl = attach(*name, aaddrs)
		if cl == nil {
			cl = boot(*name, id, *laddr, *buri)
		}
	case len(aaddrs) > 0:
		cl = attach(*name, aaddrs)
		if cl == nil {
			panic("failed to attach")
		}
	case *buri != "":
		cl = boot(*name, id, *laddr, *buri)
	}

	peer.Main(*name, id, *buri, rwsk, rosk, cl, usock, tsock, wsock, ns(*pi), ns(*fd), ns(*kt), *hi)
	panic("main exit")
}