quic

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT, BSD-3-Clause Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package quic implements the QUIC protocol.

This package is a work in progress. It is not ready for production usage. Its API is subject to change without notice.

This package is low-level. Most users will use it indirectly through an HTTP/3 implementation.

Usage

An Endpoint sends and receives traffic on a network address. Create an Endpoint to either accept inbound QUIC connections or create outbound ones.

A Conn is a QUIC connection.

A Stream is a QUIC stream, an ordered, reliable byte stream.

Cancellation

All blocking operations may be canceled using a context.Context. When performing an operation with a canceled context, the operation will succeed if doing so does not require blocking. For example, reading from a stream will return data when buffered data is available, even if the stream context is canceled.

Limitations

This package is a work in progress. Known limitations include:

  • Performance is untuned.
  • 0-RTT is not supported (mimicry: Dial clients send 0-RTT; see UPSTREAM.md).
  • Address migration is not supported (mimicry: a Dial client moves to a new local port when its path degrades, as Chrome does; see UPSTREAM.md).
  • Server preferred addresses are not supported.
  • The latency spin bit is not supported (mimicry: browser clients set it; see UPSTREAM.md).
  • Stream send/receive windows are configurable, but are fixed and do not adapt to available throughput.
  • Path MTU discovery is not implemented.

Security Policy

This package is a work in progress, and not yet covered by the Go security policy.

mimicry

A copy of golang.org/x/net/quic with uTLS for TLS (decision 0027); changes are listed in UPSTREAM.md and marked "mimicry:". Dial's browser-shaped client lives in client*.go.

Index

Constants

View Source
const (
	// QLogLevelFrame includes per-frame information.
	// When this level is enabled, packet_sent and packet_received events will
	// contain information on individual frames sent/received.
	QLogLevelFrame = slog.Level(-6)

	// QLogLevelPacket events occur at most once per packet sent or received.
	//
	// For example: packet_sent, packet_received.
	QLogLevelPacket = slog.Level(-4)

	// QLogLevelConn events occur multiple times over a connection's lifetime,
	// but less often than the frequency of individual packets.
	//
	// For example: connection_state_updated.
	QLogLevelConn = slog.Level(-2)

	// QLogLevelEndpoint events occur at most once per connection.
	//
	// For example: connection_started, connection_closed.
	QLogLevelEndpoint = slog.Level(0)
)

Log levels for qlog events.

Variables

View Source
var ErrHandshakeTimeout = errors.New("quic: handshake timed out")

