Documentation ¶
Overview ¶
package ttrpc defines and implements a low level simple transfer protocol optimized for low latency and reliable connections between processes on the same host. The protocol uses simple framing for sending requests, responses, and data using multiple streams.
Index ¶
- Variables
- func GetMetadataValue(ctx context.Context, name string) (string, bool)
- func OversizedMessageError(messageLength int) error
- func WithMetadata(ctx context.Context, md MD) context.Context
- type Client
- func (c *Client) Call(ctx context.Context, service, method string, req, resp interface{}) error
- func (c *Client) Close() error
- func (c *Client) NewStream(ctx context.Context, desc *StreamDesc, service, method string, req interface{}) (ClientStream, error)
- func (c *Client) UserOnCloseWait(ctx context.Context) error
- type ClientOpts
- type ClientStream
- type Handshaker
- type Invoker
- type KeyValue
- type MD
- type Method
- type OversizedMessageErr
- type Request
- func (*Request) Descriptor() ([]byte, []int)deprecated
- func (x *Request) GetMetadata() []*KeyValue
- func (x *Request) GetMethod() string
- func (x *Request) GetPayload() []byte
- func (x *Request) GetService() string
- func (x *Request) GetTimeoutNano() int64
- func (*Request) ProtoMessage()
- func (x *Request) ProtoReflect() protoreflect.Message
- func (x *Request) Reset()
- func (x *Request) String() string
- type Response
- type Server
- type ServerOpt
- type ServiceDesc
- type Stream
- type StreamClientInterceptor
- type StreamDesc
- type StreamHandler
- type StreamServer
- type StreamServerInfo
- type StreamServerInterceptor
- type StringList
- type UnaryClientInfo
- type UnaryClientInterceptor
- type UnaryServerInfo
- type UnaryServerInterceptor
- type UnixCredentialsFunc
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProtocol is a general error in the handling the protocol. ErrProtocol = errors.New("protocol error") // ErrClosed is returned by client methods when the underlying connection is // closed. ErrClosed = errors.New("ttrpc: closed") // ErrServerClosed is returned when the Server has closed its connection. ErrServerClosed = errors.New("ttrpc: server closed") // ErrStreamClosed is when the streaming connection is closed. ErrStreamClosed = errors.New("ttrpc: stream closed") )
var File_github_com_containerd_ttrpc_request_proto protoreflect.FileDescriptor
Functions ¶
func GetMetadataValue ¶
GetMetadataValue gets a specific metadata value by name from context.Context
func OversizedMessageError ¶ added in v1.2.6
OversizedMessageError returns an OversizedMessageErr error for the given message length if it exceeds the allowed maximum. Otherwise a nil error is returned.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for a ttrpc server
func NewClient ¶
func NewClient(conn net.Conn, opts ...ClientOpts) *Client
NewClient creates a new ttrpc client using the given connection
func (*Client) NewStream ¶ added in v1.2.0
func (c *Client) NewStream(ctx context.Context, desc *StreamDesc, service, method string, req interface{}) (ClientStream, error)
NewStream creates a new stream with the given stream descriptor to the specified service and method. If not a streaming client, the request object may be provided.
type ClientOpts ¶
type ClientOpts func(c *Client)
ClientOpts configures a client
func WithChainUnaryClientInterceptor ¶ added in v1.2.3
func WithChainUnaryClientInterceptor(interceptors ...UnaryClientInterceptor) ClientOpts
WithChainUnaryClientInterceptor sets the provided chain of client interceptors
func WithOnClose ¶
func WithOnClose(onClose func()) ClientOpts
WithOnClose sets the close func whenever the client's Close() method is called
func WithUnaryClientInterceptor ¶
func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts
WithUnaryClientInterceptor sets the provided client interceptor
type ClientStream ¶ added in v1.2.0
type ClientStream interface { CloseSend() error SendMsg(m interface{}) error RecvMsg(m interface{}) error }
ClientStream is used to send or recv messages on the underlying stream
type Handshaker ¶
type Handshaker interface { // Handshake should confirm or decorate a connection that may be incoming // to a server or outgoing from a client. // // If this returns without an error, the caller should use the connection // in place of the original connection. // // The second return value can contain credential specific data, such as // unix socket credentials or TLS information. // // While we currently only have implementations on the server-side, this // interface should be sufficient to implement similar handshakes on the // client-side. Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) }
Handshaker defines the interface for connection handshakes performed on the server or client when first connecting.
type KeyValue ¶
type KeyValue struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` // contains filtered or unexported fields }
func (*KeyValue) Descriptor
deprecated
added in
v1.2.0
func (*KeyValue) ProtoMessage ¶
func (*KeyValue) ProtoMessage()
func (*KeyValue) ProtoReflect ¶ added in v1.2.0
func (x *KeyValue) ProtoReflect() protoreflect.Message
type MD ¶
MD is the user type for ttrpc metadata
func GetMetadata ¶
GetMetadata retrieves metadata from context.Context (previously attached with WithMetadata)
func (MD) Clone ¶ added in v1.2.7
Clone returns a copy of MD or nil if it's nil. It's copied from golang's `http.Header.Clone` implementation: https://cs.opensource.google/go/go/+/refs/tags/go1.23.4:src/net/http/header.go;l=94
type OversizedMessageErr ¶ added in v1.2.6
type OversizedMessageErr struct {
// contains filtered or unexported fields
}
OversizedMessageErr is used to indicate refusal to send an oversized message. It wraps a ResourceExhausted grpc Status together with the offending message length.
func (*OversizedMessageErr) Error ¶ added in v1.2.6
func (e *OversizedMessageErr) Error() string
Error returns the error message for the corresponding grpc Status for the error.
func (*OversizedMessageErr) MaximumLength ¶ added in v1.2.6
func (*OversizedMessageErr) MaximumLength() int
MaximumLength retrieves the maximum allowed message length that triggered the error.
func (*OversizedMessageErr) RejectedLength ¶ added in v1.2.6
func (e *OversizedMessageErr) RejectedLength() int
RejectedLength retrieves the rejected message length which triggered the error.
func (*OversizedMessageErr) Unwrap ¶ added in v1.2.6
func (e *OversizedMessageErr) Unwrap() error
Unwrap returns the corresponding error with our grpc status code.
type Request ¶
type Request struct { Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"` TimeoutNano int64 `protobuf:"varint,4,opt,name=timeout_nano,json=timeoutNano,proto3" json:"timeout_nano,omitempty"` Metadata []*KeyValue `protobuf:"bytes,5,rep,name=metadata,proto3" json:"metadata,omitempty"` // contains filtered or unexported fields }
func (*Request) Descriptor
deprecated
added in
v1.2.0
func (*Request) GetMetadata ¶ added in v1.2.0
func (*Request) GetPayload ¶ added in v1.2.0
func (*Request) GetService ¶ added in v1.2.0
func (*Request) GetTimeoutNano ¶ added in v1.2.0
func (*Request) ProtoMessage ¶
func (*Request) ProtoMessage()
func (*Request) ProtoReflect ¶ added in v1.2.0
func (x *Request) ProtoReflect() protoreflect.Message
type Response ¶
type Response struct { Status *status.Status `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` // contains filtered or unexported fields }
func (*Response) Descriptor
deprecated
added in
v1.2.0
func (*Response) GetPayload ¶ added in v1.2.0
func (*Response) ProtoMessage ¶
func (*Response) ProtoMessage()
func (*Response) ProtoReflect ¶ added in v1.2.0
func (x *Response) ProtoReflect() protoreflect.Message
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Register ¶
Register registers a map of methods to method handlers TODO: Remove in 2.0, does not support streams
func (*Server) RegisterService ¶ added in v1.2.0
func (s *Server) RegisterService(name string, desc *ServiceDesc)
type ServerOpt ¶
type ServerOpt func(*serverConfig) error
ServerOpt for configuring a ttrpc server
func WithChainUnaryServerInterceptor ¶ added in v1.2.3
func WithChainUnaryServerInterceptor(interceptors ...UnaryServerInterceptor) ServerOpt
WithChainUnaryServerInterceptor sets the provided chain of server interceptors
func WithServerHandshaker ¶
func WithServerHandshaker(handshaker Handshaker) ServerOpt
WithServerHandshaker can be passed to NewServer to ensure that the handshaker is called before every connection attempt.
Only one handshaker is allowed per server.
func WithUnaryServerInterceptor ¶
func WithUnaryServerInterceptor(i UnaryServerInterceptor) ServerOpt
WithUnaryServerInterceptor sets the provided interceptor on the server
type Stream ¶ added in v1.2.0
type Stream struct { Handler StreamHandler StreamingClient bool StreamingServer bool }
type StreamClientInterceptor ¶ added in v1.2.0
type StreamDesc ¶ added in v1.2.0
StreamDesc describes the stream properties, whether the stream has a streaming client, a streaming server, or both
type StreamHandler ¶ added in v1.2.0
type StreamHandler func(context.Context, StreamServer) (interface{}, error)
type StreamServer ¶ added in v1.2.0
type StreamServerInfo ¶ added in v1.2.0
StreamServerInfo provides information about the server request
type StreamServerInterceptor ¶ added in v1.2.0
type StreamServerInterceptor func(context.Context, StreamServer, *StreamServerInfo, StreamHandler) (interface{}, error)
type StringList ¶
type StringList struct { List []string `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` // contains filtered or unexported fields }
func (*StringList) Descriptor
deprecated
added in
v1.2.0
func (*StringList) Descriptor() ([]byte, []int)
Deprecated: Use StringList.ProtoReflect.Descriptor instead.
func (*StringList) GetList ¶ added in v1.2.0
func (x *StringList) GetList() []string
func (*StringList) ProtoMessage ¶
func (*StringList) ProtoMessage()
func (*StringList) ProtoReflect ¶ added in v1.2.0
func (x *StringList) ProtoReflect() protoreflect.Message
func (*StringList) Reset ¶
func (x *StringList) Reset()
func (*StringList) String ¶
func (x *StringList) String() string
type UnaryClientInfo ¶
type UnaryClientInfo struct {
FullMethod string
}
UnaryClientInfo provides information about the client request
type UnaryClientInterceptor ¶
type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error
UnaryClientInterceptor specifies the interceptor function for client request/response
type UnaryServerInfo ¶
type UnaryServerInfo struct {
FullMethod string
}
UnaryServerInfo provides information about the server request
type UnaryServerInterceptor ¶
type UnaryServerInterceptor func(context.Context, Unmarshaler, *UnaryServerInfo, Method) (interface{}, error)
UnaryServerInterceptor specifies the interceptor function for server request/response
type UnixCredentialsFunc ¶
func UnixSocketRequireRoot ¶
func UnixSocketRequireRoot() UnixCredentialsFunc
func UnixSocketRequireSameUser ¶
func UnixSocketRequireSameUser() UnixCredentialsFunc
UnixSocketRequireSameUser resolves the current effective unix user and returns a UnixCredentialsFunc that will validate incoming unix connections against the current credentials.
This is useful when using abstract sockets that are accessible by all users.
func UnixSocketRequireUidGid ¶
func UnixSocketRequireUidGid(uid, gid int) UnixCredentialsFunc
UnixSocketRequireUidGid requires specific *effective* UID/GID, rather than the real UID/GID.
For example, if a daemon binary is owned by the root (UID 0) with SUID bit but running as an unprivileged user (UID 1001), the effective UID becomes 0, and the real UID becomes 1001. So calling this function with uid=0 allows a connection from effective UID 0 but rejects a connection from effective UID 1001.
See socket(7), SO_PEERCRED: "The returned credentials are those that were in effect at the time of the call to connect(2) or socketpair(2)."
type Unmarshaler ¶
type Unmarshaler func(interface{}) error
Unmarshaler contains the server request data and allows it to be unmarshaled into a concrete type