grpcmux

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCClientMuxer

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

GRPCClientMuxer implements the client (host) side of the gRPC broker's GRPCMuxer interface for multiplexing multiple gRPC broker connections over a single net.Conn.

The client dials the initial net.Conn eagerly, and creates a yamux.Session as the implementation for multiplexing any additional connections.

Each net.Listener returned from Listener will block until the client receives a knock that matches its gRPC broker stream ID. There is no default listener on the client, as it is a client for the gRPC broker's control services. (See GRPCServerMuxer for more details).

func NewGRPCClientMuxer

func NewGRPCClientMuxer(logger hclog.Logger, addr net.Addr) (*GRPCClientMuxer, error)

func (*GRPCClientMuxer) AcceptKnock

func (m *GRPCClientMuxer) AcceptKnock(id uint32) error

func (*GRPCClientMuxer) Close

func (m *GRPCClientMuxer) Close() error

func (*GRPCClientMuxer) Dial

func (m *GRPCClientMuxer) Dial() (net.Conn, error)

func (*GRPCClientMuxer) Enabled

func (m *GRPCClientMuxer) Enabled() bool

func (*GRPCClientMuxer) Listener

func (m *GRPCClientMuxer) Listener(id uint32, doneCh <-chan struct{}) (net.Listener, error)

type GRPCMuxer

type GRPCMuxer interface {
	// Enabled determines whether multiplexing should be used. It saves users
	// of the interface from having to compare an interface with nil, which
	// is a bit awkward to do correctly.
	Enabled() bool

	// Listener returns a multiplexed listener that will wait until AcceptKnock
	// is called with a matching ID before its Accept function returns.
	Listener(id uint32, doneCh <-chan struct{}) (net.Listener, error)

	// AcceptKnock unblocks the listener with the matching ID, and returns an
	// error if it hasn't been created yet.
	AcceptKnock(id uint32) error

	// Dial makes a new multiplexed client connection. To dial a specific ID,
	// a knock must be sent first.
	Dial() (net.Conn, error)

	// Close closes connections and releases any resources associated with the
	// muxer.
	Close() error
}

GRPCMuxer enables multiple implementations of net.Listener to accept connections over a single "main" multiplexed net.Conn, and dial multiple client connections over the same multiplexed net.Conn.

The first multiplexed connection is used to serve the gRPC broker's own control services: plugin.GRPCBroker, plugin.GRPCController, plugin.GRPCStdio.

Clients must "knock" before dialling, to tell the server side that the next net.Conn should be accepted onto a specific stream ID. The knock is a bidirectional streaming message on the plugin.GRPCBroker service.

type GRPCServerMuxer

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

GRPCServerMuxer implements the server (plugin) side of the gRPC broker's GRPCMuxer interface for multiplexing multiple gRPC broker connections over a single net.Conn.

The server side needs a listener to serve the gRPC broker's control services, which includes the service we will receive knocks on. That means we always accept the first connection onto a "default" main listener, and if we accept any further connections without receiving a knock first, they are also given to the default listener.

When creating additional multiplexed listeners for specific stream IDs, we can't control the order in which gRPC servers will call Accept() on each listener, but we do need to control which gRPC server accepts which connection. As such, each multiplexed listener blocks waiting on a channel. It will be unblocked when a knock is received for the matching stream ID.

func NewGRPCServerMuxer

func NewGRPCServerMuxer(logger hclog.Logger, ln net.Listener) *GRPCServerMuxer

func (*GRPCServerMuxer) Accept

func (m *GRPCServerMuxer) Accept() (net.Conn, error)

Accept accepts all incoming connections and routes them to the correct stream ID based on the most recent knock received.

func (*GRPCServerMuxer) AcceptKnock

func (m *GRPCServerMuxer) AcceptKnock(id uint32) error

func (*GRPCServerMuxer) Addr

func (m *GRPCServerMuxer) Addr() net.Addr

func (*GRPCServerMuxer) Close

func (m *GRPCServerMuxer) Close() error

func (*GRPCServerMuxer) Dial

func (m *GRPCServerMuxer) Dial() (net.Conn, error)

func (*GRPCServerMuxer) Enabled

func (m *GRPCServerMuxer) Enabled() bool

func (*GRPCServerMuxer) Listener

func (m *GRPCServerMuxer) Listener(id uint32, doneCh <-chan struct{}) (net.Listener, error)

Jump to

Keyboard shortcuts

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