// NewRPCClient gets a new client.
423231
func NewRPCClient(storePath, certsDir string) libmachine.API {
	c := libmachine.NewClient(storePath, certsDir)
	c.SSHClientType = ssh.Native
	return c
}
508735
func (r *RPCWrapper) NewRPCClient(contextID string, channel string, sharedsecret string) error {

	r.Lock()
	defer r.Unlock()

	max := maxRetries
	retries := os.Getenv(envRetryString)
	if len(retries) > 0 {
		max, _ = strconv.Atoi(retries)
	}

	numRetries := 0
	client, err := rpc.DialHTTP("unix", channel)
	for err != nil {
		numRetries++
		if numRetries >= max {
			return err
		}

		time.Sleep(5 * time.Millisecond)
		client, err = rpc.DialHTTP("unix", channel)
	}

	r.rpcClientMap.AddOrUpdate(contextID, &RPCHdl{Client: client, Channel: channel, Secret: sharedsecret})

	return nil

}
791883
func NewClient(addr string, opt *ClientOpt) (*grpc.ClientConn, error) {

	if opt == nil {
		return nil, fmt.Errorf("Empty ClientOpt")
	}

	// Load key pair
	certificate, err := tls.LoadX509KeyPair(opt.Crt, opt.Key)
	if err != nil {
		return nil, err
	}

	tlsConf := &tls.Config{
		ServerName:         opt.ServerName,
		Certificates:       []tls.Certificate{certificate},
		InsecureSkipVerify: opt.InsecureSkipVerify,
	}

	// Mutual handshake with private ca
	if opt.CaCrt != "" {
		certPool := x509.NewCertPool()
		bs, err := ioutil.ReadFile(opt.CaCrt)
		if err != nil {
			return nil, err
		}
		ok := certPool.AppendCertsFromPEM(bs)
		if !ok {
			return nil, fmt.Errorf("failed to append certs")
		}
		tlsConf.InsecureSkipVerify = false
		tlsConf.RootCAs = certPool
	}

	dailOpts := []grpc.DialOption{
		grpc.WithTransportCredentials(credentials.NewTLS(tlsConf)),
	}

	if opt.WithBlock {
		dailOpts = append(dailOpts, grpc.WithBlock(), grpc.WithTimeout(5*time.Second))
	}

	// Dail and return connection
	conn, err := grpc.Dial(addr, dailOpts...)
	if err != nil {
		return nil, err
	}

	return conn, nil

}
245094
func NewAgentClient(addr, port string, creds *Credentials) *Client {
	return &Client{
		addr:        addr,
		port:        port,
		useAgent:    true,
		credentials: creds,
	}
}
627850
func (m *MockRPCClient) NewRPCClient(contextID, channel, rpcSecret string) error {
	ret := m.ctrl.Call(m, "NewRPCClient", contextID, channel, rpcSecret)
	ret0, _ := ret[0].(error)
	return ret0
}
53514
func NewAPIClient(datasetAPIURL, serviceToken, xDownloadServiceToken string) *Client {
	return &Client{
		cli: rchttp.ClientWithDownloadServiceToken(
			rchttp.ClientWithServiceToken(nil, serviceToken),
			xDownloadServiceToken,
		),
		url: datasetAPIURL,
	}
}
887613
func NewClient(h string, p int) Client {
	return Client{
		Host: h,
		Port: p,
	}
}
269325
func NewCollectorGrpcClient(address string, timeout time.Duration, security GRPCSecurity) (PluginCollectorClient, error) {
	ctx := context.Background()
	p, err := newPluginGrpcClient(ctx, address, timeout, security, plugin.CollectorPluginType)
	if err != nil {
		return nil, err
	}
	return p.(PluginCollectorClient), err
}
559543
func NewClient(host string, port int) (client *Client, err error) {
	client = new(Client)
	client.Host = host
	client.Port = port
	client.Connection, err = net.Dial("tcp", fmt.Sprintf("%v:%v", client.Host, client.Port))
	return
}
1052652
func NewPubControlClient(uri string) *PubControlClient {
    // This is basically the same as the default in Go 1.6, but with these changes:
    // Timeout: 30s -> 10s
    // TLSHandshakeTimeout: 10s -> 7s
    // MaxIdleConnsPerHost: 2 -> 100
    transport := &http.Transport{
        Proxy: http.ProxyFromEnvironment,
        Dial: (&net.Dialer{
            Timeout:   10 * time.Second,
            KeepAlive: 30 * time.Second,
        }).Dial,
        TLSHandshakeTimeout:   7 * time.Second,
        ExpectContinueTimeout: 1 * time.Second,
        MaxIdleConnsPerHost: 100,
    }

    newPcc := new(PubControlClient)
    newPcc.uri = uri
    newPcc.lock = &sync.Mutex{}
    newPcc.pubCall = pubCall
    newPcc.publish = publish
    newPcc.makeHttpRequest = makeHttpRequest
    newPcc.httpClient = &http.Client{Transport: transport, Timeout: 15 * time.Second}
    return newPcc
}
603182
func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) {
	// Create the yamux client so we can multiplex
	mux, err := yamux.Client(conn, nil)
	if err != nil {
		conn.Close()
		return nil, err
	}

	// Connect to the control stream.
	control, err := mux.Open()
	if err != nil {
		mux.Close()
		return nil, err
	}

	// Connect stdout, stderr streams
	stdstream := make([]net.Conn, 2)
	for i, _ := range stdstream {
		stdstream[i], err = mux.Open()
		if err != nil {
			mux.Close()
			return nil, err
		}
	}

	// Create the broker and start it up
	broker := newMuxBroker(mux)
	go broker.Run()

	// Build the client using our broker and control channel.
	return &RPCClient{
		broker:  broker,
		control: rpc.NewClient(control),
		plugins: plugins,
		stdout:  stdstream[0],
		stderr:  stdstream[1],
	}, nil
}
1238657
func NewAPIClient(client common.RCHTTPClienter, apiURL, serviceToken string) *Client {
	return &Client{
		client: rchttp.ClientWithServiceToken(client, serviceToken),
		url:    apiURL,
	}
}
848190
func newPeerRESTClient(peer *xnet.Host) (*peerRESTClient, error) {

	scheme := "http"
	if globalIsSSL {
		scheme = "https"
	}

	serverURL := &url.URL{
		Scheme: scheme,
		Host:   peer.String(),
		Path:   peerRESTPath,
	}

	var tlsConfig *tls.Config
	if globalIsSSL {
		tlsConfig = &tls.Config{
			ServerName: peer.Name,
			RootCAs:    globalRootCAs,
		}
	}

	restClient, err := rest.NewClient(serverURL, tlsConfig, rest.DefaultRESTTimeout, newAuthToken)

	if err != nil {
		return &peerRESTClient{host: peer, restClient: restClient, connected: false}, err
	}

	return &peerRESTClient{host: peer, restClient: restClient, connected: true}, nil
}
1251603
func NewPeerClientFromEnv() (*PeerClient, error) {
	address, override, clientConfig, err := configFromEnv("peer")
	if err != nil {
		return nil, errors.WithMessage(err, "failed to load config for PeerClient")
	}
	return newPeerClientForClientConfig(address, override, clientConfig)
}
589372
func NewClient(conn io.ReadWriteCloser) *rpc.Client {
	return rpc.NewClientWithCodec(NewClientCodec(conn))
}
109907
func newReconnectRPCClient(serverAddr, serviceEndpoint string) *ReconnectRPCClient {
	return &ReconnectRPCClient{
		serverAddr:      serverAddr,
		serviceEndpoint: serviceEndpoint,
	}
}
344045
func newPluginGrpcClient(ctx context.Context, address string, timeout time.Duration, security GRPCSecurity, typ plugin.PluginType) (interface{}, error) {
	address, port, err := parseAddress(address)
	if err != nil {
		return nil, err
	}
	var p *grpcClient
	var creds credentials.TransportCredentials
	if creds, err = buildCredentials(security); err != nil {
		return nil, err
	}
	p, err = newGrpcClient(ctx, address, int(port), timeout, typ, creds)
	if err != nil {
		return nil, err
	}
	return p, nil
}