Documentation
¶
Overview ¶
Package grpc implements common gRPC related services and utilities.
Index ¶
- Constants
- Variables
- func Dial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func NewClientCreds(opts *ClientOptions) (credentials.TransportCredentials, error)
- func NewStreamWriter(stream grpc.ServerStream) io.Writer
- type AccessControlFunc
- type CBORCodec
- type ClientOptions
- type MethodDesc
- func (m *MethodDesc) ExtractNamespace(ctx context.Context, req interface{}) (common.Namespace, error)
- func (m *MethodDesc) FullName() string
- func (m *MethodDesc) HasNamespaceExtractor() bool
- func (m *MethodDesc) IsAccessControlled(ctx context.Context, req interface{}) (bool, error)
- func (m *MethodDesc) ShortName() string
- func (m *MethodDesc) UnmarshalRawMessage(req *cbor.RawMessage) (interface{}, error)
- func (m *MethodDesc) WithAccessControl(f AccessControlFunc) *MethodDesc
- func (m *MethodDesc) WithNamespaceExtractor(f NamespaceExtractorFunc) *MethodDesc
- type NamespaceExtractorFunc
- type Server
- type ServerConfig
- type ServiceName
- type WrappedRequest
- type WrappedRequestCommon
- type WrappedStreamRequest
- type WrappedUnaryRequest
Constants ¶
const (
// CfgLogDebug enables verbose gRPC debug output.
CfgLogDebug = "grpc.log.debug"
)
const ServicePrefix = "oasis-core."
ServicePrefix is a prefix given to all gRPC services defined by oasis-core.
Variables ¶
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.
var ( // Flags has the flags used by the gRPC server. Flags = flag.NewFlagSet("", flag.ContinueOnError) )
Functions ¶
func Dial ¶
func Dial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
Dial creates a client connection to the given target.
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 ¶
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 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 func() (map[signature.PublicKey]bool, error)
// 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 ¶
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) DeregisterServiceWrapper ¶
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.
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 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.
Source Files
¶
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. |