tunnel

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeRelayProtocol              = "relay_protocol"
	ErrorCodeUnsupportedProtocolVersion = "unsupported_protocol_version"
	ErrorCodeRelayOverloaded            = "relay_overloaded"
	ErrorCodeStreamWindowTimeout        = "stream_window_timeout"
	ErrorCodeRequestCancelled           = "request_cancelled"
	ErrorCodeRequestDeadline            = "request_deadline"
	ErrorCodeSessionClosed              = "session_closed"
	ErrorCodeDrainTimeout               = "drain_timeout"
)
View Source
const (
	ProtocolVersion   uint8 = 2
	HeaderSize              = 28
	MaxV2PayloadBytes       = 64 * 1024
)
View Source
const (
	DirectTunnelPath       = "/internal/agent/direct-tunnel"
	MaxMetadataBytes       = MaxV2PayloadBytes
	MaxV2StreamWindowBytes = 8 * 1024 * 1024
	MaxV2SessionQueueBytes = 64 * 1024 * 1024
	MaxV2ConcurrentStreams = 4096
)
View Source
const (
	MaxWebSocketControlPayloadBytes = 125
	WebSocketTextMessage            = 1
	WebSocketBinaryMessage          = 2
	WebSocketCloseProtocolError     = 1002
)

Variables

View Source
var (
	ErrShortHeader            = errors.New("tunnel: frame header too short")
	ErrUnsupportedVersion     = errors.New("tunnel: unsupported protocol version")
	ErrUnknownFrameType       = errors.New("tunnel: unknown frame type")
	ErrUnknownFlags           = errors.New("tunnel: unknown frame flags")
	ErrPayloadLengthMismatch  = errors.New("tunnel: payload length mismatch")
	ErrPayloadTooLarge        = errors.New("tunnel: frame payload too large")
	ErrZeroStreamID           = errors.New("tunnel: stream ID is zero")
	ErrSequenceOverflow       = errors.New("tunnel: sequence overflow")
	ErrMetadataTooLarge       = errors.New("tunnel: metadata too large")
	ErrMalformedMetadata      = errors.New("tunnel: malformed metadata")
	ErrInvalidLimits          = errors.New("tunnel: invalid limits")
	ErrNilMetadataDestination = errors.New("tunnel: nil metadata destination")
	ErrStreamIDGeneration     = errors.New("tunnel: stream ID generation failed")
)
View Source
var ErrInvalidOpenKind = errors.New("tunnel: invalid open stream kind")

Functions

func DecodeMetadata

func DecodeMetadata[T any](payload []byte, dst *T, limit int64) error

func Encode

func Encode(frame Frame, limits Limits) ([]byte, error)

func EncodeMetadata

func EncodeMetadata[T any](value T, limit int64) ([]byte, error)

func EncodeWebSocketClose added in v0.0.16

func EncodeWebSocketClose(code int, reason string) ([]byte, error)

func FramePayloadLimit added in v0.0.14

func FramePayloadLimit(frameType Type, limits Limits) (int64, error)

FramePayloadLimit returns the negotiated payload ceiling for one frame type.

func NextSequence

func NextSequence(sequence uint32) (uint32, error)

func TrimRelayURIWhitespace

func TrimRelayURIWhitespace(raw string) string

TrimRelayURIWhitespace removes only the ASCII whitespace accepted around Relay URI input.

func ValidWebSocketRejectionStatus added in v0.0.16

func ValidWebSocketRejectionStatus(status int) bool

ValidWebSocketRejectionStatus reports whether an ordinary HTTP response can be the terminal result of a failed WebSocket upgrade.

func ValidateWebSocketMessageType added in v0.0.16

func ValidateWebSocketMessageType(messageType int) error

Types

type Authenticated

type Authenticated struct {
	DesiredGeneration uint64 `json:"desired_generation"`
	SessionGeneration uint64 `json:"session_generation"`
}

type CommitState

type CommitState uint8
const (
	PreCommit CommitState = iota
	CommitUncertain
	Committed
)

type Confirmed

