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