ErrHandshakeTimeout is the error of a client connection whose handshake the profile gave up on (QUICLoss's give-up): Dial returns it, and a connection Dial returned at once (0-RTT) ends with it (Conn.Err, Conn.WaitHandshake). errors.Is matches it, whatever the connection sent.

View Source
var ErrIdleTimeout = errIdleTimeout

ErrIdleTimeout is the error of a connection closed by its idle timeout (RFC 9000, section 10.1): Conn.Wait and Conn.Err return it.

View Source
var ErrNoDatagrams = errors.New("quic: the connection carries no DATAGRAM frames")

ErrNoDatagrams is the error of SendDatagram and ReceiveDatagram on a connection that carries no DATAGRAM frames: it did not ask for them (DialConfig.Datagrams), or the peer announced none (max_datagram_frame_size).

View Source
var ErrPathDegraded = errors.New("quic: path stopped answering")

ErrPathDegraded is the error of a client connection that closed itself because its path stopped answering (Safari: its keep-alives went unanswered). Requests pending on it never reached the server's answer; the browser sends them again on a new connection.

View Source
var ErrVersionNegotiation = errVersionNegotiation

ErrVersionNegotiation is the error of a connection the server answered with a Version Negotiation packet that does not list its version (RFC 9000, section 6.2). Dial returns it at once as a *VersionNegotiationError; errors.Is matches it.

Functions

func RetryVersion

func RetryVersion(err error, p *profile.QUIC, from uint32) (uint32, bool)

RetryVersion is the version a profile's client starts a new connection in after err, a Version Negotiation packet (RFC 9368, section 2.1), when its profile retries (QUICVersionNegotiation.Retry): the first of its Available Versions the packet lists, other than the one it was in. The new connection's DialConfig sets AfterVersionNegotiation.

func TicketVersion

func TicketVersion(extra [][]byte) uint32

TicketVersion is the QUIC version of the connection that issued a ticket, from its SessionState.Extra: the version a connection resuming it starts in (DialConfig.Version). Firefox resumes a v2 connection's ticket in v2 from its first packet (capture h3-v2); tickets of version 1 connections, and any other, give 1.

Types

type Config

type Config struct {
	// TLSConfig is the endpoint's TLS configuration.
	// It must be non-nil and include at least one certificate or else set GetCertificate.
	TLSConfig *tls.Config

	// MaxBidiRemoteStreams limits the number of simultaneous bidirectional streams
	// a peer may open.
	// If zero, the default value of 100 is used.
	// If negative, the limit is zero.
	MaxBidiRemoteStreams int64

	// MaxUniRemoteStreams limits the number of simultaneous unidirectional streams
	// a peer may open.
	// If zero, the default value of 100 is used.
	// If negative, the limit is zero.
	MaxUniRemoteStreams int64

	// MaxDatagramFrameSize, when positive, is the max_datagram_frame_size
	// a server announces (RFC 9221), for tests' peers; it never receives
	// DATAGRAM frames. mimicry: client_datagram.go.
	MaxDatagramFrameSize int64

	// MaxStreamReadBufferSize is the maximum amount of data sent by the peer that a
	// stream will buffer for reading.
	// If zero, the default value of 1MiB is used.
	// If negative, the limit is zero.
	MaxStreamReadBufferSize int64

	// MaxStreamWriteBufferSize is the maximum amount of data a stream will buffer for
	// sending to the peer.
	// If zero, the default value of 1MiB is used.
	// If negative, the limit is zero.
	MaxStreamWriteBufferSize int64

	// MaxConnReadBufferSize is the maximum amount of data sent by the peer that a
	// connection will buffer for reading, across all streams.
	// If zero, the default value of 1MiB is used.
	// If negative, the limit is zero.
	MaxConnReadBufferSize int64

	// RequireAddressValidation may be set to true to enable address validation
	// of client connections prior to starting the handshake.
	//
	// Enabling this setting reduces the amount of work packets with spoofed
	// source address information can cause a server to perform,
	// at the cost of increased handshake latency.
	RequireAddressValidation bool

	// StatelessResetKey is used to provide stateless reset of connections.
	// A restart may leave an endpoint without access to the state of
	// existing connections. Stateless reset permits an endpoint to respond
	// to a packet for a connection it does not recognize.
	//
	// This field should be filled with random bytes.
	// The contents should remain stable across restarts,
	// to permit an endpoint to send a reset for
	// connections created before a restart.
	//
	// The contents of the StatelessResetKey should not be exposed.
	// An attacker can use knowledge of this field's value to
	// reset existing connections.
	//
	// If this field is left as zero, stateless reset is disabled.
	StatelessResetKey [32]byte

	// HandshakeTimeout is the maximum time in which a connection handshake must complete.
	// If zero, the default of 10 seconds is used.
	// If negative, there is no handshake timeout.
	HandshakeTimeout time.Duration

	// MaxIdleTimeout is the maximum time after which an idle connection will be closed.
	// If zero, the default of 30 seconds is used.
	// If negative, idle connections are never closed.
	//
	// The idle timeout for a connection is the minimum of the maximum idle timeouts
	// of the endpoints.
	MaxIdleTimeout time.Duration

	// KeepAlivePeriod is the time after which a packet will be sent to keep
	// an idle connection alive.
	// If zero, keep alive packets are not sent.
	// If greater than zero, the keep alive period is the smaller of KeepAlivePeriod and
	// half the connection idle timeout.
	KeepAlivePeriod time.Duration

	// QLogLogger receives qlog events.
	//
	// Events currently correspond to the definitions in draft-ietf-qlog-quic-events-03.
	// This is not the latest version of the draft, but is the latest version supported
	// by common event log viewers as of the time this paragraph was written.
	//
	// The qlog package contains a slog.Handler which serializes qlog events
	// to a standard JSON representation.
	QLogLogger *slog.Logger
	// contains filtered or unexported fields
}

A Config structure configures a QUIC endpoint. A Config must not be modified after it has been passed to a QUIC function. A Config may be reused; the quic package will also not modify it.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone returns a shallow clone of c, or nil if c is nil. It is safe to clone a Config that is being used concurrently by a QUIC endpoint.

type Conn

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

A Conn is a QUIC connection.

Multiple goroutines may invoke methods on a Conn simultaneously.

func Dial

func Dial(ctx context.Context, pc net.PacketConn, peer netip.AddrPort, cfg DialConfig) (*Conn, error)

Dial opens a client connection to peer over pc, which it owns and closes when the connection ends (one connection per socket, as browsers do).

The connection is returned corked: the caller must Uncork once it has written its first requests, which then leave together. With a 0-RTT ticket Dial returns before anything is sent and those writes go in 0-RTT; otherwise it returns at handshake completion, with the Finished held until Uncork.

func (*Conn) Abandon

func (c *Conn) Abandon()

Abandon ends the connection as a browser drops a QUIC attempt that lost the race to TCP (QUICLoss.AbandonClose). Before the handshake completes it sends at most one 0-RTT CONNECTION_CLOSE (H3_NO_ERROR) and ends at once; after, it is Abort(nil).

func (*Conn) Abort

func (c *Conn) Abort(err error)

Abort closes the connection and returns immediately.

If err is nil, Abort sends a transport error of NO_ERROR to the peer. If err is a ConnectionCloseError, Abort sends its error code and text. Otherwise, Abort sends a transport error of APPLICATION_ERROR with the error's text.

func (*Conn) AcceptStream

func (c *Conn) AcceptStream(ctx context.Context) (*Stream, error)

AcceptStream waits for and returns the next stream created by the peer.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

Close is equivalent to:

conn.Abort(nil)
err := conn.Wait(context.Background())

func (*Conn) Confirmed

func (c *Conn) Confirmed() <-chan struct{}

Confirmed is closed once the handshake is confirmed: the server's HANDSHAKE_DONE arrived (RFC 9001, section 4.1.2).

func (*Conn) ConnectionState

func (c *Conn) ConnectionState() tls.ConnectionState

ConnectionState returns basic TLS details about the connection.

func (*Conn) Cork

func (c *Conn) Cork()

Cork holds the connection's packets: what the application writes and flushes until the matching Uncork leaves together, its STREAM frames in the order the streams were flushed. Corks nest. A handshake in progress is not held, apart from the client's Finished once it is ready. A datagram the loop is building when Cork is called is finished first, so nothing written after Cork returns goes in it.

func (*Conn) Discard

func (c *Conn) Discard()

Discard ends the connection at once without a word to the peer: no CONNECTION_CLOSE and no draining period, as an idle timeout ends it (RFC 9000, section 10.1). Its socket closes with it; Err is then non-nil.

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done is closed when the connection has ended; Err then says why.

func (*Conn) EarlyData

func (c *Conn) EarlyData() bool

EarlyData reports whether the connection sends 0-RTT data: it resumes a ticket that allows it, and the server has not rejected it.

func (*Conn) Err

func (c *Conn) Err() error

Err is why the connection ended (nil before Done is closed): nil for a close with NO_ERROR, ErrIdleTimeout, a *ConnectionCloseError for the peer's application close, or another error.

func (*Conn) ExpectStream added in v0.2.0

func (c *Conn) ExpectStream()

ExpectStream counts a request made on the connection, which opens a bidirectional stream with NewStream next. A request made when the requests before it take every stream the server allows may send STREAMS_BLOCKED by the profile's rule (profile.QUICStreamsBlocked). Every ExpectStream must be followed by one NewStream, which counts the request as given its stream, or as gone if it fails. Without a rule it does nothing.

func (*Conn) FinishedSent

func (c *Conn) FinishedSent() <-chan struct{}

FinishedSent is closed once the datagram carrying the client's Finished (all of its Handshake CRYPTO data) has been handed to the socket: what the application writes from then on goes in a later datagram.

func (*Conn) HandshakeComplete

func (c *Conn) HandshakeComplete() <-chan struct{}

HandshakeComplete is closed once the TLS handshake is complete: the client's Finished is ready, and what the application writes from then on goes in 1-RTT packets.

func (*Conn) HoldFinished

func (c *Conn) HoldFinished()

HoldFinished holds the client's Finished, once the handshake completes, with every packet after it, until the matching ReleaseFinished: what the application writes meanwhile leaves with it. Unlike Cork it holds nothing before the handshake completes, so 0-RTT data leaves as it is written.

func (*Conn) KeepAlive

func (c *Conn) KeepAlive(on bool)

KeepAlive tells the connection whether a request awaits its response. While one does, the connection sends the profile's keep-alive PINGs (QUICKeepAlive) and watches its path (QUICPathDegrading). An idle connection without requests ends silently.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() netip.AddrPort

LocalAddr returns the local network address, if known.

func (*Conn) MaxDatagramSize added in v0.5.0

func (c *Conn) MaxDatagramSize() int

MaxDatagramSize is the largest payload SendDatagram sends: what fits a packet of the profile's datagram size with nothing else in it, within the peer's max_datagram_frame_size. Zero until the peer's transport parameters arrive, and on a connection that carries no DATAGRAM frames.

func (*Conn) NewSendOnlyStream

func (c *Conn) NewSendOnlyStream(ctx context.Context) (*Stream, error)

NewSendOnlyStream creates a unidirectional, send-only stream.

If the peer's maximum stream limit for the connection has been reached, NewSendOnlyStream blocks until the limit is increased or the context expires.

func (*Conn) NewStream

func (c *Conn) NewStream(ctx context.Context) (*Stream, error)

NewStream creates a stream.

If the peer's maximum stream limit for the connection has been reached, NewStream blocks until the limit is increased or the context expires.

func (*Conn) ReceiveDatagram added in v0.5.0

func (c *Conn) ReceiveDatagram(ctx context.Context) ([]byte, error)

ReceiveDatagram returns the payload of the next DATAGRAM frame the peer sent, waiting for one until ctx ends or the connection does.

func (*Conn) ReleaseFinished

func (c *Conn) ReleaseFinished()

ReleaseFinished releases a HoldFinished.

func (*Conn) RememberedApplicationState added in v0.4.0

func (c *Conn) RememberedApplicationState() []byte

RememberedApplicationState is the application's state stored with the ticket the connection resumed with 0-RTT (DialConfig.RememberApplication), or nil: none, or no 0-RTT. Set before Dial returns.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() netip.AddrPort

RemoteAddr returns the remote network address, if known.

func (*Conn) SendDatagram added in v0.5.0

func (c *Conn) SendDatagram(b []byte) error

SendDatagram queues b to go in a DATAGRAM frame of the next 1-RTT packet with room for it, under congestion control, never sent again when lost (RFC 9221, section 5). A datagram the queue has no room for is dropped without an error, as a full socket drops one. b may be reused once it returns.

func (*Conn) SetApplicationState added in v0.4.0

func (c *Conn) SetApplicationState(state []byte)

SetApplicationState gives the application's state to store with the connection's 0-RTT tickets (DialConfig.RememberApplication): those held for it are stored now, later ones with it. Only the first call counts: the server's SETTINGS come once.

func (*Conn) Settle

func (c *Conn) Settle()

Settle returns once the connection's loop has handled everything sent to it before the call (an Uncork's wake included), so it has sent what that let it send; or once the connection has ended. NewStream no longer waits for the loop (UPSTREAM.md change 12): h3 settles after uncorking the streams it opens at the handshake, so a request started next is not packed in front of them (Chrome's 0-RTT: the control stream's packet first).

