vmrelay

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 18 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 vmrelay implements the VM relay (ADR 0005). On a VM runtime (Docker Desktop, Colima, OrbStack, Podman machine) the container networks live inside a virtual machine: the host can neither route to container IPs nor bind the services network's gateway. The relay is a Managed container joined to every network the Instance uses, which publishes one control port on the host's 127.0.0.1. The emulator keeps one yamux session on it, over which it dials container addresses, and over which the relay hands it the connections and datagrams that Managed containers send to the emulator endpoints it listens for.

Index

Constants

View Source
const ControlPort = 7171

ControlPort is the port the agent serves the emulator on; the container publishes it on the host's 127.0.0.1.

View Source
const Env = "GCPEMU_VM_RELAY"

Env forces the relay on ("1") or off ("0").

View Source
const Image = "busybox:1.37"

Image runs the relay agent (any image works: the agent is a static binary).

Variables

This section is empty.

Functions

func DefaultGateway added in v0.10.0

func DefaultGateway(ctx context.Context, cl *runtime.Client) string

DefaultGateway is the gateway of the runtime's default bridge network, which stands in for the services network's gateway before the Instance creates it, or "" when there is none.

Types

type Decision

type Decision struct {
	On bool
	// VM: the gateway cannot be bound, so the runtime runs in a VM, whose
	// host network is not the host's.
	VM bool
	// Forced: GCPEMU_VM_RELAY decided On, not the gateway probe.
	Forced bool
	Reason string
}

Decision says whether an Instance uses the relay, and why.

func Decide

func Decide(inContainer bool, gateway string) Decision

Decide chooses: never when the emulator runs in a container (ADR 0003), since it is already on every network; otherwise as GCPEMU_VM_RELAY says; otherwise when the services network's gateway cannot be bound on the host, which is how a VM runtime shows.

func (Decision) String

func (d Decision) String() string

func (Decision) Unroutable added in v0.10.0

func (d Decision) Unroutable() bool

Unroutable reports whether the relay is on because the services network's gateway cannot be bound, rather than forced: the host then cannot route to container networks, which live in the runtime's VM.

type Options

type Options struct {
	// Services and External are the Instance's services and external
	// networks. The relay publishes its control port through External,
	// since a runtime publishes no ports of a container that is only on
	// internal networks.
	Services, External string
	// Target resolves an endpoint name to the host address it is served
	// at, for connections the relay hands in.
	Target func(name string) string
	Log    *slog.Logger
}

Options configure Start.

type Relay

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

Relay is the emulator's side of a running relay.

func Start

func Start(ctx context.Context, rt *runtime.Manager, o Options) (*Relay, error)

Start creates the relay container, joins it to every network the Instance has and creates, and connects to it.

func (*Relay) Close

func (r *Relay) Close(ctx context.Context) error

Close disconnects and removes the relay container.

func (*Relay) Control added in v0.10.0

func (r *Relay) Control() string

Control is the control port's current address on the host.

func (*Relay) Covers

func (r *Relay) Covers(ip string) bool

Covers reports whether ip lies on a network the relay has joined.

func (*Relay) DialContext

func (r *Relay) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext connects to addr on a container network through the relay.

func (*Relay) ID

func (r *Relay) ID() string

ID is the relay container's ID.

func (*Relay) IP

func (r *Relay) IP() string

IP is the relay's address on the services network.

func (*Relay) Listen

func (r *Relay) Listen(ctx context.Context, name, addr string, withUDP bool) (string, error)

Listen has the relay listen at addr (its own address on a network, or another port there when that one is taken) for the named emulator endpoint, with UDP as well when withUDP. It returns the address bound, and is idempotent per name.

func (*Relay) Offer added in v0.7.0

func (r *Relay) Offer(ctx context.Context, name, addr string, udp bool) error

Offer has the relay listen on exactly addr, over UDP when udp and TCP otherwise, for the named emulator endpoint: an Offered port (ADR 0014). Unlike Listen it fails when the port is taken. It is idempotent per name.

func (*Relay) Streams

func (r *Relay) Streams() map[string]int64

Streams returns how many streams the relay has carried per target: the container address for dials, the endpoint name for connections handed in, and the endpoint name with "/udp" for datagrams.

func (*Relay) Withdraw added in v0.7.0

func (r *Relay) Withdraw(ctx context.Context, name string) error

Withdraw has the relay stop listening for the named endpoint.

Jump to

Keyboard shortcuts

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