rpc

package
v0.0.0-...-b5d9cbe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Overview

Package rpc provides internal gRPC utilities.

Index

Constants

View Source
const MaxMessageSize = 1024 * 1024 * 8

MaxMessageSize is used to tell Tast's GRPC servers and clients the maximum size of messages.

Variables

This section is empty.

Functions

func NewPipeClientConn

func NewPipeClientConn(ctx context.Context, r io.Reader, w io.Writer, extraOpts ...grpc.DialOption) (*grpc.ClientConn, error)

NewPipeClientConn constructs ClientConn based on r and w.

The returned ClientConn is suitable for talking with a gRPC server over a bidirectional pipe.

func RunServer

func RunServer(r io.Reader, w io.Writer, svcs []*testing.Service, register func(srv *grpc.Server, req *protocol.HandshakeRequest) error) error

RunServer runs a gRPC server on r/w channels. register is called back to register core services. svcs is a list of user-defined gRPC services to be registered if the client requests them in HandshakeRequest. RunServer blocks until the client connection is closed or it encounters an error.

func RunTCPServer

func RunTCPServer(port int, handshakeReq *protocol.HandshakeRequest, stdin io.Reader, stdout, stderr io.Writer,
	svcs []*testing.Service, register func(srv *grpc.Server, req *protocol.HandshakeRequest) error) error

RunTCPServer runs a gRPC server listening on the specified port thought TCP Port contains the TCP port number where gRPC server listens to HandshakeRequest contains parameters needed to initialize a gRPC server. stdin is the linux standard input. stdout is the linux standard output. stderr is the linux standard error. svcs is the candidate list of user-defined gRPC services and they will be registered if GuaranteeCompatibility is set.

Types

type ExecClient

type ExecClient struct {
	// contains filtered or unexported fields
}

ExecClient is a Tast gRPC client over a locally executed subprocess.

func DialExec

func DialExec(ctx context.Context, path string, newSession bool, req *protocol.HandshakeRequest) (*ExecClient, error)

DialExec establishes a gRPC connection to an executable on host. If newSession is true, a new session is created for the subprocess and its descendants so that all of them are killed on closing Client.

func (*ExecClient) Close

func (c *ExecClient) Close() error

Close closes this client.

func (*ExecClient) Conn

func (c *ExecClient) Conn() *grpc.ClientConn

Conn returns a gRPC connection.

func (*ExecClient) PID

func (c *ExecClient) PID() int

PID returns PID of the subprocess.

type GenericClient

type GenericClient struct {
	// contains filtered or unexported fields
}

GenericClient is a Tast gRPC client.

func NewClient

func NewClient(ctx context.Context, r io.Reader, w io.Writer, req *protocol.HandshakeRequest, opts ...grpc.DialOption) (_ *GenericClient, retErr error)

NewClient establishes a gRPC connection to a test bundle executable using r and w. Callers are responsible for closing the underlying connection of r/w after the client is closed.

func (*GenericClient) Close

func (c *GenericClient) Close() error

Close closes this client.

func (*GenericClient) Conn

func (c *GenericClient) Conn() *grpc.ClientConn

Conn returns a gRPC connection.

type PipeListener

type PipeListener struct {
	// contains filtered or unexported fields
}

PipeListener is a pseudo net.Listener implementation based on io.Reader and io.Writer. PipeListener's Accept returns exactly one net.Conn that is based on the given io.Reader and io.Writer. When the connection is closed, Accept returns io.EOF.

PipeListener is suitable for running a gRPC server over a bidirectional pipe.

func NewPipeListener

func NewPipeListener(r io.Reader, w io.Writer) *PipeListener

NewPipeListener constructs a new PipeListener based on r and w.

func (*PipeListener) Accept

func (l *PipeListener) Accept() (net.Conn, error)

Accept returns a connection. See the comment of PipeListener for its behavior.

func (*PipeListener) Addr

func (l *PipeListener) Addr() net.Addr

Addr returns a fake IPv4 address.

func (*PipeListener) Close

func (l *PipeListener) Close() error

Close closes the listener.

type SSHClient

type SSHClient struct {
	// contains filtered or unexported fields
}

SSHClient is a Tast gRPC client over an SSH connection.

func DialSSH

func DialSSH(ctx context.Context, conn *ssh.Conn, path string, req *protocol.HandshakeRequest, proxy bool) (*SSHClient, error)

DialSSH establishes a gRPC connection to an executable on a remote machine. proxy if true indicates that HTTP proxy environment variables should be forwarded.

The context passed in must remain valid for as long as the gRPC connection. I.e. Don't use the context from within a testing.Poll function.

func (*SSHClient) Close

func (c *SSHClient) Close(opts ...ssh.RunOption) error

Close closes this client.

func (*SSHClient) Conn

func (c *SSHClient) Conn() *grpc.ClientConn

Conn returns a gRPC connection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL