wire

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 10 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 wire holds what the hub and dial halves of the tunnel share: the frame-level net.Conn adapter, the handshake, and the GoAway vocabulary.

Index

Constants

View Source
const (
	ReasonSuperseded   = "superseded"
	ReasonTokenRevoked = "token-revoked"
	ReasonShuttingDown = "shutting-down"
	ReasonPeerStopping = "peer-stopping"
	// ReasonClosed is an operator-initiated close (e.g. an admin
	// "kill"): terminal, so the peer stops redialing until it is
	// restarted or re-enrolled.
	ReasonClosed = "closed"
)

Well-known GoAway reasons. Superseded, credential revocation, and deliberate stop are terminal for the peer (no redial); everything else means "redial with backoff".

View Source
const MaxDataFrame = 32 * 1024

MaxDataFrame caps one TunnelFrame data payload — keeps inner HTTP/2 stream interleaving granular and each WebSocket message small enough for any intermediary.

View Source
const ProtocolVersion = 1

ProtocolVersion is the tunnel framing version spoken by this module, offered in Hello and confirmed in Welcome.

Variables

This section is empty.

Functions

func ClientHandshake

func ClientHandshake(stream FrameStream, peerVersion string, tunnelType holtv1.TunnelType) error

ClientHandshake sends Hello and requires Welcome as the first reply. Called by the dial side on a fresh stream.

func GoAwayReason

func GoAwayReason(err error) string

GoAwayReason returns the GoAway reason carried by err, or "" when err is not a GoAway.

func ServerHandshake

func ServerHandshake(stream FrameStream) (*holtv1.Hello, error)

ServerHandshake requires Hello as the first frame and answers Welcome. Called by the hub on a fresh stream. Returns the peer's Hello for observability.

func TerminalReason

func TerminalReason(reason string) bool

TerminalReason reports whether a GoAway reason tells the peer to stop redialing.

Types

type Conn

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

Conn adapts an attached FrameStream to a net.Conn carrying raw bytes as TunnelFrame data frames. Read is single-reader — the HTTP/2 session on top owns it — and writes are serialised internally because frame streams do not allow concurrent sends.

Close seals the adapter: it waits out any in-flight write, then makes every later I/O attempt fail locally with net.ErrClosed instead of reaching the stream. Hub handlers rely on this — the HTTP/2 transport's background goroutines (ping, resets) outlive the handler, and a late write must never reach a finished handler's socket.

func NewConn

func NewConn(stream FrameStream, opts ...ConnOption) *Conn

NewConn wraps an attached (post-handshake) stream.

func (*Conn) Close

func (c *Conn) Close() error

Close seals the adapter (see the type comment) and runs the configured close func once.

func (*Conn) LastError

func (c *Conn) LastError() error

LastError returns the first terminal read error; a GoAway from the far end surfaces here with its reason intact.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

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

Read returns buffered tunnel bytes, receiving the next data frame when the buffer is empty. A GoAway ends the stream with io.EOF after recording the reason (see LastError).

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SendGoAway

func (c *Conn) SendGoAway(reason string) error

SendGoAway emits a GoAway frame under the write mutex so it can never interleave with a data frame.

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(time.Time) error

Deadlines are accepted but not enforced: liveness comes from the HTTP/2 session's PING on top and the stream's own context.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(time.Time) error

func (*Conn) Write

func (c *Conn) Write(p []byte) (int, error)

Write chunks p into data frames of at most MaxDataFrame bytes.

type ConnOption

type ConnOption func(*Conn)

ConnOption configures a Conn.

func WithCloseFunc

func WithCloseFunc(fn func() error) ConnOption

WithCloseFunc runs fn once when the Conn is closed — the dial side passes the stream's CloseSend so the hub sees a clean EOF.

func WithSides

func WithSides(local, remote string) ConnOption

WithSides labels LocalAddr/RemoteAddr for logs ("hub"/"peer").

type FrameStream

type FrameStream interface {
	Send(*holtv1.TunnelFrame) error
	Recv() (*holtv1.TunnelFrame, error)
}

FrameStream is the frame-level view of an attached tunnel: one TunnelFrame per Send/Recv. NewWSStream adapts a WebSocket connection to it; tests may substitute in-memory implementations.

func NewWSStream

func NewWSStream(ctx context.Context, c *websocket.Conn) FrameStream

NewWSStream wraps an open WebSocket connection as a FrameStream. ctx bounds every send and receive — pass the context that governs the connection's lifetime (the attach context on the peer, the request context on the hub).

type GoAwayError

type GoAwayError struct{ Reason string }

GoAwayError carries the far end's GoAway reason.

func (GoAwayError) Error

func (e GoAwayError) Error() string

Jump to

Keyboard shortcuts

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