func (*Conn) SmoothedRTT

func (c *Conn) SmoothedRTT() time.Duration

SmoothedRTT is the connection's smoothed round-trip time (RFC 9002, section 5.3).

func (*Conn) String

func (c *Conn) String() string

func (*Conn) Uncork

func (c *Conn) Uncork()

Uncork releases a Cork; at the last one the held packets are sent.

func (*Conn) Wait

func (c *Conn) Wait(ctx context.Context) error

Wait waits for the peer to close the connection.

If the connection is closed locally and the peer does not close its end of the connection, Wait will return with a non-nil error after the drain period expires.

If the peer closes the connection with a NO_ERROR transport error, Wait returns nil. If the peer closes the connection with an application error, Wait returns a ConnectionCloseError containing the peer's error code and reason. If the peer closes the connection with any other status, Wait returns a non-nil error.

func (*Conn) WaitHandshake

func (c *Conn) WaitHandshake(ctx context.Context) error

WaitHandshake waits for the handshake to complete: nil once it has, the connection's error if it ended first (ErrHandshakeTimeout when the profile gave up), or ctx's.

type ConnectionCloseError

type ConnectionCloseError struct {
	Code   uint64 // application protocol error code (RFC 9000, Section 20.2).
	Reason string // diagnostic information for the closure
}

