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
- type Decision
- type Options
- type Relay
- func (r *Relay) Close(ctx context.Context) error
- func (r *Relay) Covers(ip string) bool
- func (r *Relay) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (r *Relay) ID() string
- func (r *Relay) IP() string
- func (r *Relay) Listen(ctx context.Context, name, addr string, withUDP bool) (string, error)
- func (r *Relay) Offer(ctx context.Context, name, addr string, udp bool) error
- func (r *Relay) Streams() map[string]int64
- func (r *Relay) Withdraw(ctx context.Context, name string) error
Constants ¶
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.
const Env = "GCPEMU_VM_RELAY"
Env forces the relay on ("1") or off ("0").
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 ¶
This section is empty.
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
Reason string
}
Decision says whether an Instance uses the relay, and why.
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 ¶
Start creates the relay container, joins it to every network the Instance has and creates, and connects to it.
func (*Relay) DialContext ¶
DialContext connects to addr on a container network through the relay.
func (*Relay) Listen ¶
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
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.