Exemplo n.º 1
0
func NewNetwork(me *gway.PeerInfo) (*Network, error) {
	gw := gway.NewGateway()
	err := gw.ListenAll(me.MAddrs)
	if err != nil {
		return nil, err
	}

	gob.Register(&gway.PeerInfo{})

	(&ping.Ping{ProtoNet: gw.NewProtoNet("/ping")}).Serve()

	c := cyclon.New(me, 30, 10, gw.NewProtoNet("/cyclon"))
	c.Start(time.Second)

	b := broadcast.New(2, time.Minute, gw.NewProtoNet("/broadcast"))
	b.Start(c.Out(), 30)

	r := ps.New(1)
	go route(b.Out(), r)

	return &Network{
		gw:  gw,
		cyc: c,
		bro: b,
		rtr: r,
	}, nil
}
Exemplo n.º 2
0
func NewNetwork(me *gway.PeerInfo) error {
	gw := gway.NewGateway()
	err := gw.ListenAll(me.MAddrs)
	if err != nil {
		return err
	}

	(&ping.Ping{ProtoNet: gw.NewProtoNet("/ping")}).Serve()

	return nil
}
Exemplo n.º 3
0
			fmt.Fprintln(stdio, "Hello Status")
			fmt.Fprintf(stdio, "daemon: %v\n", daemon)
			return 0
		},
	},

	"ping": &LocalCommand{
		help: "Usage: pubsub ping <maddr> - Try to contact a remote ping service",
		Run: func(args []string, stdio io.ReadWriter) byte {
			m, err := maddr.NewMultiaddr(args[0])
			if err != nil {
				fmt.Fprintln(stdio, err)
				return 1
			}

			gw := gway.NewGateway()
			png := ping.Ping{ProtoNet: gw.NewProtoNet("/ping")}
			p := &gway.PeerInfo{MAddrs: [][]byte{m.Bytes()}}

			stop := make(chan bool)
			done := make(chan error)

			go func() {
				done <- png.Ping(p, stop)
			}()

			select {
			case err = <-done:
				if err != nil {
					fmt.Fprintln(stdio, err)
					return 1