type Confirmed struct {
	DesiredGeneration uint64 `json:"desired_generation"`
	SessionGeneration uint64 `json:"session_generation"`
}

type ConnectionCloseOwner

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

func NewConnectionCloseOwner

func NewConnectionCloseOwner(close func() error) *ConnectionCloseOwner

func (*ConnectionCloseOwner) Close

func (o *ConnectionCloseOwner) Close() error

type DirectAccepted added in v0.0.14

type DirectAccepted struct {
	SessionGeneration uint64 `json:"session_generation"`
}

type DirectConfirmed added in v0.0.14

type DirectConfirmed struct {
	SessionGeneration uint64 `json:"session_generation"`
}

type DirectHello added in v0.0.14

type DirectHello struct {
	ProtocolVersion uint8  `json:"protocol_version"`
	Limits          Limits `json:"limits"`
}

type DirectReady added in v0.0.14

type DirectReady struct {
	ProtocolVersion   uint8  `json:"protocol_version"`
	TargetAgentID     string `json:"target_agent_id"`
	SessionGeneration uint64 `json:"session_generation"`
	Limits            Limits `json:"limits"`
}

type Frame

type Frame struct {
	Version  uint8
	Type     Type
	Flags    uint16
	StreamID StreamID
	Sequence uint32
	Payload  []byte
}

func Decode

func Decode(message []byte, limits Limits) (Frame, error)

type HandshakeOutcome

type HandshakeOutcome uint32
const (
	HandshakePending HandshakeOutcome = iota
	HandshakeSucceeded
	HandshakeTimedOut
	HandshakeCanceled
	HandshakeStopped
)

type HandshakeOutcomeOwner

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

func NewHandshakeOutcomeOwner

func NewHandshakeOutcomeOwner() *HandshakeOutcomeOwner

func (*HandshakeOutcomeOwner) Outcome

func (*HandshakeOutcomeOwner) TryOwn

func (o *HandshakeOutcomeOwner) TryOwn(outcome HandshakeOutcome) bool

type Headers

type Headers struct {
	StatusCode int                 `json:"status_code"`
	Header     map[string][]string `json:"header"`
	Trailer    map[string][]string `json:"trailer,omitempty"`
}

type Hello

type Hello struct {
	Nonce             string `json:"nonce"`
	DesiredGeneration uint64 `json:"desired_generation"`
}

type Limits

type Limits struct {
	MaxMetadataBytes      int64 `json:"max_metadata_bytes"`
	MaxDataBytes          int64 `json:"max_data_bytes"`
	InitialStreamWindow   int64 `json:"initial_stream_window"`
	MaxQueuedSessionBytes int64 `json:"max_queued_session_bytes"`
	MaxConcurrentStreams  int   `json:"max_concurrent_streams"`
}

func NormalizeV2Limits added in v0.0.14

func NormalizeV2Limits(limits Limits) (Limits, error)

func SelectDirectLimits added in v0.0.14

func SelectDirectLimits(source, target Limits) (Limits, error)

type Open

type Open struct {
	ProbePolicy    ProbePolicy                   `json:"probe_policy,omitempty"`
	Method         string                        `json:"method"`
	Path           string                        `json:"path"`
	Header         map[string][]string           `json:"header"`
	BodyLength     int64                         `json:"body_length"`
	RemainingNanos int64                         `json:"remaining_nanos"`
	RequestID      string                        `json:"request_id"`
	SourceAgentID  string                        `json:"source_agent_id"`
	TargetAgentID  string                        `json:"target_agent_id"`
	RouteID        uint                          `json:"route_id"`
	Hop            uint8                         `json:"hop"`
	ResponseWindow int64                         `json:"response_window"`
	Attempt        *attemptwire.AttemptProxyMeta `json:"attempt,omitempty"`
	API            *apiattempt.APIAttemptMeta    `json:"api,omitempty"`
	WebSocket      *WebSocketOpen                `json:"websocket,omitempty"`
}

func (Open) IsConnectivityProbe

func (o Open) IsConnectivityProbe() bool

