Beispiel #1
0
func server(c *cli.Context) {
	println("CIRCUIT 2014 gocircuit.org")
	var err error

	if c.Bool("docker") {
		cmd, err := docker.Init()
		if err != nil {
			log.Fatalf("cannot use docker: %v", err)
		}
		log.Printf("Enabling docker elements, using %s", cmd)
	}
	// parse arguments
	var tcpaddr = parseAddr(c) // server bind address
	var join n.Addr            // join address of another circuit server
	if c.IsSet("join") {
		if join, err = n.ParseAddr(c.String("join")); err != nil {
			log.Fatalf("join address does not parse (%s)", err)
		}
	}
	var multicast = parseDiscover(c)
	// server instance working directory
	var varDir string
	if !c.IsSet("var") {
		varDir = path.Join(os.TempDir(), fmt.Sprintf("%s-%%W-P%04d", n.Scheme, os.Getpid()))
	} else {
		varDir = c.String("var")
	}

	// start circuit runtime
	addr := load(tcpaddr, varDir, readkey(c))

	// tissue + locus
	kin, xkin, rip := tissue.NewKin()
	xlocus := locus.NewLocus(kin, rip)

	// joining
	switch {
	case join != nil:
		kin.ReJoin(join)
	case multicast != nil:
		log.Printf("Using UDP multicast discovery on address %s", multicast.String())
		go assemble.NewAssembler(addr, multicast).AssembleServer(
			func(joinAddr n.Addr) {
				kin.ReJoin(joinAddr)
			},
		)
	default:
		log.Println("Singleton server.")
	}

	circuit.Listen(tissue.ServiceName, xkin)
	circuit.Listen(LocusName, xlocus)

	<-(chan int)(nil)
}
Beispiel #2
0
func DialDiscover(multicast string, authkey []byte) *Client {
	mcast, err := net.ResolveUDPAddr("udp", multicast)
	if err != nil {
		panic(err)
	}
	_once.Do(func() {
		_init(authkey)
	})
	c := &Client{}
	dialback := assemble.NewAssembler(circuit.ServerAddr(), mcast).AssembleClient()
	c.y = locus.YLocus{circuit.Dial(dialback, "locus")}
	return c
}