grpc

package
v0.2103.9 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 37 Imported by: 17

Documentation

Overview

Package grpc implements common gRPC related services and utilities.

Index

Constants

View Source
const (
	// CfgLogDebug enables verbose gRPC debug output.
	CfgLogDebug = "grpc.log.debug"
)
View Source
const ServicePrefix = "oasis-core."

ServicePrefix is a prefix given to all gRPC services defined by oasis-core.

Variables

View Source
var ErrServiceClosed = errors.New("grpc/wrapper: received message for wrapped service with deregistered wrapper")

ErrServiceClosed is the error returned when the wrapper receives a message for a service whose interceptor has been removed.

View Source
var (
	// Flags has the flags used by the gRPC server.
	Flags = flag.NewFlagSet("", flag.ContinueOnError)
)

Functions

func AccessControlAlways added in v0.2100.0

func AccessControlAlways(ctx context.Context, req interface{}) (bool, error)

AccessControlAlways is a utility AccessControlFunc that enables access control for every request.

func Dial

func Dial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

Dial creates a client connection to the given target.

func GetErrorStatus added in v0.2100.0

func GetErrorStatus(err error) *status.Status

GetErrorStatus returns gRPC status from error.

func IsErrorCode added in v0.2010.0

func IsErrorCode(err error, code codes.Code) bool

IsErrorCode returns true if the given error represents a specific gRPC error code.

func NewClientCreds

func NewClientCreds(opts *ClientOptions) (credentials.TransportCredentials, error)

NewClientCreds creates new client TLS transport credentials.

func NewStreamWriter

func NewStreamWriter(stream grpc.ServerStream) io.Writer

NewStreamWriter wraps a server-side gRPC stream into an io.Writer interface so that a stream can be used as a writer. Each Write into such a strema will cause a message to be sent, encoded as a raw byte slice.

Types

type AccessControlFunc

type AccessControlFunc func(ctx context.Context, req interface{}) (bool, error)

AccessControlFunc is a function that decides whether access control policy lookup is required for a specific request. In case an error is returned the request is aborted.

type CBORCodec

type CBORCodec struct{}

CBORCodec implements gRPC's encoding.Codec interface.

func (*CBORCodec) Marshal

func (c *CBORCodec) Marshal(v interface{}) ([]byte, error)

func (*CBORCodec) Name

func (c *CBORCodec) Name() string

func (*CBORCodec) String

func (c *CBORCodec) String() string

func (*CBORCodec) Unmarshal

func (c *CBORCodec) Unmarshal(data []byte, v interface{}) error

type ClientOptions

type ClientOptions struct {
	// CommonName is the expected certificate common name.
	CommonName string

	// ServerPubKeys is the set of public keys that are allowed to sign the server's certificate. If
	// this field is set GetServerPubKeys will be ignored.
	ServerPubKeys map[signature.PublicKey]bool

	// If GetServerPubKeys is set and ServerPubKeys is nil, GetServerPubKeys will be invoked every
	// time when verifying the server certificates.
	GetServerPubKeys ServerPubKeysGetter

	// If field Certificates is set, field GetClientCertificate will be ignored. The server will use
	// Certificates every time when asked for a certificate, without performing certificate
	// reloading.
	Certificates []tls.Certificate

	// If GetClientCertificate is set and Certificates is nil, the server will invoke this function
	// every time asked to present certificates to the client when a new connection is established.
	// This is known as peer certificate reloading.
	GetClientCertificate func(*tls.CertificateRequestInfo) (*tls.Certificate, error)
}

ClientOptions contains all the fields needed to configure a TLS client.

type MethodDesc

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

MethodDesc is a gRPC method descriptor.

func GetRegisteredMethod

func GetRegisteredMethod(name string) (*MethodDesc, error)

GetRegisteredMethod returns a registered method description.

func (*MethodDesc) ExtractNamespace

func (m *MethodDesc) ExtractNamespace(ctx context.Context, req interface{}) (common.Namespace, error)

ExtractNamespace extracts the from the method request.

func (*MethodDesc) FullName

func (m *MethodDesc) FullName() string

FullName returns the full method name.

func (*MethodDesc) HasNamespaceExtractor

func (m *MethodDesc) HasNamespaceExtractor() bool

HasNamespaceExtractor returns true iff method has a defined namespace extractor.

func (*MethodDesc) IsAccessControlled

func (m *MethodDesc) IsAccessControlled(ctx context.Context, req interface{}) (bool, error)

IsAccessControlled retruns if method is access controlled.

func (*MethodDesc) ShortName

func (m *MethodDesc) ShortName() string

ShortName returns the short method name.

func (*MethodDesc) UnmarshalRawMessage

func (m *MethodDesc) UnmarshalRawMessage(req *cbor.RawMessage) (interface{}, error)

UnmarshalRawMessage unmarshals `cbor.RawMessage` request.

func (*MethodDesc) WithAccessControl

func (m *MethodDesc) WithAccessControl(f AccessControlFunc) *MethodDesc

WithAccessControl tells weather the endpoint does have access control.

func (*MethodDesc) WithNamespaceExtractor

func (m *MethodDesc) WithNamespaceExtractor(f NamespaceExtractorFunc) *MethodDesc

WithNamespaceExtractor tells weather the endpoint does have namespace extractor defined.

type NamespaceExtractorFunc

type NamespaceExtractorFunc func(ctx context.Context, req interface{}) (common.Namespace, error)

NamespaceExtractorFunc extracts namespce from a method request.

type Server

type Server struct {
	sync.Mutex
	service.BaseBackgroundService
	// contains filtered or unexported fields
}

