vmrelay

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 19 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 hold 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.38"

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

Variables

This section is empty.

Functions

func HostHolder added in v0.14.0

func HostHolder(addr netip.Addr) ([]string, error)

HostHolder looks addr up among the host's interfaces.

Types

type Decision

type Decision struct {
	On bool
	// VM: the runtime is a VM runtime, whose networks the host cannot
	// route into.
	VM bool
	// Forced: GCPEMU_VM_RELAY decided On, not the runtime.
	Forced bool
	Reason string
}

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

func Decide

func Decide(goos string, inContainer bool, info runtime.Info, n runtime.Network, holder Holder) 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 on a VM runtime. On a goos other than Linux every runtime is one (ADR 0056). On Linux it is one when it says it is Docker Desktop or rootless, or when the bridge it reports for network n does not hold n's gateway on the host, as holder finds it (ADR 0058): a bind would pass on any adapter holding the address, e.g. a VPN, libvirt's virbr0 or another runtime's docker0 (#915).

func DecideDefault added in v0.14.0

func DecideDefault(ctx context.Context, goos string, inContainer bool, cl *runtime.Client, info runtime.Info, holder Holder) (d Decision, ok bool)

DecideDefault decides as Decide does, with the runtime's default bridge network standing in for the services network; ok is false when there is none. On Linux the relay is then off unless forced or the runtime says it is a VM runtime, since no network shows it is one.

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 runtime is a VM runtime, rather than forced: the host then cannot route to container networks, which live in the runtime's VM.

type Holder added in v0.14.0

type Holder func(addr netip.Addr) ([]string, error)

Holder names the host interfaces that hold addr, none when no interface does.

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. When the runtime's port forward stalls, it recreates the relay once (ADR 0050).

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