func NewClient(uuid, localAddr string, daemonAddr string, daemonPortUdp int, servicetype string, ad string, addresses []string, ports []int) (c *Client) { incoming, err := connection.NewIncoming(localAddr) if err != nil { panic(err) } c = &Client{ uuid: uuid, localAddr: localAddr, daemonAddr: daemonAddr, daemonPortUdp: daemonPortUdp, servicetype: servicetype, ad: ad, addresses: addresses, ports: ports, localPort: incoming.Port(), logger: log.New(os.Stdout, "client ", log.Lshortfile), stop: eventual2go.NewCompleter(), } c.logger.Println("starting") c.logger.Println("incoming port is", c.localPort) c.stop.Future().Then(stopIncoming(incoming)) msg_in := incoming.In().Where(ValidMessage) c.arrived = msg_in.Where(IsMessage(SERVICE_ARRIVE)).Transform(ToServiceArrivedMessage) c.gone = msg_in.Where(IsMessage(SERVICE_GONE)).Transform(ToServiceGone) msg_in.Where(IsMessage(HELLO)).Listen(c.onHello) return }
func New(addr string, port int) (d *Daemon) { d = new(Daemon) d.clients = map[string]*eventual2go.StreamController{} d.announcer = map[string]*service.Announcer{} d.logger = log.New(os.Stdout, "daemon ", log.Lshortfile) d.logger.Println("starting up") incoming, _ := connection.NewIncoming(addr) d.logger.Println("launched incoming at", incoming.Port()) msg := incoming.In().Where(ValidMessage) ct := NewClientTracker(addr, port) r := eventual2go.NewReactor() r.React("new_client", d.newClient(incoming.Port())) r.AddStream("new_client", ct.new.Stream) r.React("client_gone", d.clientGone) r.AddStream("client_gone", ct.gone.Stream) r.React("client_service", d.clientService) r.AddStream("client_service", msg.Where(IsMessage(EXPORT)).Transform(ToNewServiceMessage)) r.AddStream("client_service", msg.Where(IsMessage(IMPORT)).Transform(ToNewServiceMessage)) d.logger.Println("starting tracker") ct.Run() d.logger.Println("started") return }
func NewClient(uuid, localAddr string, daemonAddr string, daemonPortUdp int, servicetype string, ad *appdescriptor.AppDescriptor, addresses []string) (c *Client) { c = new(Client) c.logger = log.New(os.Stdout, "client ", log.Lshortfile) c.logger.Println("starting") c.uuid = uuid c.ad = ad c.addresses = addresses c.servicetype = servicetype c.localAddr = localAddr c.daemonAddr = daemonAddr c.daemonPortUdp = daemonPortUdp c.stop = eventual2go.NewCompleter() incoming, err := connection.NewIncoming(localAddr) if err != nil { panic(err) } c.localPort = incoming.Port() c.logger.Println("incoming port is", c.localPort) c.stop.Future().Then(stopIncoming(incoming)) msg_in := incoming.In().Where(ValidMessage) c.arrived = msg_in.Where(IsMessage(SERVICE_ARRIVE)).Transform(ToServiceArrivedMessage) c.gone = msg_in.Where(IsMessage(SERVICE_GONE)).Transform(ToServiceGone) msg_in.Where(IsMessage(HELLO)).Listen(c.onHello) return }
func (s *Service) createIncoming(cfg *config.Config) { for _, addr := range cfg.NetworkInterfaces { s.logger.Println("Opening Incoming Socket on", addr) incoming, err := connection.NewIncoming(addr) if err == nil { s.in.Join(incoming.In().Where(messages.Valid).Transform(messages.ToIncomingMsg)) s.logger.Println("port is", incoming.Port()) s.incoming[addr] = incoming } else { s.logger.Println("Error opening socket", err) } } }