コード例 #1
0
ファイル: client.go プロジェクト: prodigeni/circuit
// Dial establishes a connection to a circuit server specified by a circuit address.
// Circuit addresses are printed to standard output when a server is started with the
// "circuit start …" command.
// Errors in communication, such as a missing server, or invalid URL format
// are reported through panics.
func Dial(addr string) *Client {
	_once.Do(_init)
	c := &Client{}
	w, err := n.ParseAddr(addr)
	if err != nil {
		panic("circuit address does not parse")
	}
	c.y = locus.YLocus{circuit.Dial(w, "locus")}
	return c
}
コード例 #2
0
ファイル: client.go プロジェクト: keryoo/circuit
// Dial establishes a connection to a circuit server specified by a circuit address.
// Circuit addresses are printed to standard output when a server is started with the
// "circuit start …" command.
//
// If authkey is non-nil it is used as a private key and all communications are
// secured by HMAC authentication and RC4 symmetric encryption;
// otherwise transmissions are in plaintext.
//
// Errors in communication, such as a missing server, or invalid URL format
// are reported through panics.
func Dial(addr string, authkey []byte) *Client {
	_once.Do(func() {
		_init(authkey)
	})
	c := &Client{}
	w, err := n.ParseAddr(addr)
	if err != nil {
		panic("circuit address does not parse")
	}
	c.y = locus.YLocus{circuit.Dial(w, "locus")}
	return c
}
コード例 #3
0
ファイル: client.go プロジェクト: keryoo/circuit
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
}
コード例 #4
0
ファイル: kin.go プロジェクト: keryoo/circuit
// ReJoin contacts the peering service at the circuit worker with address join
// and joins into its circuit network.
func (k *Kin) ReJoin(join n.Addr) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("panic joining: %v", r)
		}
	}()
	ykin := YKin{
		KinAvatar{
			X: circuit.Dial(join, ServiceName),
		},
	}
	for _, peer := range ykin.Join(k.chooseBoundary(Spread), Spread) {
		peer = k.remember(peer)
	}
	return nil
}
コード例 #5
0
ファイル: kin.go プロジェクト: herokai/circuit
// ReJoin contacts the peering kin service join and joins its circuit network.
func (k *Kin) ReJoin(join n.Addr) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("panic joining: %v", r)
		}
	}()
	ykin := YKin{
		KinAvatar{
			X: circuit.Dial(join, ServiceName),
		},
	}
	var w bytes.Buffer
	for _, peer := range ykin.Join(k.chooseBoundary(Spread), Spread) {
		peer = k.remember(peer)
		w.WriteString(peer.X.Addr().String())
		w.WriteByte(' ')
	}
	// if w.Len() > 0 {
	// 	log.Println("Remembering offered server(s):", w.String())
	// }
	return nil
}
コード例 #6
0
ファイル: start.go プロジェクト: prodigeni/circuit
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)
}