Skip to main content

Module shared_tunnel

Module shared_tunnel 

Source
Expand description

Machine-wide shared quick-tunnel record, file-protocol compatible with greentic-start (greentic-start/src/tunnel_state.rs).

A quick tunnel fronts exactly one local port, so one tunnel per (machine, port) is both necessary and sufficient. Setup and the runtime both honour a shared on-disk record instead of each spawning (and previously killing) their own cloudflared:

  • pidfile: <root>/state/pids/shared.cloudflared-<port>/cloudflared.pid
  • URL cache: <root>/state/runtime/shared.cloudflared-<port>/public_base_url.txt
  • log: <root>/logs/shared.cloudflared-<port>/cloudflared.log
  • spawn lock: <root>/state/cloudflared-<port>.lock

<root> is ~/.greentic/tunnel (override: GREENTIC_TUNNEL_STATE_DIR). greentic-setup does not depend on greentic-start, so this module implements the same protocol independently; changing these paths is a cross-repo protocol change. Only processes recorded here are ever terminated — never by name.

Structs§

SharedTunnelPaths
On-disk paths of the shared cloudflared record for one local port.
TunnelLock
Advisory file lock guarding the check-then-spawn critical section: exists while held, reclaimed when stale. Dropping releases it.

Functions§

clear_record
local_port_from_base_url
Local port a tunnel for local_base_url would be keyed on.
probe_tunnel_alive
Probe with retries until REUSE_PROBE_TIMEOUT elapses.
read_record
Read the recorded (pid, url) pair; either half may be absent.
shared_tunnel_paths
terminate_recorded_pid
Terminate the recorded process. Only ever called with a PID read from the shared record — ownership is proven by the record, never by process name.
write_record
Publish a spawned tunnel into the shared record so other Greentic processes (greentic-start in particular) reuse it instead of respawning.