示例#1
0
文件: rpc.go 项目: abronan/drax
// 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
}
示例#2
0
文件: rpc.go 项目: abronan/drax
// 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
}
示例#3
0
文件: rpc.go 项目: abronan/drax
// 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)
}
示例#4
0
文件: rpc.go 项目: abronan/drax
func (c *client) dial() (net.Conn, error) {
	return api.Dial(c.addr, api.ClientMessage, c.dialTimeout, c.tlsConfig, true)
}