Ejemplo n.º 1
0
func parseStringPort(data []byte) (v2net.Port, v2net.Port, error) {
	var s string
	err := json.Unmarshal(data, &s)
	if err != nil {
		return v2net.Port(0), v2net.Port(0), err
	}
	pair := strings.SplitN(s, "-", 2)
	if len(pair) == 0 {
		return v2net.Port(0), v2net.Port(0), v2net.ErrInvalidPortRange
	}
	if len(pair) == 1 {
		port, err := v2net.PortFromString(pair[0])
		return port, port, err
	}

	fromPort, err := v2net.PortFromString(pair[0])
	if err != nil {
		return v2net.Port(0), v2net.Port(0), err
	}
	toPort, err := v2net.PortFromString(pair[1])
	if err != nil {
		return v2net.Port(0), v2net.Port(0), err
	}
	return fromPort, toPort, nil
}
Ejemplo n.º 2
0
func (v *FreedomConfig) Build() (*serial.TypedMessage, error) {
	config := new(freedom.Config)
	config.DomainStrategy = freedom.Config_AS_IS
	domainStrategy := strings.ToLower(v.DomainStrategy)
	if domainStrategy == "useip" || domainStrategy == "use_ip" {
		config.DomainStrategy = freedom.Config_USE_IP
	}
	config.Timeout = 600
	if v.Timeout != nil {
		config.Timeout = *v.Timeout
	}
	if len(v.Redirect) > 0 {
		host, portStr, err := net.SplitHostPort(v.Redirect)
		if err != nil {
			return nil, errors.Base(err).Message("Config: Invalid redirect address: ", v.Redirect, ": ", err)
		}
		port, err := v2net.PortFromString(portStr)
		if err != nil {
			return nil, errors.Base(err).Message("Config: Invalid redirect port: ", v.Redirect, ": ", err)
		}
		if len(host) == 0 {
			host = "127.0.0.1"
		}
		config.DestinationOverride = &freedom.DestinationOverride{
			Server: &protocol.ServerEndpoint{
				Address: v2net.NewIPOrDomain(v2net.ParseAddress(host)),
				Port:    uint32(port),
			},
		}
	}
	return serial.ToTypedMessage(config), nil
}