A ConnectionCloseError is a notice that a connection is being closed. It contains the information from a CONNECTION_CLOSE frame (RFC 9000, Section 19.19).

func (*ConnectionCloseError) Error

func (e *ConnectionCloseError) Error() string

func (*ConnectionCloseError) Is

func (e *ConnectionCloseError) Is(err error) bool

Is reports a match if err is a *ConnectionCloseError with a matching Code.

type DialConfig

type DialConfig struct {
	// Profile is the browser's QUIC section: how the connection builds,
	// numbers, pads and acknowledges its packets, and its transport
	// parameters. Required.
	Profile *profile.QUIC
	// Hello is the connection's ClientHello (handshake.Spec of the plan's
	// QUIC hello). It must carry quic_transport_parameters, whose body the
	// connection fills in, and pre_shared_key exactly when TLS's session
	// cache holds the ticket it resumes. A spec serves one connection.
	Hello *tls.ClientHelloSpec
	// TLS has the server name, the roots and the session cache
	// (handshake.QUICConfig). Required, with ServerName set, or
	// InsecureServerNameToVerify when no server_name is sent.
	TLS *tls.Config
	// Token is the token of the last NEW_TOKEN frame the server sent on an
	// earlier connection, sent in this one's Initial packets when the
	// profile uses tokens; nil for none.
	Token []byte
	// OnToken, if set, is called with each NEW_TOKEN token the server sends
	// (a copy), on the connection's goroutine: it must not block.
	OnToken func([]byte)
	// OnFirstDatagram, if set, is called once, when the connection hands
	// its first datagram to the socket, on the connection's goroutine: it
	// must not block. A connection dropped before that never calls it. A
	// Dial that fails has returned only once it was called, if it will be.
	OnFirstDatagram func()
	// CachedRTT is the smoothed RTT of the connection whose ticket Hello
	// resumes (Conn.SmoothedRTT), for a profile that sends it when resuming
	// (Chrome's initial_rtt); zero leaves that parameter out.
	CachedRTT time.Duration
	// Version is the QUIC version the connection starts in: zero or 1, or
	// 2 when Hello resumes the ticket of a v2 connection
	// (TicketVersion), as Firefox does. 2 needs a profile offering it.
	Version uint32
	// AfterVersionNegotiation: the connection is the one started in
	// Version after a Version Negotiation packet (RetryVersion). It then
	// requires the server's version_information and checks its Available
	// Versions (RFC 9368, section 4), and ignores further such packets.
	AfterVersionNegotiation bool
	// NewPath opens another UDP socket to the same peer, for a
	// connection that moves to a new local port when its path degrades
	// (QUICPathDegrading's PathMigrate: Chrome). Required for such a
	// profile; the socket is the connection's from then on.
	NewPath func(ctx context.Context) (net.PacketConn, error)
	// RememberApplication keeps each ticket the server sends until
	// Conn.SetApplicationState gives the application's state for it (the
	// server's HTTP/3 SETTINGS, which a client remembers for 0-RTT: RFC
	// 9114, section 7.2.4.2), then stores both, as QUICHE does; a
	// connection resuming the ticket finds that state in
	// Conn.RememberedApplicationState.
	RememberApplication bool
	// Datagrams lets the connection send and receive DATAGRAM frames (RFC
	// 9221: SendDatagram, ReceiveDatagram), for HTTP/3 datagrams. The
	// profile must announce max_datagram_frame_size; otherwise DATAGRAM
	// frames it receives are dropped.
	Datagrams bool
}