Server is a gRPC server service.

func NewServer

func NewServer(config *ServerConfig) (*Server, error)

NewServer constructs a new gRPC server service listening on a specific TCP port or local socket path.

This internally takes a snapshot of the current global tracer, so make sure you initialize the global tracer before calling this.

func (*Server) Cleanup

func (s *Server) Cleanup()

Cleanup cleans up after the Server.

func (*Server) DeregisterServiceWrapper

func (s *Server) DeregisterServiceWrapper(prefix string)

DeregisterServiceWrapper removes the specified service wrapper from the stack. Subsequent messages the service might receive will be answered with an error response.

func (*Server) RegisterServiceWrapper

func (s *Server) RegisterServiceWrapper(prefix string, registrator func(*grpc.Server)) <-chan *WrappedRequest

RegisterServiceWrapper registers a wrapper for the specified GRPC service and registers it with the GRPC server.

Note: In case multiple wrappers are registered with the same prefix, only the first one will be used. If a wrapper is registered with a prefix that overlaps with the same set of services as another prefix, then both such wrappers will be called, potentially confusing the remote end of the connection.

func (*Server) Server

func (s *Server) Server() *grpc.Server

Server returns the underlying gRPC server instance.

func (*Server) Start

func (s *Server) Start() error

Start starts the Server.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the Server.

type ServerConfig

type ServerConfig struct {
	// Name of the server being constructed.
	Name string
	// Port is the port used for TCP servers.
	//
	// Iff Path is not empty (i.e. a local server is being created), and Port is not 0, then
	// the local server will *also* listen on that port.
	Port uint16
	// Path is the path for the local server. Leave nil to create a TCP server.
	Path string
	// Identity is the identity of the worker that's running the server.
	Identity *identity.Identity
	// InstallWrapper specifies whether intercepting facilities should be enabled on this server,
	// to enable intercepting RPC calls with a wrapper.
	InstallWrapper bool
	// AuthFunc is the authentication function for access control.
	AuthFunc auth.AuthenticationFunction
	// ClientCommonName is the expected common name on client TLS certificates. If not specified,
	// the default identity.CommonName will be used.
	ClientCommonName string
	// CustomOptions is an array of extra options for the grpc server.
	CustomOptions []grpc.ServerOption
}

ServerConfig holds the configuration used for creating a server.

type ServerPubKeysGetter added in v0.2010.0

type ServerPubKeysGetter func() (map[signature.PublicKey]bool, error)

ServerPubKeysGetter is a function that when called will produce a set of public keys.

func ServerPubKeysGetterFromCertificate added in v0.2010.0

func ServerPubKeysGetterFromCertificate(cert *x509.Certificate) ServerPubKeysGetter

ServerPubKeysGetterFromCertificate returns a ServerPubKeysGetter that returns the public key that signed the given X509 certificate.

type ServiceName

type ServiceName string

ServiceName is a gRPC service name.

func NewServiceName

func NewServiceName(name string) ServiceName

NewServiceName creates a new gRPC service name.

func ServiceNameFromMethod

func ServiceNameFromMethod(methodName string) ServiceName

ServiceNameFromMethod extract service name from method name.

func (ServiceName) NewMethod

func (sn ServiceName) NewMethod(name string, requestType interface{}) *MethodDesc

NewMethod creates a new method name for the given service.

type WrappedRequest

type WrappedRequest struct {
	// Unary is a wrapped unary request.
	Unary *WrappedUnaryRequest
	// Stream is a wrapped stream request.
	Stream *WrappedStreamRequest
	// contains filtered or unexported fields
}

WrappedRequest is a struct containing either a wrapped unary or stream request.

func (*WrappedRequest) Forward

func (req *WrappedRequest) Forward() (interface{}, error)

Forward forwards the request to the original handler and returns its return values.

func (*WrappedRequest) Respond

func (req *WrappedRequest) Respond(resp interface{}, err error)

Respond sends the given response back to the GRPC wrapper.

type WrappedRequestCommon

type WrappedRequestCommon struct {
	Method string
}

WrappedRequestCommon is a struct with common metadata about intercepted GRPC requests.

type WrappedStreamRequest

type WrappedStreamRequest struct {
	WrappedRequestCommon

	Server  interface{}
	Stream  grpc.ServerStream
	Info    *grpc.StreamServerInfo
	Handler grpc.StreamHandler
}

WrappedStreamRequest is a stream GRPC request packet.

func (*WrappedStreamRequest) Forward

func (s *WrappedStreamRequest) Forward() error

Forward forwards the wrapped request further down the GRPC stack, potentially to the original server implementation.

type WrappedUnaryRequest

type WrappedUnaryRequest struct {
	WrappedRequestCommon

	Context context.Context
	Request interface{}
	Info    *grpc.UnaryServerInfo
	Handler grpc.UnaryHandler
}

WrappedUnaryRequest is an unary GRPC request packet.

func (*WrappedUnaryRequest) Forward

func (u *WrappedUnaryRequest) Forward() (interface{}, error)

Forward forwards the wrapped request further down the GRPC stack, potentially to the original server implementation.

Directories

Path Synopsis
Package auth implements gRPC authentication server interceptors.
Package auth implements gRPC authentication server interceptors.
api
Package api defines the common gRPC policy service and data structures.
Package api defines the common gRPC policy service and data structures.
Package proxy implements service agnostic gRPC reverse proxy.
Package proxy implements service agnostic gRPC reverse proxy.
Package testing implements common grpc testing helpers.
Package testing implements common grpc testing helpers.

Jump to

Keyboard shortcuts

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