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

driver

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package driver is the client side of the relay's data plane: what an engine uses to give its containers a network through the relay. One Session is one connection (one browser, or one native engine); each container attached to the class network is an Endpoint with Listen, Dial, ListenPacket and Resolve, returning ordinary net.Conn, net.Listener and net.PacketConn values that the engine maps the WasmEdge socket calls onto.

Errors carry the errno a socket call should return: a refused connect wraps syscall.ECONNREFUSED, a reset syscall.ECONNRESET, an unknown address syscall.EHOSTUNREACH, a port in use syscall.EADDRINUSE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HelloVersion

func HelloVersion(ctx context.Context, t Transport, version uint32) error

HelloVersion opens a session announcing another protocol version and returns the relay's refusal.

func SendRaw

func SendRaw(e *Endpoint, srcPort uint16, to netip.AddrPort, payload []byte) error

SendRaw sends a datagram claiming any source port.

Types

type Endpoint

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

Endpoint is one container's place on the class network.

func ForgeEndpoint

func ForgeEndpoint(s *Session, p *v1.Port) *Endpoint

ForgeEndpoint is an endpoint of s that names port p, whoever owns it.

func (*Endpoint) Addr

func (e *Endpoint) Addr() netip.Addr

Addr is the container's address.

func (*Endpoint) Detach

func (e *Endpoint) Detach() error

Detach takes the container off the network.

func (*Endpoint) Dial

func (e *Endpoint) Dial(ctx context.Context, network string, addr netip.AddrPort) (net.Conn, error)

Dial connects to addr ("tcp") or returns a connected datagram socket ("udp").

func (*Endpoint) Listen

func (e *Endpoint) Listen(ctx context.Context, network string, port uint16) (*Listener, error)

Listen listens on port ("tcp"; 0 picks an ephemeral one).

func (*Endpoint) ListenPacket

func (e *Endpoint) ListenPacket(ctx context.Context, network string, port uint16) (*PacketConn, error)

ListenPacket binds a UDP port (0 picks an ephemeral one).

func (*Endpoint) Port

func (e *Endpoint) Port() *v1.Port

Port is the relay's description of the endpoint.

func (*Endpoint) Resolve

func (e *Endpoint) Resolve(ctx context.Context, name string) ([]netip.Addr, error)

Resolve looks a name up: "<container>", "<container>.<student>" or "<container>.<student>.<domain>".

type Error

type Error struct {
	Code  v1.Code
	Msg   string
	Errno syscall.Errno
}

Error is a refusal from the relay, with the errno a socket call returns.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Listener

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

Listener accepts streams on one port. It implements net.Listener.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for the next connection.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr is the listening address.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening.

func (*Listener) Port

func (l *Listener) Port() uint16

Port is the listening port.

type PacketConn

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

PacketConn is a bound UDP socket. It implements net.PacketConn.

func (*PacketConn) Close

func (pc *PacketConn) Close() error

Close unbinds the port.

func (*PacketConn) LocalAddr

func (pc *PacketConn) LocalAddr() net.Addr

func (*PacketConn) ReadFrom

func (pc *PacketConn) ReadFrom(p []byte) (int, net.Addr, error)

ReadFrom reads one datagram.

func (*PacketConn) SetDeadline

func (pc *PacketConn) SetDeadline(t time.Time) error

func (*PacketConn) SetReadDeadline

func (pc *PacketConn) SetReadDeadline(t time.Time) error

func (*PacketConn) SetWriteDeadline

func (pc *PacketConn) SetWriteDeadline(t time.Time) error

func (*PacketConn) WriteTo

func (pc *PacketConn) WriteTo(p []byte, addr net.Addr) (int, error)

WriteTo sends one datagram.

type Session

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

Session is one data connection to the relay.

func Dial

func Dial(ctx context.Context, t Transport) (*Session, error)

Dial starts a session over t (already authenticated by its transport: the WebSocket carries the session token in its handshake).

func DialWebSocket

func DialWebSocket(ctx context.Context, url, token string, hc *http.Client) (*Session, error)

DialWebSocket opens a session at url (wss://relay.example/v1/data) with a session token. The token travels as a WebSocket subprotocol, so it is checked before the upgrade and never appears in a URL. hc may be nil (in a browser, js/wasm, the browser's WebSocket is used and hc is ignored).

func (*Session) Attach

func (s *Session) Attach(ctx context.Context, container string) (*Endpoint, error)

Attach gives a container an address on the class network (the same one it had, if it was attached before).

func (*Session) Close

func (s *Session) Close() error

Close ends the session.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done is closed when the session ends; Err then says why.

func (*Session) Err

func (s *Session) Err() error

Err is why the session ended, or nil while it runs.

func (*Session) GoAway

func (s *Session) GoAway() *v1.Result

GoAway is the relay's last word, when it closed the session.

func (*Session) Reauth

func (s *Session) Reauth(token string) error

Reauth hands the relay a fresh session token; open flows stay.

func (*Session) Welcome

func (s *Session) Welcome() *v1.Welcome

Welcome is what the relay said about this session.

type Transport

type Transport interface {
	ReadMessage(ctx context.Context) ([]byte, error)
	WriteMessage(ctx context.Context, msg []byte) error
	Close(reason string) error
}

Transport is the message transport (relay.Transport has the same shape).

Jump to

Keyboard shortcuts

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