DialConfig is what a client connection needs besides its peer's address.

type Endpoint

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

An Endpoint handles QUIC traffic on a network address. It can accept inbound connections or create outbound ones.

Multiple goroutines may invoke methods on an Endpoint simultaneously.

func Listen

func Listen(network, address string, listenConfig *Config) (*Endpoint, error)

Listen listens on a local network address.

The config is used to for connections accepted by the endpoint. If the config is nil, the endpoint will not accept connections.

func NewEndpoint

func NewEndpoint(conn net.PacketConn, config *Config) (*Endpoint, error)

NewEndpoint creates an endpoint using a net.PacketConn as the underlying transport.

If the PacketConn is not a *net.UDPConn, the endpoint may be slower and lack access to some features of the network.

func (*Endpoint) Accept

func (e *Endpoint) Accept(ctx context.Context) (*Conn, error)

Accept waits for and returns the next connection.

func (*Endpoint) Close

func (e *Endpoint) Close(ctx context.Context) error

Close closes the Endpoint. Any blocked operations on the Endpoint or associated Conns and Stream will be unblocked and return errors.

Close aborts every open connection. Data in stream read and write buffers is discarded. It waits for the peers of any open connection to acknowledge the connection has been closed, unless the given context has expired or is canceled.

func (*Endpoint) Dial

