Ejemplo n.º 1
0
func (gw *Gateway) ListenAll(maddrs [][]byte) error {
	retErr := multierr.New()
	addErr := func(err error) {
		if retErr.Errors == nil {
			retErr.Errors = make([]error, 0)
		}
		retErr.Errors = append(retErr.Errors, err)
	}

	// listen on every address
	for _, bts := range maddrs {
		m, err := ma.NewMultiaddrBytes(bts)
		if err != nil {
			addErr(err)
			continue
		}

		err = gw.listen(m)
		if err != nil {
			addErr(err)
		}
	}

	if retErr.Errors != nil {
		return retErr
	}
	return nil
}
Ejemplo n.º 2
0
// Open listeners for each network the swarm should listen on
func (s *Swarm) listen(addrs []ma.Multiaddr) error {

	for _, addr := range addrs {
		if !addrutil.AddrUsable(addr, true) {
			return fmt.Errorf("cannot use addr: %s", addr)
		}
	}

	retErr := multierr.New()

	// listen on every address
	for i, addr := range addrs {
		err := s.setupListener(addr)
		if err != nil {
			if retErr.Errors == nil {
				retErr.Errors = make([]error, len(addrs))
			}
			retErr.Errors[i] = err
			log.Debugf("Failed to listen on: %s - %s", addr, err)
		}
	}

	if retErr.Errors != nil {
		return retErr
	}
	return nil
}