package transport

Import Path
	google.golang.org/grpc/internal/transport (on go.dev)

Dependency Relation
	imports 47 packages, and imported by 2 packages

Involved Source Files bdp_estimator.go client_stream.go controlbuf.go defaults.go flowcontrol.go handler_server.go http2_client.go http2_server.go http_util.go logging.go proxy.go server_stream.go Package transport defines and implements message oriented communication channel to complete various transactions (e.g., an RPC). It is meant for grpc-internal usage and is not intended to be imported directly by users.
Package-Level Type Names (total 56, in which 12 are exported)
/* sort exporteds by: | */
CallHdr carries the information of a particular RPC. Authority is used to explicitly override the `:authority` header. If set, this value takes precedence over the Host field and will be used as the value for the `:authority` header. ContentSubtype specifies the content-subtype for a request. For example, a content-subtype of "proto" will result in a content-type of "application/grpc+proto". The value of ContentSubtype must be all lowercase, otherwise the behavior is undefined. See https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for more details. Creds specifies credentials.PerRPCCredentials for a call. // called when the stream is finished Host specifies the peer's host. Method specifies the operation to perform. // value of grpc-previous-rpc-attempts header to set SendCompress specifies the compression algorithm applied on outbound message. func ClientTransport.NewStream(ctx context.Context, callHdr *CallHdr) (*ClientStream, error)
ClientStream implements streaming functionality for a gRPC client. // Embed for common stream functionality. BytesReceived indicates whether any bytes have been received on this stream. Close closes the stream and propagates err to any readers. Context returns the context of the stream. Done returns a channel which is closed when it receives the final status from the server. GoString is implemented by Stream so context.String() won't race when printing %#v. Header returns the header metadata of the stream. Acquires the key-value pairs of header metadata once it is available. It blocks until i) the metadata is ready or ii) there is no header metadata or iii) the stream is canceled/expired. Method returns the method for the stream. Read reads an n byte message from the input stream. ReadMessageHeader reads data into the provided header slice from the stream. It first checks if there was an error during a previous read operation and returns it if present. It then requests a read operation for the length of the header. It continues to read from the stream until the entire header slice is filled or an error occurs. If an `io.EOF` error is encountered with partially read data, it is converted to `io.ErrUnexpectedEOF` to indicate an unexpected end of the stream. The method returns any error encountered during the read process or nil if the header was successfully read. RecvCompress returns the compression algorithm applied to the inbound message. It is empty string if there is no compression applied. Status returns the status received from the server. Status can be read safely only after the stream has ended, that is, after Done() is closed. Trailer returns the cached trailer metadata. Note that if it is not called after the entire stream is done, it could return an empty MD. It can be safely read only after stream has ended that is either read or write have returned io.EOF. TrailersOnly blocks until a header or trailers-only frame is received and then returns true if the stream was trailers-only. If the stream ends before headers are received, returns true, nil. Unprocessed indicates whether the server did not process this stream -- i.e. it sent a refused stream or GOAWAY including this stream ID. Write writes the hdr and data bytes to the output stream. ClientStream : fmt.GoStringer func ClientTransport.NewStream(ctx context.Context, callHdr *CallHdr) (*ClientStream, error)
ClientTransport is the common interface for all gRPC client-side transport implementations. Close tears down this transport. Once it returns, the transport should not be accessed any more. The caller must make sure this is called only once. Error returns a channel that is closed when some I/O error happens. Typically the caller should have a goroutine to monitor this in order to take action (e.g., close the current transport and create a new one) in error case. It should not return nil once the transport is initiated. GetGoAwayReason returns the reason why GoAway frame was received, along with a human readable string with debug info. GoAway returns a channel that is closed when ClientTransport receives the draining signal from the server (e.g., GOAWAY frame in HTTP/2). GracefulClose starts to tear down the transport: the transport will stop accepting new RPCs and NewStream will return error. Once all streams are finished, the transport will close. It does not block. NewStream creates a Stream for an RPC. RemoteAddr returns the remote network address. func NewHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts ConnectOptions, onClose func(GoAwayReason)) (_ ClientTransport, err error)
ConnectionError is an error that results in the termination of the entire connection and the retry of all the active streams. Desc string ( ConnectionError) Error() string Origin returns the original error of this connection error. Temporary indicates if this connection error is temporary or fatal. Unwrap returns the original error of this connection error or nil when the origin is nil. ConnectionError : error var ErrConnClosing
ConnectOptions covers all relevant options for communicating with the server. The mem.BufferPool to use when reading/writing to the wire. ChannelzParent sets the addrConn id which initiated the creation of this client transport. CredsBundle is the credentials bundle to be used. Only one of TransportCredentials and CredsBundle is non-nil. Dialer specifies how to dial a network address. FailOnNonTempDialError specifies if gRPC fails on non-temporary dial errors. InitialConnWindowSize sets the initial window size for a connection. InitialWindowSize sets the initial window size for a stream. KeepaliveParams stores the keepalive parameters. MaxHeaderListSize sets the max (uncompressed) size of header list that is prepared to be received. PerRPCCredentials stores the PerRPCCredentials required to issue RPCs. ReadBufferSize sets the size of read buffer, which in turn determines how much data can be read at most for one read syscall. SharedWriteBuffer indicates whether connections should reuse write buffer StaticWindowSize controls whether dynamic window sizing is enabled. StatsHandlers stores the handler for stats. TransportCredentials stores the Authenticator required to setup a client connection. Only one of TransportCredentials and CredsBundle is non-nil. UserAgent is the application user agent. WriteBufferSize sets the size of write buffer which in turn determines how much data can be batched before it's written on the wire. func NewHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts ConnectOptions, onClose func(GoAwayReason)) (_ ClientTransport, err error)
GoAwayReason contains the reason for the GoAway frame received. func ClientTransport.GetGoAwayReason() (GoAwayReason, string) const GoAwayInvalid const GoAwayNoReason const GoAwayTooManyPings
NewStreamError wraps an error and reports additional information. Typically NewStream errors result in transparent retry, as they mean nothing went onto the wire. However, there are two notable exceptions: 1. If the stream headers violate the max header list size allowed by the server. It's possible this could succeed on another transport, even if it's unlikely, but do not transparently retry. 2. If the credentials errored when requesting their headers. In this case, it's possible a retry can fix the problem, but indefinitely transparently retrying is not appropriate as it is likely the credentials, if they can eventually succeed, would need I/O to do so. AllowTransparentRetry bool Err error ( NewStreamError) Error() string NewStreamError : error
ServerStream implements streaming functionality for a gRPC server. // Embed for common stream functionality. ClientAdvertisedCompressors returns the compressor names advertised by the client via grpc-accept-encoding header. ContentSubtype returns the content-subtype for a request. For example, a content-subtype of "proto" will result in a content-type of "application/grpc+proto". This will always be lowercase. See https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for more details. Context returns the context of the stream. GoString is implemented by Stream so context.String() won't race when printing %#v. Header returns the header metadata of the stream. It returns the out header after t.WriteHeader is called. It does not block and must not be called until after WriteHeader. HeaderWireLength returns the size of the headers of the stream as received from the wire. Method returns the method for the stream. Read reads an n byte message from the input stream. ReadMessageHeader reads data into the provided header slice from the stream. It first checks if there was an error during a previous read operation and returns it if present. It then requests a read operation for the length of the header. It continues to read from the stream until the entire header slice is filled or an error occurs. If an `io.EOF` error is encountered with partially read data, it is converted to `io.ErrUnexpectedEOF` to indicate an unexpected end of the stream. The method returns any error encountered during the read process or nil if the header was successfully read. RecvCompress returns the compression algorithm applied to the inbound message. It is empty string if there is no compression applied. SendCompress returns the send compressor name. SendHeader sends the header metadata for the given stream. SetContext sets the context of the stream. This will be deleted once the stats handler callouts all move to gRPC layer. SetHeader sets the header metadata. This can be called multiple times. This should not be called in parallel to other data writes. SetSendCompress sets the compression algorithm to the stream. SetTrailer sets the trailer metadata which will be sent with the RPC status by the server. This can be called multiple times. This should not be called parallel to other data writes. Trailer returns the cached trailer metadata. Note that if it is not called after the entire stream is done, it could return an empty MD. It can be safely read only after stream has ended that is either read or write have returned io.EOF. Write writes the hdr and data bytes to the output stream. WriteStatus sends the status of a stream to the client. WriteStatus is the final call made on a stream and always occurs. *ServerStream : google.golang.org/grpc.ServerTransportStream ServerStream : fmt.GoStringer
ServerTransport is the common interface for all gRPC server-side transport implementations. Methods may be called concurrently from multiple goroutines, but Write methods for a given Stream will be called serially. Close tears down the transport. Once it is called, the transport should not be accessed any more. All the pending streams and their handlers will be terminated asynchronously. Drain notifies the client this ServerTransport stops accepting new RPCs. HandleStreams receives incoming streams using the given handler. Peer returns the peer of the server transport. func NewServerHandlerTransport(w http.ResponseWriter, r *http.Request, stats []stats.Handler, bufferPool mem.BufferPool) (ServerTransport, error) func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport, err error)
Stream represents an RPC in the transport layer. Context returns the context of the stream. GoString is implemented by Stream so context.String() won't race when printing %#v. Method returns the method for the stream. ReadMessageHeader reads data into the provided header slice from the stream. It first checks if there was an error during a previous read operation and returns it if present. It then requests a read operation for the length of the header. It continues to read from the stream until the entire header slice is filled or an error occurs. If an `io.EOF` error is encountered with partially read data, it is converted to `io.ErrUnexpectedEOF` to indicate an unexpected end of the stream. The method returns any error encountered during the read process or nil if the header was successfully read. Trailer returns the cached trailer metadata. Note that if it is not called after the entire stream is done, it could return an empty MD. It can be safely read only after stream has ended that is either read or write have returned io.EOF. *Stream : fmt.GoStringer
WriteOptions provides additional hints and information for message transmission. Last indicates whether this write is the last piece for this stream. func (*ClientStream).Write(hdr []byte, data mem.BufferSlice, opts *WriteOptions) error func (*ServerStream).Write(hdr []byte, data mem.BufferSlice, opts *WriteOptions) error
Package-Level Functions (total 42, in which 7 are exported)
ContextErr converts the error from context package into a status error.
GetConnection gets the connection from the context.
NewHTTP2Client constructs a connected ClientTransport to addr based on HTTP2 and starts to receive messages on it. Non-nil error returns if construction fails.
NewServerHandlerTransport returns a ServerTransport handling gRPC from inside an http.Handler, or writes an HTTP error to w and returns an error. It requires that the http Server supports HTTP/2.
NewServerTransport creates a http2 transport with conn and configuration options from config. It returns a non-nil transport and a nil error on success. On failure, it returns a nil transport and a non-nil error. For a special case where the underlying conn gets closed before the client preface could be read, it returns a nil transport and a nil error.
ParseDialTarget returns the network and address to pass to dialer.
SetConnection adds the connection to the context to be able to get information about the destination ip and port for an incoming RPC. This also allows any unary or streaming interceptors to see the connection.
Package-Level Variables (total 22, in which 5 are exported)
ErrConnClosing indicates that the transport is closing.
ErrHeaderListSizeLimitViolation indicates that the header list size is larger than the limit set by peer.
ErrIllegalHeaderWrite indicates that setting header is illegal because of the stream's state.
HTTPStatusConvTab is the HTTP status code to gRPC error code conversion table.
MaxStreamID is the upper bound for the stream ID before the current transport gracefully closes and new transport is created for subsequent RPCs. This is set to 75% of 2^31-1. Streams are identified with an unsigned 31-bit integer. It's exported so that tests can override it.
Package-Level Constants (total 53, in which 3 are exported)
GoAwayInvalid indicates that no GoAway frame is received.
GoAwayNoReason is the default value when GoAway frame is received.
GoAwayTooManyPings indicates that a GoAway frame with ErrCodeEnhanceYourCalm was received and that the debug data said "too_many_pings".