grpcadapter

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyDialed = errors.New("connection already dialed")

Functions

func ForwardServerToClient

func ForwardServerToClient(ctx context.Context, params ForwardS2C) error

ForwardServerToClient forwards an incoming ServerStream to an outgoing ClientStream. It either returns an error when the forwarding process fails, or nil when the outgoing stream returns an io.EOF on Recv.

Types

type AdaptedClientConn

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

func AdaptClient

func AdaptClient(conn *grpc.ClientConn) *AdaptedClientConn

AdaptClient wraps an existing gRPC client with an adapter implementing ClientConn. The returned client is instantly ready to be used, and will be valid until *AdaptedClientConn.Close is called, after which any stream initiations via the client will return an error and the underlying gRPC client will be closed, too.

func (*AdaptedClientConn) Close

func (cc *AdaptedClientConn) Close()

Close marks this connection as closed and closes the underlying gRPC client. Calling Close concurrently won't cause issues, but why would you want to even do it...

func (*AdaptedClientConn) Stream

func (cc *AdaptedClientConn) Stream(ctx context.Context, method string) (ClientStream, error)

type AdaptedClientPool

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

func NewAdaptedClientPool

func NewAdaptedClientPool(opts AdaptedClientPoolOpts) *AdaptedClientPool

func (*AdaptedClientPool) Get

func (p *AdaptedClientPool) Get(target string) (ClientConn, bool)

func (*AdaptedClientPool) New

func (p *AdaptedClientPool) New(targetName, dialTarget string, opts ...grpc.DialOption) (*AdaptedClientPoolController, error)

New creates a new *AdaptedClientConn using grpc.NewClient or the NewClientFunc specified in AdaptedClientPoolOpts using the merged set of default options and the options passed to New. It returns a *AdaptedClientPoolController which can be used to close the connection and remove it from the pool.

It is an error to call New() with the same targetName multiple times on a single DialedPool instance, the previous *AdaptedClientPoolController must be explicitly used to close the connection before dialing a new one. Instead of trying to synchronize such procedures, however, it's better to have a properly defined lifecycle for each possible target, with clear logic about when it gets added or removed to/from all the components of a bridge.

type AdaptedClientPoolController

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

AdaptedClientPoolController wraps an AdaptedClientConn created using a DialedPool, providing methods to control the AdaptedClientConn's own and pool lifecycle.

func (*AdaptedClientPoolController) Close

func (pw *AdaptedClientPoolController) Close()

Close removes this connection from the pool and closes it. Calling close multiple times or concurrently will intentionally result in a panic to avoid bugs. TODO(renbou): implement graceful connection closure.

type AdaptedClientPoolOpts

type AdaptedClientPoolOpts struct {
	// NewClientFunc can be used to specify an alternative connection constructor to be used instead of [grpc.NewClient].
	NewClientFunc func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

	// DefaultOpts specify the default options to be used when creating a new client, by default no opts are used.
	DefaultOpts []grpc.DialOption
}

type AdaptedClientStream

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

func (*AdaptedClientStream) Close

func (s *AdaptedClientStream) Close()

func (*AdaptedClientStream) CloseSend

func (s *AdaptedClientStream) CloseSend()

func (*AdaptedClientStream) Recv

func (*AdaptedClientStream) Send

type ClientConn

type ClientConn interface {
	Stream(ctx context.Context, method string) (ClientStream, error)
	Close()
}

type ClientPool

type ClientPool interface {
	Get(target string) (ClientConn, bool)
}

type ClientStream

type ClientStream interface {
	Send(context.Context, proto.Message) error
	Recv(context.Context, proto.Message) error
	CloseSend()
	Close()
}

type ForwardS2C

type ForwardS2C struct {
	Incoming ServerStream
	Outgoing ClientStream
	Method   *bridgedesc.Method
}

type ServerStream

type ServerStream interface {
	Send(context.Context, proto.Message) error
	Recv(context.Context, proto.Message) error
}

Jump to

Keyboard shortcuts

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