func createConfig(config *Config) (*proxy.Config, error) {
	listenIP := net.ParseIP(config.ListenAddr)
	if listenIP == nil {
		return nil, fmt.Errorf("cannot parse %s", config.ListenAddr)
	}
	timeout := time.Duration(config.Timeout) * time.Millisecond

	// Init listen addresses and upstreams
	listenUDPAddr := &net.UDPAddr{Port: config.ListenPort, IP: listenIP}
	listenTCPAddr := &net.TCPAddr{Port: config.ListenPort, IP: listenIP}
	upstreams := make([]upstream.Upstream, 0)

	// Check bootstraps list for empty strings
	bootstrapLines := strings.Split(config.BootstrapDNS, "\n")
	var bootstraps []string
	for _, line := range bootstrapLines {
		if line == "" {
			continue
		}

		bootstraps = append(bootstraps, line)
	}

	lines := strings.Split(config.Upstreams, "\n")

	for i, line := range lines {
		if line == "" {
			continue
		}

		dnsUpstream, err := upstream.AddressToUpstream(line, upstream.Options{Bootstrap: bootstraps, Timeout: timeout})
		if err != nil {
			return nil, fmt.Errorf("cannot prepare the upstream %s (%s): %s", line, config.BootstrapDNS, err)
		}
		log.Printf("Upstream %d: %s", i, dnsUpstream.Address())
		upstreams = append(upstreams, dnsUpstream)
	}

	// Create the config
	proxyConfig := proxy.Config{
		UDPListenAddr: listenUDPAddr,
		TCPListenAddr: listenTCPAddr,
		Upstreams:     upstreams,
		AllServers:    config.AllServers,
	}

	if config.Fallbacks != "" {
		fallbacks := []upstream.Upstream{}
		lines = strings.Split(config.Fallbacks, "\n")
		for i, line := range lines {
			if line == "" {
				continue
			}

			fallback, err := upstream.AddressToUpstream(line, upstream.Options{Timeout: timeout})
			if err != nil {
				return nil, fmt.Errorf("cannot parse the fallback %s (%s): %s", line, config.BootstrapDNS, err)
			}

			log.Printf("Fallback %d: %s", i, fallback.Address())
			fallbacks = append(fallbacks, fallback)
		}
		proxyConfig.Fallbacks = fallbacks
	}

	return &proxyConfig, nil
}
// createProxyConfig creates proxy.Config from mobile.Config values
createProxyConfig creates proxy.Config from mobile.Config values
// createProxyConfig creates proxy . Config from mobile . Config values
func createConfig(config *Config) (*proxy.Config, error) {
	listenIP := net.ParseIP(config.ListenAddr)
	if listenIP == nil {
		return nil, fmt.Errorf("cannot parse %s", config.ListenAddr)
	}
	timeout := time.Duration(config.Timeout) * time.Millisecond
	listenUDPAddr := &net.UDPAddr{Port: config.ListenPort, IP: listenIP}
	listenTCPAddr := &net.TCPAddr{Port: config.ListenPort, IP: listenIP}
	upstreams := make([]upstream.Upstream, 0)
	bootstrapLines := strings.Split(config.BootstrapDNS, "\n")
	var bootstraps []string
	for _, line := range bootstrapLines {
		if line == "" {
			continue
		}
		bootstraps = append(bootstraps, line)
	}
	lines := strings.Split(config.Upstreams, "\n")
	for i, line := range lines {
		if line == "" {
			continue
		}
		dnsUpstream, err := upstream.AddressToUpstream(line, upstream.Options{Bootstrap: bootstraps, Timeout: timeout})
		if err != nil {
			return nil, fmt.Errorf("cannot prepare the upstream %s (%s): %s", line, config.BootstrapDNS, err)
		}
		log.Printf("Upstream %d: %s", i, dnsUpstream.Address())
		upstreams = append(upstreams, dnsUpstream)
	}
	proxyConfig := proxy.Config{
		UDPListenAddr: listenUDPAddr,
		TCPListenAddr: listenTCPAddr,
		Upstreams:     upstreams,
		AllServers:    config.AllServers,
	}
	if config.Fallbacks != "" {
		fallbacks := []upstream.Upstream{}
		lines = strings.Split(config.Fallbacks, "\n")
		for i, line := range lines {
			if line == "" {
				continue
			}
			fallback, err := upstream.AddressToUpstream(line, upstream.Options{Timeout: timeout})
			if err != nil {
				return nil, fmt.Errorf("cannot parse the fallback %s (%s): %s", line, config.BootstrapDNS, err)
			}
			log.Printf("Fallback %d: %s", i, fallback.Address())
			fallbacks = append(fallbacks, fallback)
		}
		proxyConfig.Fallbacks = fallbacks
	}
	return &proxyConfig, nil
}
func createConfig ( config * Config ) ( * proxy . Config , error ) { listenIP := net . ParseIP ( config . ListenAddr ) if listenIP == nil { return nil , fmt . Errorf ( " " , config . ListenAddr ) } timeout := time . Duration ( config . Timeout ) * time . Millisecond listenUDPAddr := & net . UDPAddr { Port : config . ListenPort , IP : listenIP } listenTCPAddr := & net . TCPAddr { Port : config . ListenPort , IP : listenIP } upstreams := make ( [ ] upstream . Upstream , 0 ) bootstrapLines := strings . Split ( config . BootstrapDNS , " \n " ) var bootstraps [ ] string for _ , line := range bootstrapLines { if line == " " { continue } bootstraps = append ( bootstraps , line ) } lines := strings . Split ( config . Upstreams , " \n " ) for i , line := range lines { if line == " " { continue } dnsUpstream , err := upstream . AddressToUpstream ( line , upstream . Options { Bootstrap : bootstraps , Timeout : timeout } ) if err != nil { return nil , fmt . Errorf ( " " , line , config . BootstrapDNS , err ) } log . Printf ( " " , i , dnsUpstream . Address ( ) ) upstreams = append ( upstreams , dnsUpstream ) } proxyConfig := proxy . Config { UDPListenAddr : listenUDPAddr , TCPListenAddr : listenTCPAddr , Upstreams : upstreams , AllServers : config . AllServers , } if config . Fallbacks != " " { fallbacks := [ ] upstream . Upstream { } lines = strings . Split ( config . Fallbacks , " \n " ) for i , line := range lines { if line == " " { continue } fallback , err := upstream . AddressToUpstream ( line , upstream . Options { Timeout : timeout } ) if err != nil { return nil , fmt . Errorf ( " " , line , config . BootstrapDNS , err ) } log . Printf ( " " , i , fallback . Address ( ) ) fallbacks = append ( fallbacks , fallback ) } proxyConfig . Fallbacks = fallbacks } return & proxyConfig , nil }
createProxyConfig creates proxy.Config from mobile.Config values
createProxyConfig creates proxy . Config from mobile . Config values
// Init listen addresses and upstreams // Check bootstraps list for empty strings // Create the config