func (e *Endpoint) Dial(ctx context.Context, network, address string, config *Config) (*Conn, error)

Dial creates and returns a connection to a network address. The config cannot be nil.

func (*Endpoint) LocalAddr

func (e *Endpoint) LocalAddr() netip.AddrPort

LocalAddr returns the local network address.

type Stream

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

A Stream is an ordered byte stream.

Streams may be bidirectional, read-only, or write-only. Methods inappropriate for a stream's direction (for example, [Write] to a read-only stream) return errors.

It is not safe to perform concurrent reads from or writes to a stream. It is safe, however, to read and write at the same time.

Reads and writes are buffered. It is generally not necessary to wrap a stream in a bufio.ReadWriter or otherwise apply additional buffering.

To cancel reads or writes, use the [SetReadContext] and [SetWriteContext] methods.

func (*Stream) Close

func (s *Stream) Close() error

Close closes the stream. Any blocked stream operations will be unblocked and return errors.

Close flushes any data in the stream write buffer and waits for the peer to acknowledge receipt of the data. If the stream has been reset, it waits for the peer to acknowledge the reset. If the context expires before the peer receives the stream's data, Close discards the buffer and returns the context error.

func (*Stream) CloseRead

func (s *Stream) CloseRead() error

CloseRead aborts reads on the stream.

It is identical to s.StopSending(0).

func (*Stream) CloseWrite

func (s *Stream) CloseWrite() error

CloseWrite aborts writes on the stream. Any blocked writes will be unblocked and return errors.

CloseWrite sends any data in the stream write buffer to the peer. It does not wait for the peer to acknowledge receipt of the data. Use Close to wait for the peer's acknowledgement.

CloseWrite only returns an error if used on a read-only stream.

func (*Stream) Flush

func (s *Stream) Flush() error

