Beispiel #1
0
// rpc is a helper function for performing RPC requests between nodes
func rpc(addr string, msg *rpcRequest, tlsConfig *tls.Config) (*rpcResponse, error) {
	conn, err := api.Dial(addr, api.RPCMessage, defaultTimeout, tlsConfig, true)
	if err != nil {
		return nil, err
	}

	if err := api.Encode(msg, conn); err != nil {
		return nil, err
	}

	var res rpcResponse
	if err := api.Decode(&res, conn); err != nil {
		return nil, err
	}
	return &res, nil
}
Beispiel #2
0
// rpcProxyRequest is a helper function to proxy an rpc request to another node
func rpcProxyRequest(addr string, msg *rpcRequest, from io.ReadWriter, tlsConfig *tls.Config) error {
	conn, err := api.Dial(addr, api.RPCMessage, defaultTimeout, tlsConfig, true)
	if err != nil {
		return err
	}
	if err := api.Encode(msg, conn); err != nil {
		return err
	}

	chErr := make(chan error, 2)
	go func() {
		_, err := io.Copy(from, conn)
		chErr <- err
	}()
	go func() {
		_, err := io.Copy(conn, from)
		chErr <- err
	}()

	if err := <-chErr; err != nil {
		return err
	}
	return <-chErr
}
Beispiel #3
0
// Dial is used by Raft for RPC
func (l *streamLayer) Dial(address string, timeout time.Duration) (net.Conn, error) {
	return api.Dial(address, l.rpcType, timeout, l.tlsConfig, false)
}
Beispiel #4
0
func (c *client) dial() (net.Conn, error) {
	return api.Dial(c.addr, api.ClientMessage, c.dialTimeout, c.tlsConfig, true)
}