// NewProxier returns a new Proxier
487515
func NewProxier(
	syncPeriod time.Duration,
	minSyncPeriod time.Duration,
	masqueradeAll bool,
	masqueradeBit int,
	clusterCIDR string,
	hostname string,
	nodeIP net.IP,
	recorder record.EventRecorder,
	healthzServer healthcheck.HealthzUpdater,
	config config.KubeProxyWinkernelConfiguration,
) (*Proxier, error) {
	masqueradeValue := 1 << uint(masqueradeBit)
	masqueradeMark := fmt.Sprintf("%#08x/%#08x", masqueradeValue, masqueradeValue)

	if nodeIP == nil {
		klog.Warningf("invalid nodeIP, initializing kube-proxy with 127.0.0.1 as nodeIP")
		nodeIP = net.ParseIP("127.0.0.1")
	}

	if len(clusterCIDR) == 0 {
		klog.Warningf("clusterCIDR not specified, unable to distinguish between internal and external traffic")
	}

	healthChecker := healthcheck.NewServer(hostname, recorder, nil, nil) // use default implementations of deps
	var hns HostNetworkService
	hns = hnsV1{}
	supportedFeatures := hcn.GetSupportedFeatures()
	if supportedFeatures.RemoteSubnet {
		hns = hnsV2{}
	}

	hnsNetworkName := config.NetworkName
	if len(hnsNetworkName) == 0 {
		klog.V(3).Infof("network-name flag not set. Checking environment variable")
		hnsNetworkName = os.Getenv("KUBE_NETWORK")
		if len(hnsNetworkName) == 0 {
			return nil, fmt.Errorf("Environment variable KUBE_NETWORK and network-flag not initialized")
		}
	}

	hnsNetworkInfo, err := hns.getNetworkByName(hnsNetworkName)
	if err != nil {
		klog.Errorf("Unable to find Hns Network specified by %s. Please check environment variable KUBE_NETWORK or network-name flag", hnsNetworkName)
		return nil, err
	}
	klog.V(1).Infof("Hns Network loaded with info = %v", hnsNetworkInfo)
	isDSR := config.EnableDSR
	if isDSR && !utilfeature.DefaultFeatureGate.Enabled(genericfeatures.WinDSR) {
		return nil, fmt.Errorf("WinDSR feature gate not enabled")
	}
	err = hcn.DSRSupported()
	if isDSR && err != nil {
		return nil, err
	}

	var sourceVip string
	var hostMac string
	if hnsNetworkInfo.networkType == "Overlay" {
		if !utilfeature.DefaultFeatureGate.Enabled(genericfeatures.WinOverlay) {
			return nil, fmt.Errorf("WinOverlay feature gate not enabled")
		}
		err = hcn.RemoteSubnetSupported()
		if err != nil {
			return nil, err
		}
		sourceVip = config.SourceVip
		if len(sourceVip) == 0 {
			return nil, fmt.Errorf("source-vip flag not set")
		}

		interfaces, _ := net.Interfaces() //TODO create interfaces
		for _, inter := range interfaces {
			addresses, _ := inter.Addrs()
			for _, addr := range addresses {
				addrIP, _, _ := net.ParseCIDR(addr.String())
				if addrIP.String() == nodeIP.String() {
					klog.V(2).Infof("Host MAC address is %s", inter.HardwareAddr.String())
					hostMac = inter.HardwareAddr.String()
				}
			}
		}
		if len(hostMac) == 0 {
			return nil, fmt.Errorf("Could not find host mac address for %s", nodeIP)
		}

		existingSourceVip, _ := hns.getEndpointByIpAddress(sourceVip, hnsNetworkName)
		if existingSourceVip == nil {
			hnsEndpoint := &endpointsInfo{
				ip:              sourceVip,
				isLocal:         true,
				macAddress:      hostMac,
				providerAddress: nodeIP.String(),
			}
			_, err = hns.createEndpoint(hnsEndpoint, hnsNetworkName)
			if err != nil {
				return nil, fmt.Errorf("Source Vip endpoint creation failed: %v", err)
			}
		}
	}

	proxier := &Proxier{
		portsMap:         make(map[localPort]closeable),
		serviceMap:       make(proxyServiceMap),
		serviceChanges:   newServiceChangeMap(),
		endpointsMap:     make(proxyEndpointsMap),
		endpointsChanges: newEndpointsChangeMap(hostname),
		masqueradeAll:    masqueradeAll,
		masqueradeMark:   masqueradeMark,
		clusterCIDR:      clusterCIDR,
		hostname:         hostname,
		nodeIP:           nodeIP,
		recorder:         recorder,
		healthChecker:    healthChecker,
		healthzServer:    healthzServer,
		hns:              hns,
		network:          *hnsNetworkInfo,
		sourceVip:        sourceVip,
		hostMac:          hostMac,
		isDSR:            isDSR,
	}

	burstSyncs := 2
	klog.V(3).Infof("minSyncPeriod: %v, syncPeriod: %v, burstSyncs: %d", minSyncPeriod, syncPeriod, burstSyncs)
	proxier.syncRunner = async.NewBoundedFrequencyRunner("sync-runner", proxier.syncProxyRules, minSyncPeriod, syncPeriod, burstSyncs)
	return proxier, nil

}
548412
func NewForwarder(s *stack.Stack, handler func(*ForwarderRequest)) *Forwarder {
	return &Forwarder{
		stack:   s,
		handler: handler,
	}
}
1168498
func NewProfiler() (prof *Profiler, err error) {
	p, err := freq.NewProfiler()
	if err != nil {
		return nil, err
	}
	return &Profiler{Profiler: p}, nil
}
710505
func NewProxyQueryService(queryController *pcontrol.Controller) query.ProxyQueryService {
	return query.ProxyQueryServiceAsyncBridge{
		AsyncQueryService: queryController,
	}
}
221877
func NewProfiler() (prof *Profiler, err error) {
	p, err := mem.NewProfiler()
	if err != nil {
		return nil, err
	}
	return &Profiler{Profiler: p}, nil
}
599453
func CreateNewProxyLB(name string) *ProxyLB {
	return &ProxyLB{
		Resource: &Resource{},
		propName: propName{Name: name},
		Provider: ProxyLBProvider{
			Class: "proxylb",
		},
		Settings: ProxyLBSettings{
			ProxyLB: ProxyLBSetting{
				HealthCheck: defaultProxyLBHealthCheck,
				SorryServer: ProxyLBSorryServer{},
				Servers:     []ProxyLBServer{},
			},
		},
	}
}
179323
func NewProvider() environs.CloudEnvironProvider {
	configReader := lxcConfigReader{}
	factory := NewServerFactory()
	credentials := environProviderCredentials{
		certReadWriter:  certificateReadWriter{},
		certGenerator:   certificateGenerator{},
		lookup:          netLookup{},
		serverFactory:   factory,
		lxcConfigReader: configReader,
	}
	return &environProvider{
		ProviderCredentials:         credentials,
		RequestFinalizeCredential:   credentials,
		ProviderCredentialsRegister: credentials,
		serverFactory:               factory,
		lxcConfigReader:             configReader,
	}
}
203834
func NewProfiler() (prof *Profiler, err error) {
	proc, err := joe.NewProc(procFile)
	if err != nil {
		return nil, err
	}
	cpuProf := cpux.NewProfiler()
	nodeProf := node.NewProfiler()
	return &Profiler{Procer: proc, Buffer: joe.NewBuffer(), CPUProf: cpuProf, NodeProf: nodeProf}, nil
}
493615
func NewProfiler() (p *Profiler, err error) {
	prof, err := procs.NewProfiler()
	if err != nil {
		return nil, err
	}
	return &Profiler{Profiler: prof}, nil
}
583192
func newProber(s *Server, nodes nodeMap) *prober {
	prober := &prober{
		Pinger:       fastping.NewPinger(),
		server:       s,
		done:         make(chan bool),
		proberExited: make(chan bool),
		stop:         make(chan bool),
		results:      make(map[ipString]*models.PathStatus),
		nodes:        make(nodeMap),
	}
	prober.MaxRTT = s.ProbeDeadline

	prober.setNodes(nodes)
	prober.OnRecv = func(addr *net.IPAddr, rtt time.Duration) {
		prober.Lock()
		defer prober.Unlock()
		node, exists := prober.nodes[ipString(addr.String())]

		scopedLog := log.WithFields(logrus.Fields{
			logfields.IPAddr: addr,
			"rtt":            rtt,
		})
		if !exists {
			scopedLog.Debugf("Node disappeared, skip result")
			return
		}

		prober.results[ipString(addr.String())].Icmp = &models.ConnectivityStatus{
			Latency: rtt.Nanoseconds(),
			Status:  "",
		}
		scopedLog.WithFields(logrus.Fields{
			logfields.NodeName: node.Name,
		}).Debugf("Probe successful")
	}

	return prober
}
735018
func NewReporter(reporter metrics.ProxyReporter, logger logger.Logger) negroni.Handler {
	return &reporterHandler{
		reporter: reporter,
		logger:   logger,
	}
}
1216309
func NewProver(policyChecker PolicyChecker, signingIdentity SignerIdentity) (*Prover, error) {
	responseMarshaler, err := NewResponseMarshaler(signingIdentity)
	if err != nil {
		return nil, err
	}

	return &Prover{
		Marshaler:     responseMarshaler,
		PolicyChecker: policyChecker,
		TMSManager: &Manager{
			LedgerManager: &PeerLedgerManager{},
		},
	}, nil
}
873096
func NewProxyQueryHandler() *ProxyQueryHandler {
	h := &ProxyQueryHandler{
		Router: NewRouter(),
	}

	h.HandlerFunc("POST", proxyQueryPath, h.handlePostQuery)
	return h
}
639597
func NewDNSProvider() (*DNSProvider, error) {
	values, err := env.Get("HTTPREQ_ENDPOINT")
	if err != nil {
		return nil, fmt.Errorf("httpreq: %v", err)
	}

	endpoint, err := url.Parse(values["HTTPREQ_ENDPOINT"])
	if err != nil {
		return nil, fmt.Errorf("httpreq: %v", err)
	}

	config := NewDefaultConfig()
	config.Mode = os.Getenv("HTTPREQ_MODE")
	config.Username = os.Getenv("HTTPREQ_USERNAME")
	config.Password = os.Getenv("HTTPREQ_PASSWORD")
	config.Endpoint = endpoint
	return NewDNSProviderConfig(config)
}
1101438
func NewProxyServer(filebase string, apiProxyPrefix string, staticPrefix string, filter *FilterServer, cfg *client.Config) (*ProxyServer, error) {
	host := cfg.Host
	if !strings.HasSuffix(host, "/") {
		host = host + "/"
	}
	target, err := url.Parse(host)
	if err != nil {
		return nil, err
	}
	proxy := newProxy(target)
	if proxy.Transport, err = client.TransportFor(cfg); err != nil {
		return nil, err
	}
	proxyServer := http.Handler(proxy)
	if filter != nil {
		proxyServer = filter.HandlerFor(proxyServer)
	}

	if !strings.HasPrefix(apiProxyPrefix, "/api") {
		proxyServer = stripLeaveSlash(apiProxyPrefix, proxyServer)
	}

	mux := http.NewServeMux()
	mux.Handle(apiProxyPrefix, proxyServer)
	if filebase != "" {
		// Require user to explicitly request this behavior rather than
		// serving their working directory by default.
		mux.Handle(staticPrefix, newFileHandler(staticPrefix, filebase))
	}
	return &ProxyServer{handler: mux}, nil
}
822964
func (client *Client) CreateProxy(name, listen, upstream string) (*Proxy, error) {
	proxy := &Proxy{
		Name:     name,
		Listen:   listen,
		Upstream: upstream,
		Enabled:  true,
		client:   client,
	}

	err := proxy.Save()
	if err != nil {
		return nil, err
	}

	return proxy, nil
}
966154
func NewProvider(conf *Conf, indexConfig *blkstorage.IndexConfig) blkstorage.BlockStoreProvider {
	p := leveldbhelper.NewProvider(&leveldbhelper.Conf{DBPath: conf.getIndexDir()})
	return &FsBlockstoreProvider{conf, indexConfig, p}
}