func (Open) StreamKind added in v0.0.16

func (o Open) StreamKind() (OpenStreamKind, error)

type OpenStreamKind added in v0.0.16

type OpenStreamKind uint8
const (
	OpenStreamProbe OpenStreamKind = iota + 1
	OpenStreamAttempt
	OpenStreamAPI
)

type ParsedURI

type ParsedURI struct {
	URI       *url.URL
	Sanitized string
}

func ParseRelayURI

func ParseRelayURI(raw string) (ParsedURI, error)

type ProbePolicy added in v0.0.14

type ProbePolicy string
const (
	ProbeRespectBusinessPolicy ProbePolicy = "respect_business_policy"
	ProbeBypassBusinessPolicy  ProbePolicy = "bypass_business_policy"
)

type Ready

type Ready struct {
	RequestWindow int64 `json:"request_window"`
}

type Reset

type Reset struct {
	Code      string `json:"code"`
	Stage     string `json:"stage"`
	Committed bool   `json:"committed"`
}

type StreamID

type StreamID [16]byte

func NewStreamID

func NewStreamID() (StreamID, error)

type Trailers

type Trailers struct {
	Header  map[string][]string `json:"header,omitempty"`
	Dynamic []string            `json:"dynamic,omitempty"`
}

type Type

type Type uint8
const (
	FrameOpen Type = iota + 1
	FrameReady
	FrameCommit
	FrameCommitted
	FrameRequestData
	FrameRequestEnd
	FrameHeaders
	FrameResponseData
	FrameAttemptResult
	FrameEnd
	FrameCancel
	FrameReset
	FrameWindowUpdate
	FrameAPIResult
	FrameWebSocketMessageStart
	FrameWebSocketMessageData
	FrameWebSocketMessageEnd
	FrameWebSocketPing
	FrameWebSocketPong
	FrameWebSocketClose
)

type WebSocketAccepted added in v0.0.16

type WebSocketAccepted struct {
	RequestWindow  int64               `json:"request_window"`
	Subprotocol    string              `json:"subprotocol,omitempty"`
	ProviderStatus int                 `json:"provider_status,omitempty"`
	Rejection      *WebSocketRejection `json:"rejection,omitempty"`
}

type WebSocketEvent added in v0.0.16

type WebSocketEvent struct {
	Kind      WebSocketEventKind
	MessageID uint64
	Type      int
	Data      []byte
	Code      int
	Reason    string
}

func DecodeWebSocketClose added in v0.0.16

func DecodeWebSocketClose(payload []byte) (WebSocketEvent, error)

type WebSocketEventKind added in v0.0.16

type WebSocketEventKind uint8
const (
	WebSocketMessageStartEvent WebSocketEventKind = iota + 1
	WebSocketMessageDataEvent
	WebSocketMessageEndEvent
	WebSocketPingEvent
	WebSocketPongEvent
	WebSocketCloseEvent
)

type WebSocketMessageStart added in v0.0.16

type WebSocketMessageStart struct {
	MessageID uint64 `json:"message_id"`
	Type      int    `json:"type"`
}

type WebSocketOpen added in v0.0.16

type WebSocketOpen struct {
	ResponseWindow int64 `json:"response_window"`
}

type WebSocketRejection added in v0.0.16

type WebSocketRejection struct {
	StatusCode      int                 `json:"status_code"`
	Header          map[string][]string `json:"header,omitempty"`
	Body            []byte              `json:"body,omitempty"`
	HeaderTruncated bool                `json:"header_truncated,omitempty"`
	BodyTruncated   bool                `json:"body_truncated,omitempty"`
}

type Welcome

type Welcome struct {
	NonceProof        string   `json:"nonce_proof"`
	MasterInstanceID  string   `json:"master_instance_id"`
	SessionGeneration uint64   `json:"session_generation"`
	Capabilities      []string `json:"capabilities"`
	Limits            Limits   `json:"limits"`
}

type WindowUpdate

type WindowUpdate struct {
	Bytes int64 `json:"bytes"`
}

Jump to

Keyboard shortcuts

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