Help us shape the future of Go! Take the 2026 Go Developer Survey

tunnel

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion byte = 0x01

	StatusOK                 byte = 0x00
	StatusPortNotAllowed     byte = 0x01
	StatusDialFailed         byte = 0x02
	StatusUnsupportedVersion byte = 0x03
)

Variables

This section is empty.

Functions

func Bridge

func Bridge(ctx context.Context, stream net.Conn, tcp net.Conn)

Bridge copies data bidirectionally between a yamux stream and a TCP connection until one side closes or ctx is cancelled. Both connections are closed when Bridge returns.

func ReadStatus

func ReadStatus(r io.Reader) (byte, error)

ReadStatus reads a single status byte from r.

func WriteConnectHeader

func WriteConnectHeader(w io.Writer, port uint16) error

WriteConnectHeader writes a connect header to w.

func WriteStatus

func WriteStatus(w io.Writer, status byte) error

WriteStatus writes a single status byte to w.

Types

type ConnectHeader

type ConnectHeader struct {
	Version byte
	Port    uint16
}

ConnectHeader is the first message sent on each yamux stream by the client.

func ReadConnectHeader

func ReadConnectHeader(r io.Reader) (ConnectHeader, error)

ReadConnectHeader reads a connect header from r.

type WSAdapter

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

WSAdapter wraps a *websocket.Conn to implement io.ReadWriteCloser, bridging gorilla/websocket's message-based API to the byte-stream interface that yamux requires.

func NewWSAdapter

func NewWSAdapter(conn *websocket.Conn) *WSAdapter

NewWSAdapter creates a new adapter around the given WebSocket connection.

func (*WSAdapter) Close

func (a *WSAdapter) Close() error

Close sends a close frame and closes the underlying connection.

func (*WSAdapter) Read

func (a *WSAdapter) Read(p []byte) (int, error)

Read implements io.Reader. It buffers partially-read WebSocket messages so callers can read arbitrary byte counts.

Read is NOT safe for concurrent use. This is intentional: yamux guarantees a single reader goroutine (recvLoop). Write uses mu because yamux writes from multiple goroutines (data, pings, window updates).

Do NOT add a mutex here. Close() must be callable concurrently to unblock a NextReader() blocked on the connection. If Read held a mutex that Close also acquired, Close would deadlock waiting for Read, while Read is blocked on NextReader waiting for Close to shut the connection.

func (*WSAdapter) Write

func (a *WSAdapter) Write(p []byte) (int, error)

Write implements io.Writer. Each call sends one binary WebSocket message.

Jump to

Keyboard shortcuts

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