Ejemplo n.º 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)
}
Ejemplo n.º 2
0
func server(c *cli.Context) {
	println("CIRCUIT 2014 gocircuit.org")
	log.Println("Starting circuit server")
	// parse arguments
	if !c.IsSet("addr") {
		log.Fatal("server network address not given; use -addr")
	}
	var err error
	var join n.Addr
	if c.IsSet("join") {
		if join, err = n.ParseAddr(c.String("join")); err != nil {
			log.Fatalf("join address does not parse (%s)", err)
		}
	}
	var mutexDir string
	if !c.IsSet("mutex") {
		mutexDir = path.Join(os.TempDir(), fmt.Sprintf("%s-%%W-P%04d", n.Scheme, os.Getpid()))
	} else {
		mutexDir = c.String("mutex")
	}

	// start circuit runtime
	load(c.String("addr"), mutexDir)

	// kinfolk join
	var xjoin circuit.PermX
	dontPanic(func() {
		xjoin = circuit.Dial(join, KinfolkName)
	}, "join")

	// locus
	kin, xkin, kinJoin, kinLeave := kinfolk.NewKin(xjoin)
	xlocus := locus.NewLocus(kin, kinJoin, kinLeave)

	circuit.Listen(KinfolkName, xkin)
	circuit.Listen(LocusName, xlocus)

	<-(chan int)(nil)
}
Ejemplo n.º 3
0
func (a *Assembler) AssembleClient() n.Addr { // XXX: Clients should get more than one offering.
	d, xd := NewDialBack()
	circuit.Listen("dialback", xd)
	go a.scatter("client")
	return d.ObtainAddr()
}