internal

package
v1.16.105 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPipeClosed = errors.New("pipe listener has been closed")

ErrPipeClosed is returned when calling Accept or DialContext on a closed PipeListener.

Functions

This section is empty.

Types

type ALPNWrapper

type ALPNWrapper func(dc, nodeName, alpnProto string, conn net.Conn) (net.Conn, error)

ALPNWrapper is a function that is used to wrap a non-TLS connection and returns an appropriate TLS connection or error. This taks a datacenter and node name as argument to configure the desired SNI value and the desired next proto for configuring ALPN.

type ClientConnPool

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

ClientConnPool creates and stores a connection for each datacenter.

func NewClientConnPool

func NewClientConnPool(cfg ClientConnPoolConfig) *ClientConnPool

NewClientConnPool create new GRPC client pool to connect to servers using GRPC over RPC.

func (*ClientConnPool) ClientConn

func (c *ClientConnPool) ClientConn(datacenter string) (*grpc.ClientConn, error)

ClientConn returns a grpc.ClientConn for the datacenter. If there are no existing connections in the pool, a new one will be created, stored in the pool, then returned.

func (*ClientConnPool) ClientConnLeader

func (c *ClientConnPool) ClientConnLeader() (*grpc.ClientConn, error)

TODO: godoc

func (*ClientConnPool) SetGatewayResolver

func (c *ClientConnPool) SetGatewayResolver(gatewayResolver func(string) string)

SetGatewayResolver is only to be called during setup before the pool is used.

type ClientConnPoolConfig

type ClientConnPoolConfig struct {
	// Servers is a reference for how to figure out how to dial any server.
	Servers ServerLocator

	// SrcAddr is the source address for outgoing connections.
	SrcAddr *net.TCPAddr

	// TLSWrapper is the specifics of wrapping a socket when doing an TYPE_BYTE+TLS
	// wrapped RPC request.
	TLSWrapper TLSWrapper

	// ALPNWrapper is the specifics of wrapping a socket when doing an ALPN+TLS
	// wrapped RPC request (typically only for wan federation via mesh
	// gateways).
	ALPNWrapper ALPNWrapper

	// UseTLSForDC is a function to determine if dialing a given datacenter
	// should use TLS.
	UseTLSForDC func(dc string) bool

	// DialingFromServer should be set to true if this connection pool is owned
	// by a consul server instance.
	DialingFromServer bool

	// DialingFromDatacenter is the datacenter of the consul agent using this
	// pool.
	DialingFromDatacenter string
}

type Handler

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

Handler implements a handler for the rpc server listener, and the agent.Component interface for managing the lifecycle of the grpc.Server.

func NewHandler

func NewHandler(logger Logger, addr net.Addr, register func(server *grpc.Server), metricsObj *metrics.Metrics, rateLimiter rate.RequestLimitsHandler) *Handler

NewHandler returns a gRPC server that accepts connections from Handle(conn). The register function will be called with the grpc.Server to register gRPC services with the server.

func (*Handler) Handle

func (h *Handler) Handle(conn net.Conn)

Handle the connection by sending it to a channel for the grpc.Server to receive.

func (*Handler) Run

func (h *Handler) Run() error

func (*Handler) Shutdown

func (h *Handler) Shutdown() error

type Listener

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

Listener implements the net.Listener interface and allows you to manually pass connections to it. This is useful when you need to accept connections and do something with them yourself first (e.g. handling our multiplexing scheme) before giving them to the gRPC server.

func NewListener

func NewListener(addr net.Addr) *Listener

NewListener creates a Listener with the given address.

func (*Listener) Accept

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

Accept a connection.

func (*Listener) Addr

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

Addr returns the listener's address.

func (*Listener) Close

func (l *Listener) Close() error

Close the listener.

func (*Listener) Handle

func (l *Listener) Handle(conn net.Conn)

Handle makes the given connection available to Accept.

type Logger

type Logger interface {
	Error(string, ...interface{})
	Warn(string, ...interface{})
}

type NoOpHandler

type NoOpHandler struct {
	Logger Logger
}

NoOpHandler implements the same methods as Handler, but performs no handling. It may be used in place of Handler to disable the grpc server.

func (NoOpHandler) Handle

func (h NoOpHandler) Handle(conn net.Conn)

func (NoOpHandler) Run

func (h NoOpHandler) Run() error

func (NoOpHandler) Shutdown

func (h NoOpHandler) Shutdown() error

type PipeListener

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

PipeListener implements the net.Listener interface using a net.Pipe so that you can interact with a gRPC service in the same process without going over the network.

func NewPipeListener

func NewPipeListener() *PipeListener

NewPipeListener creates a new PipeListener.

func (*PipeListener) Accept

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

Accept a connection.

func (*PipeListener) Addr

func (*PipeListener) Addr() net.Addr

Add returns the listener's address.

func (*PipeListener) Close

func (p *PipeListener) Close() error

Close the listener.

func (*PipeListener) DialContext

func (p *PipeListener) DialContext(ctx context.Context, _ string) (net.Conn, error)

DialContext dials the server over an in-process pipe.

type ServerLocator

type ServerLocator interface {
	// ServerForGlobalAddr returns server metadata for a server with the specified globally unique address.
	ServerForGlobalAddr(globalAddr string) (*metadata.Server, error)

	// Authority returns the target authority to use to dial the server. This is primarily
	// needed for testing multiple agents in parallel, because gRPC requires the
	// resolver to be registered globally.
	Authority() string
}

type TLSWrapper

type TLSWrapper func(dc string, conn net.Conn) (net.Conn, error)

TLSWrapper wraps a non-TLS connection and returns a connection with TLS enabled.

type Tracker

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

Tracker satisfies the ServerTracker interface the router manager uses to register/deregister servers and trigger rebalances.

func NewTracker

NewTracker returns an implementation of the router.ServerTracker interface backed by the given ServerResolverBuilder and Balancer.

func (*Tracker) AddServer

func (t *Tracker) AddServer(a types.AreaID, s *metadata.Server)

AddServer adds the given server to the resolver.

func (*Tracker) NewRebalancer

func (t *Tracker) NewRebalancer(dc string) func()

NewRebalancer returns a function that can be called to randomize the priority order of connections for the given datacenter.

func (*Tracker) RemoveServer

func (t *Tracker) RemoveServer(a types.AreaID, s *metadata.Server)

RemoveServer removes the given server from the resolver.

Directories

Path Synopsis
package balancer implements a custom gRPC load balancer.
package balancer implements a custom gRPC load balancer.
services

Jump to

Keyboard shortcuts

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