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
- func ClientHandshake(stream FrameStream, peerVersion string, tunnelType holtv1.TunnelType) error
- func GoAwayReason(err error) string
- func ServerHandshake(stream FrameStream) (*holtv1.Hello, error)
- func TerminalReason(reason string) bool
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LastError() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(p []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SendGoAway(reason string) error
- func (c *Conn) SetDeadline(time.Time) error
- func (c *Conn) SetReadDeadline(time.Time) error
- func (c *Conn) SetWriteDeadline(time.Time) error
- func (c *Conn) Write(p []byte) (int, error)
- type ConnOption
- type FrameStream
- type GoAwayError
Constants ¶
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".
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.
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 ¶
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 ¶
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 ¶
Close seals the adapter (see the type comment) and runs the configured close func once.
func (*Conn) LastError ¶
LastError returns the first terminal read error; a GoAway from the far end surfaces here with its reason intact.
func (*Conn) Read ¶
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 (*Conn) SendGoAway ¶
SendGoAway emits a GoAway frame under the write mutex so it can never interleave with a data frame.
func (*Conn) SetDeadline ¶
Deadlines are accepted but not enforced: liveness comes from the HTTP/2 session's PING on top and the stream's own context.
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