// NewRPCClient exported
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

}
377525
func newXMPPClient(auth Auth) (*xmppClient, error) {
	addr := "talk.google.com:443"
	user := auth.XMPPJID
	if user == "" {
		user = auth.TokenUser
	}
	passwd := auth.Token.AccessToken
	host := addr

	a := strings.SplitN(host, ":", 2)
	if len(a) == 1 {
		host += ":5222"
	}
	proxy := os.Getenv("HTTP_PROXY")
	if proxy == "" {
		proxy = os.Getenv("http_proxy")
	}
	if proxy != "" {
		url, err := url.Parse(proxy)
		if err == nil {
			addr = url.Host
		}
	}
	c, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	if proxy != "" {
		fmt.Fprintf(c, "CONNECT %s HTTP/1.1\r\n", host)
		fmt.Fprintf(c, "Host: %s\r\n", host)
		fmt.Fprintf(c, "\r\n")
		br := bufio.NewReader(c)
		req, _ := http.NewRequest("CONNECT", host, nil)
		resp, err := http.ReadResponse(br, req)
		if err != nil {
			return nil, err
		}
		if resp.StatusCode != 200 {
			f := strings.SplitN(resp.Status, " ", 2)
			return nil, errors.New(f[1])
		}
	}

	tlsconn := tls.Client(c, &defaultConfig)
	if err = tlsconn.Handshake(); err != nil {
		return nil, err
	}

	if strings.LastIndex(host, ":") > 0 {
		host = host[:strings.LastIndex(host, ":")]
	}
	if err = tlsconn.VerifyHostname(host); err != nil {
		return nil, err
	}

	client := new(xmppClient)
	client.tls = tlsconn
	if err := client.init(user, passwd); err != nil {
		client.Close()
		return nil, err
	}
	return client, nil
}
795256
func New(addr string) (VtctlClient, error) {
	factory, ok := factories[*vtctlClientProtocol]
	if !ok {
		return nil, fmt.Errorf("unknown vtctl client protocol: %v", *vtctlClientProtocol)
	}
	return factory(addr)
}
167593
func NewRPCRequest(id string, method string, params json.RawMessage) *RPCRequest {
	return &RPCRequest{
		JSONRPC: "2.0",
		Id:      id,
		Method:  method,
		Params:  params,
	}
}
946906
func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) {
	return nil, errNotSupported
}
1243079
func NewPublisherGrpcClient(address string, timeout time.Duration, security GRPCSecurity) (PluginPublisherClient, error) {
	ctx := context.Background()
	p, err := newPluginGrpcClient(ctx, address, timeout, security, plugin.PublisherPluginType)
	if err != nil {
		return nil, err
	}
	return p.(PluginPublisherClient), err
}
1085698
func NewEthRPC(url string, options ...func(rpc *EthRPC)) *EthRPC {
	return New(url, options...)
}
1061002
func NewFxHelloYARPCClient(name string, options ...protobuf.ClientOption) interface{} {
	return func(params FxHelloYARPCClientParams) FxHelloYARPCClientResult {
		return FxHelloYARPCClientResult{
			Client: NewHelloYARPCClient(params.Provider.ClientConfig(name), options...),
		}
	}
}
245094
func NewAgentClient(addr, port string, creds *Credentials) *Client {
	return &Client{
		addr:        addr,
		port:        port,
		useAgent:    true,
		credentials: creds,
	}
}
249215
func NewRPCErrorResponse(id string, code int, message string) RPCResponse {
	return RPCResponse(&RPCErrorResponse{
		Error:   &RPCError{code, message},
		Id:      id,
		JSONRPC: "2.0",
	})
}
783900
func NewDebugClient(cr statscollector.Collector) (DebugClient, error) {
	d := &debugClient{
		collector:     cr,
		rpchdl:        rpcwrapper.NewRPCWrapper(),
		secret:        os.Getenv(constants.EnvStatsSecret),
		debugChannel:  os.Getenv(constants.EnvStatsChannel),
		debugInterval: defaultDebugIntervalMilliseconds * time.Millisecond,
		stop:          make(chan bool),
	}

	if d.debugChannel == "" {
		return nil, errors.New("no path to debug socket provided")
	}

	if d.secret == "" {
		return nil, errors.New("no secret provided for debug channel")
	}

	return d, nil
}
123623
func NewClient() (*Client, error) {
	osdbServer := os.Getenv("OSDB_SERVER")
	if osdbServer == "" {
		osdbServer = DefaultOSDBServer
	}
	rpc, err := xmlrpc.NewClient(osdbServer, nil)
	if err != nil {
		return nil, err
	}

	c := &Client{
		UserAgent: DefaultUserAgent,
		Client:    rpc, // xmlrpc.Client
	}

	return c, nil
}
386541
func newClient(addr string, max int, discardClientTimeout time.Duration, fn connectRPCFn) (Client, error) {

	rpcClientFactory := func() (interface{}, error) {
		return fn(addr)
	}
	rpcPool, err := pool.NewPool(max, rpcClientFactory)
	if err != nil {
		return nil, err
	}
	rc := &reconnectingClient{addr: addr, pool: rpcPool, discardClientTimeout: discardClientTimeout}
	return rc, nil
}
561701
func NewRPCError(code RPCErrorCode, message string) *RPCError {
	return &RPCError{
		Code:    code,
		Message: message,
	}
}
847591
func NewClient(parseAppID string, RESTAPIKey string) (*Client, error) {
	return &Client{appID: parseAppID, restApiKey: RESTAPIKey}, nil
}
1241505
func (mr *MockRPCClientMockRecorder) NewRPCClient(contextID, channel, rpcSecret interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewRPCClient", reflect.TypeOf((*MockRPCClient)(nil).NewRPCClient), contextID, channel, rpcSecret)
}
1289472
func (m *testRPC) GetRPCClient(contextID string) (*RPCHdl, error) {
	if mock := m.currentMocks(nil); mock != nil && mock.GetRPCClientMock != nil {
		return mock.GetRPCClientMock(contextID)
	}
	return nil, nil
}