Flush flushes data written to the stream. It does not wait for the peer to acknowledge receipt of the data. Use Close to wait for the peer's acknowledgement.

func (*Stream) ID

func (s *Stream) ID() int64

ID returns the QUIC stream ID of s.

As specified in RFC 9000, the two least significant bits of a stream ID indicate the initiator and directionality of the stream. The upper bits are the stream number.

func (*Stream) IsReadOnly

func (s *Stream) IsReadOnly() bool

IsReadOnly reports whether the stream is read-only (a unidirectional stream created by the peer).

func (*Stream) IsWriteOnly

func (s *Stream) IsWriteOnly() bool

IsWriteOnly reports whether the stream is write-only (a unidirectional stream created locally).

func (*Stream) Read

func (s *Stream) Read(b []byte) (n int, err error)

Read reads data from the stream.

Read returns as soon as at least one byte of data is available.

If the peer closes the stream cleanly, Read returns io.EOF after returning all data sent by the peer. If the peer aborts reads on the stream, Read returns an error wrapping StreamError.

It is not safe to call Read concurrently.

func (*Stream) ReadByte

func (s *Stream) ReadByte() (byte, error)

ReadByte reads and returns a single byte from the stream.

It is not safe to call ReadByte concurrently.

func (*Stream) Reset

func (s *Stream) Reset(code uint64) error

Reset aborts writes on the stream and notifies the peer that the stream was terminated abruptly. Any blocked writes will be unblocked and return errors.

Reset sends an application protocol error code, which must be less than 2^62, to the peer. It does not wait for the peer to acknowledge receipt of the error. Use Close to wait for the peer's acknowledgement.

Reset does not affect reads. Use CloseRead to abort reads on the stream.

func (*Stream) SetReadContext

func (s *Stream) SetReadContext(ctx context.Context)

SetReadContext sets the context used for reads from the stream.

It is not safe to call SetReadContext concurrently.

func (*Stream) SetWriteContext

func (s *Stream) SetWriteContext(ctx context.Context)

SetWriteContext sets the context used for writes to the stream. The write context is also used by Close when waiting for writes to be received by the peer.

It is not safe to call SetWriteContext concurrently.

func (*Stream) StopSending

func (s *Stream) StopSending(code uint64) error

StopSending aborts reads on the stream. Any blocked reads will be unblocked and return errors.

StopSending sends an application protocol error code, which must be less than 2^62, to the peer. It does not wait for the peer to acknowledge the closure. Use Close to wait for the peer's acknowledgement.

StopSending only returns an error if called on a write-only stream.

func (*Stream) Write

func (s *Stream) Write(b []byte) (n int, err error)

Write writes data to the stream.

Write writes data to the stream write buffer. Buffered data is only sent when the buffer is sufficiently full. Call the Flush method to ensure buffered data is sent.

func (*Stream) WriteByte

func (s *Stream) WriteByte(c byte) error

WriteByte writes a single byte to the stream.

type StreamError

type StreamError uint64

A StreamError is an application protocol error code (RFC 9000, Section 20.2) indicating why a stream is being closed.

func (StreamError) Error

func (e StreamError) Error() string

type VersionNegotiationError

type VersionNegotiationError struct {
	// Versions are the packet's Supported Versions, reserved ones
	// included.
	Versions []uint32
}

VersionNegotiationError is a Version Negotiation packet's answer.

func (*VersionNegotiationError) Error

func (e *VersionNegotiationError) Error() string

func (*VersionNegotiationError) Is

func (e *VersionNegotiationError) Is(target error) bool

Is makes errors.Is(err, ErrVersionNegotiation) hold.

Directories

Path Synopsis
Package qlog serializes qlog events.
Package qlog serializes qlog events.
Package quicwire encodes and decode QUIC/HTTP3 wire encoding types, particularly variable-length integers.
Package quicwire encodes and decode QUIC/HTTP3 wire encoding types, particularly variable-length integers.
Package testcert contains a test-only localhost certificate.
Package testcert contains a test-only localhost certificate.

Jump to

Keyboard shortcuts

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