Expand description
The serving loops behind microvm tunnel and microvm port-forward, and behind the SDKs’
tunnel and port-forward handles (#263).
Each loop accepts a local connection, serves it on a task of its own, and counts how it
ended. The three things the CLI used to own are parameters: a stop future (the CLI’s Ctrl-C,
a handle’s stop()), a limit on how many connections to accept, and a callback that hears
about each connection’s end, so a caller can print a warning or keep a list. A connection
that fails never ends the loop; only the stop, the limit, or a listener that stops accepting
does. The report’s counts are computed here, once, for every surface.
§Every connection gets a task, both loops alike
One WebSocket per tunnel connection matches the daemon’s no-multiplexing decision, and one
task per forwarded connection means a slow request (a long poll, a first compile) doesn’t
hold the browser’s next one behind it, which the CLI’s port-forward used to do. When the
loop stops accepting, it waits for the connections already open to end: a task still
relaying holds bytes the local client is waiting for, and dropping it would cut them short.
Only an SDK handle cuts them, when its caller’s stop gives a grace that runs out or the
handle is dropped.
§A direct session serves too
A session with no proxy credential reaches the daemon without the endpoint proxy. The
tunnel then offers no proxy subprotocols, and the daemon’s bearer check is the gate; the
forwarder mints no proxy headers and sends each request to the endpoint’s host at the guest
port (super::forward::direct_url), since there is no proxy to route it by header.
Structs§
- Connection
End - One connection that didn’t end clean. A clean end is only counted, so a long-lived handle’s report grows with its failures, not with its traffic.
- Forward
Report - What a port-forward loop did.
- Forward
Summary - What a port-forward handle did: the loop’s report, and each connection that didn’t end clean.
- Serve
Limits - When a loop stops on its own, besides its caller’s stop.
- Serving
- A serving loop on a background task: the SDKs’ tunnel and port-forward handles.
- Tunnel
Connection - How one tunnel connection ended.
- Tunnel
Report - What a tunnel loop did.
- Tunnel
Summary - What a tunnel handle did: the loop’s report, and each connection that didn’t end clean.
- Tunnel
Target - What a tunnel reaches: the daemon, the guest port, and the credentials to present.
Enums§
- EndKind
- How a connection that didn’t end clean ended, as a handle’s report lists it.
- Forward
Notice - Something one forwarded connection did, for a caller’s warnings.
- Stop
Reason - Why a loop stopped accepting.
Constants§
- DEFAULT_
BIND - The shared listener default, retained at its existing public path.
Functions§
- bind_
address - A local address to listen on:
bindwhen given,DEFAULT_BINDotherwise. - serve_
forward - Serves
listeneras an HTTP and WebSocket forward tospec’s guest port untilstopresolves, the limit is reached, or the listener fails, then waits for the open connections to end. - serve_
tunnel - Serves
listeneras a TCP tunnel totargetuntilstopresolves, the limit is reached, or the listener fails, then waits for the open connections to end. - start_
forward - Binds
bindand starts a port-forward toguest_portbehindendpointon the current tokio runtime: the SDKs’Session.port_forward.authisNonefor a direct session. - start_
tunnel - Binds
bindand starts a tunnel totargeton the current tokio runtime: the SDKs’Session.tunnel.