grpcutil

package
v1.1.0-beta.0...-604b0d6 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ForwardMetadataKey is used to record the forwarded host of PD.
	ForwardMetadataKey = "pd-forwarded-host"
	// FollowerHandleMetadataKey is used to mark the permit of follower handle.
	FollowerHandleMetadataKey = "pd-allow-follower-handle"
)

Variables

This section is empty.

Functions

func BuildForwardContext

func BuildForwardContext(ctx context.Context, url string) context.Context

BuildForwardContext creates a context with receiver metadata information. It is used in client side.

func CheckStream

func CheckStream(ctx context.Context, cancel context.CancelFunc, done chan struct{})

CheckStream checks stream status, if stream is not created successfully in time, cancel context. TODO: If goroutine here timeout when tso stream created successfully, we need to handle it correctly.

func CreateClientConn

func CreateClientConn(ctx context.Context, addr string, tlsConfig *TLSConfig, do ...grpc.DialOption) *grpc.ClientConn

CreateClientConn creates a client connection to the given target.

func GetClientConn

func GetClientConn(ctx context.Context, addr string, tlsCfg *tls.Config, do ...grpc.DialOption) (*grpc.ClientConn, error)

GetClientConn returns a gRPC client connection. creates a client connection to the given target. By default, it's a non-blocking dial (the function won't wait for connections to be established, and connecting happens in the background). To make it a blocking dial, use WithBlock() dial option.

In the non-blocking case, the ctx does not act against the connection. It only controls the setup steps.

In the blocking case, ctx can be used to cancel or expire the pending connection. Once this function returns, the cancellation and expiration of ctx will be noop. Users should call ClientConn.Close to terminate all the pending operations after this function returns.

func GetForwardedHost

func GetForwardedHost(ctx context.Context) string

GetForwardedHost returns the forwarded host in metadata.

func IsFollowerHandleEnabled

func IsFollowerHandleEnabled(ctx context.Context) bool

IsFollowerHandleEnabled returns the follower host in metadata.

func NeedRebuildConnection

func NeedRebuildConnection(err error) bool

NeedRebuildConnection checks if the error is a connection error.

func ResetForwardContext

func ResetForwardContext(ctx context.Context) context.Context

ResetForwardContext is going to reset the forwarded host in metadata.

Types

type TLSConfig

type TLSConfig struct {
	// CAPath is the path of file that contains list of trusted SSL CAs. if set, following four settings shouldn't be empty
	CAPath string `toml:"cacert-path" json:"cacert-path"`
	// CertPath is the path of file that contains X509 certificate in PEM format.
	CertPath string `toml:"cert-path" json:"cert-path"`
	// KeyPath is the path of file that contains X509 key in PEM format.
	KeyPath string `toml:"key-path" json:"key-path"`
	// CertAllowedCNs is the list of CN which must be provided by a client
	CertAllowedCNs []string `toml:"cert-allowed-cn" json:"cert-allowed-cn"`

	SSLCABytes   []byte
	SSLCertBytes []byte
	SSLKEYBytes  []byte
}

TLSConfig is the configuration for supporting tls.

func (TLSConfig) ToTLSConfig

func (s TLSConfig) ToTLSConfig() (*tls.Config, error)

ToTLSConfig generates tls config.

func (TLSConfig) ToTLSInfo

func (s TLSConfig) ToTLSInfo() (*transport.TLSInfo, error)

ToTLSInfo converts TLSConfig to transport.TLSInfo.

Jump to

Keyboard shortcuts

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