noiseconn

package
v1.79.0-mod Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package noiseconn contains an internal-only wrapper around controlbase.Conn that properly handles the early payload sent by the server before the HTTP/2 session begins.

See the documentation on the Conn type for more details.

Index

Constants

View Source
const EarlyPayloadMagic = "\xff\xff\xffTS"

EarlyPayloadMagic is the 5-byte magic prefix that indicates an early payload.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*controlbase.Conn
	// contains filtered or unexported fields
}

Conn is a wrapper around controlbase.Conn.

It allows attaching an ID to a connection to allow cleaning up references in the pool when the connection is closed, properly handles an optional "early payload" that's sent prior to beginning the HTTP/2 session, and provides a way to return a connection to a pool when the connection is closed.

func New

func New(conn *controlbase.Conn, h2t *http2.Transport, connID int, onClose func(int)) (*Conn, error)

New creates a new Conn that wraps the given controlbase.Conn.

h2t is the HTTP/2 transport to use for the connection; a new http2.ClientConn will be created that reads from the returned Conn.

connID should be a unique ID for this connection. When the Conn is closed, the onClose function will be called with the connID if it is non-nil.

func (*Conn) CanTakeNewRequest

func (c *Conn) CanTakeNewRequest() bool

CanTakeNewRequest reports whether the underlying HTTP/2 connection can take a new request, meaning it has not been closed or received or sent a GOAWAY.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) GetEarlyPayload

func (c *Conn) GetEarlyPayload(ctx context.Context) (*tailcfg.EarlyNoise, error)

GetEarlyPayload waits for the early Noise payload to arrive. It may return (nil, nil) if the server begins HTTP/2 without one.

It is safe to call this multiple times; all callers will block until the early Noise payload is ready (if any) and will return the same result for the lifetime of the Conn.

func (*Conn) Read

func (c *Conn) Read(p []byte) (n int, err error)

Read is basically the same as controlbase.Conn.Read, but it first reads the "early payload" header from the server which may or may not be present, depending on the server.

func (*Conn) ReserveNewRequest

func (c *Conn) ReserveNewRequest(ctx context.Context) (bool, *tailcfg.EarlyNoise, error)

ReserveNewRequest will reserve a new concurrent request on the connection.

It returns whether the reservation was successful, and any early Noise payload if present. If a reservation was not successful, it will return false and nil for the early payload.

func (*Conn) RoundTrip

func (c *Conn) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface.

Jump to

Keyboard shortcuts

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