tsproto

package
v0.0.0-...-853a302 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UpgradeProtocol is the Upgrade / Connection header token.
	UpgradeProtocol = controlhttpcommon.UpgradeHeaderValue
	// HandshakeHeaderName carries the base64 Noise initiation on the upgrade request.
	HandshakeHeaderName = controlhttpcommon.HandshakeHeaderName
)

ts2021 control-protocol HTTP upgrade constants, re-exported so the tunnel and capture layers don't import controlhttpcommon directly.

View Source
const CurrentCapabilityVersion = tailcfg.CurrentCapabilityVersion

CurrentCapabilityVersion is the capability version of the pinned Tailscale upstream.

View Source
const MaxMapFrameBytes = 10 << 20

MaxMapFrameBytes bounds a single MapResponse frame (resource limit, not a protocol check).

Variables

This section is empty.

Functions

func DecodeEarlyNoise

func DecodeEarlyNoise(buf []byte) (n *tailcfg.EarlyNoise, consumed int, ok bool, err error)

DecodeEarlyNoise parses an EarlyNoise frame and returns the message plus the number of bytes consumed. It returns ok=false with no error when buf does not yet hold a complete frame, so a caller can accumulate more bytes and retry. TODO - review if useful for Encode/Decode symmetry, or remove

func DecodeMapResponseFrame

func DecodeMapResponseFrame(buf []byte) (jsonPayload []byte, compressed bool, consumed int, ok bool, err error)

DecodeMapResponseFrame parses one MapResponse frame from buf, returning the JSON payload, whether the frame body was zstd-compressed, and the number of bytes consumed. It returns ok=false with no error when buf does not yet hold a complete frame.

func EncodeEarlyNoise

func EncodeEarlyNoise(n *tailcfg.EarlyNoise) ([]byte, error)

EncodeEarlyNoise frames an EarlyNoise message as the magic prefix, a 4-byte big-endian length, and the JSON payload.

func EncodeMapResponseFrame

func EncodeMapResponseFrame(jsonPayload []byte, compress bool) []byte

EncodeMapResponseFrame encodes a MapResponse JSON payload as one wire frame: zstd-compressed when compress is true, else raw JSON, prefixed by its 4-byte little-endian length. Preserve the source frame's mode when re-encoding so a client that did not request zstd still decodes the stream.

func InitiationVersion

func InitiationVersion(init []byte) (uint16, error)

InitiationVersion reads the 2-byte big-endian protocol (capability) version from a Noise initiation (msg 1). It is carried through unchanged to the upstream initiation and the /key fetch.

func ReadEarlyNoise

func ReadEarlyNoise(br *bufio.Reader) (raw []byte, n *tailcfg.EarlyNoise, ok bool, err error)

ReadEarlyNoise reads an optional leading EarlyNoise frame from br. When the next bytes are an EarlyNoise frame it returns the raw frame and parsed message with ok=true; otherwise ok=false and br is left unconsumed.

func Responder

func Responder(ctx context.Context, conn net.Conn, controlKey key.MachinePrivate, init []byte) (*controlbase.Conn, error)

Responder runs the client-facing Noise IK responder handshake over conn using controlKey (the sidecar's client-facing responder private key). init is the client's initiation recovered from the X-Tailscale-Handshake header. The returned Conn exposes the decrypted inner byte stream.

Types

type CapabilityVersion

type CapabilityVersion = tailcfg.CapabilityVersion

Inner control-protocol message types, aliased to centralize the tailscale.com/tailcfg coupling.

type CaptureFunc

type CaptureFunc func(req *http.Request) (*http.Response, error)

CaptureFunc handles one inner request from the client-facing side and returns the response to relay back. The response Body is streamed to the client and closed by the bridge.

type EarlyNoise

type EarlyNoise = tailcfg.EarlyNoise

Inner control-protocol message types, aliased to centralize the tailscale.com/tailcfg coupling.

type H2Bridge

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

H2Bridge bridges inner HTTP/2 between a client-facing connection (server side) and an upstream connection (client side), both prior-knowledge HTTP/2 over a plaintext Noise byte stream.

func NewH2Bridge

func NewH2Bridge(upstreamConn net.Conn) (*H2Bridge, error)

NewH2Bridge returns a bridge whose upstream client speaks over upstreamConn.

func (*H2Bridge) Close

func (b *H2Bridge) Close() error

Close shuts down the upstream HTTP/2 client connection.

func (*H2Bridge) Forward

func (b *H2Bridge) Forward(req *http.Request) (*http.Response, error)

Forward sends req upstream and returns the response.

func (*H2Bridge) ServeCapture

func (b *H2Bridge) ServeCapture(clientConn net.Conn, capture CaptureFunc)

ServeCapture serves the client-facing side over clientConn, routing each inner request through capture, until the connection closes

func (*H2Bridge) Usable

func (b *H2Bridge) Usable() bool

Usable reports whether the upstream connection can still serve requests.

type Initiation

type Initiation struct {
	// initiation (msg 1) to place base64-encoded in the X-Tailscale-Handshake header
	Header []byte
	// contains filtered or unexported fields
}

Initiation is a prepared upstream initiator handshake.

func Initiator

func Initiator(machineKey key.MachinePrivate, controlKey key.MachinePublic, version uint16) (*Initiation, error)

Initiator prepares the upstream (server-facing) initiator handshake: machineKey is the sidecar's upstream machine identity, controlKey the real upstream server pubkey, and version the client's capability version carried through unchanged.

func (*Initiation) Complete

func (i *Initiation) Complete(ctx context.Context, conn net.Conn) (*controlbase.Conn, error)

Complete finishes the initiator handshake over conn. The returned Conn exposes the decrypted inner stream.

type MapRequest

type MapRequest = tailcfg.MapRequest

Inner control-protocol message types, aliased to centralize the tailscale.com/tailcfg coupling.

type MapResponse

type MapResponse = tailcfg.MapResponse

Inner control-protocol message types, aliased to centralize the tailscale.com/tailcfg coupling.

type RegisterRequest

type RegisterRequest = tailcfg.RegisterRequest

Inner control-protocol message types, aliased to centralize the tailscale.com/tailcfg coupling.

type RegisterResponse

type RegisterResponse = tailcfg.RegisterResponse

Inner control-protocol message types, aliased to centralize the tailscale.com/tailcfg coupling.

Jump to

Keyboard shortcuts

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