Documentation
¶
Index ¶
- Constants
- func ConfigPath() string
- func DetachAttr() *syscall.SysProcAttr
- func Dir() string
- func IsAlive(pid int) bool
- func LogPath() string
- func PidPath() string
- func ReadPid() (int, error)
- func Remove() error
- func RemovePid() error
- func Save(state State) error
- func SendStop(addr string, timeout time.Duration) error
- func StatePath() string
- func WritePid(pid int) error
- type ControlServer
- type Management
- type Snapshot
- type State
Constants ¶
const DirEnvVar = "VPNGATE_DAEMON_DIR"
DirEnvVar overrides the base directory Dir() resolves under. Tests (in this package and elsewhere) set it to isolate state files instead of touching the real default location.
Variables ¶
This section is empty.
Functions ¶
func ConfigPath ¶
func ConfigPath() string
ConfigPath returns the path to the daemon's persisted OpenVPN config.
func DetachAttr ¶
func DetachAttr() *syscall.SysProcAttr
DetachAttr returns the SysProcAttr that starts a child process in its own session, detached from the parent's controlling terminal and process group, so it survives the parent exiting.
func Dir ¶
func Dir() string
Dir returns the directory vpngate uses for daemon state, the persisted OpenVPN config, and the daemon log. It deliberately avoids both $HOME and os.TempDir()/$TMPDIR: daemon mode is typically launched with sudo (root), while status/disconnect are typically run as the invoking user, and both $HOME and $TMPDIR can differ between the two — on macOS in particular, $TMPDIR is a per-user path assigned by launchd (e.g. /var/folders/.../T/) that sudo does not preserve by default, so os.TempDir() alone resolves to two different directories for the same daemon depending on who's asking. defaultBaseDir() (unix/windows split) picks a single fixed, machine-wide location instead, so every invocation agrees regardless of privilege.
func PidPath ¶
func PidPath() string
PidPath returns the path of the file holding the supervisor's PID. The supervisor writes it at startup, before its first connection attempt, and removes it on exit. It lets a foreground `connect -d` tell "daemon died during startup" apart from "daemon still negotiating", and guards against starting a second daemon while the first hasn't written its state file yet (state is only written once the tunnel is up).
func ReadPid ¶
ReadPid returns the PID recorded by WritePid. Check os.IsNotExist(err) for "no daemon starting".
func Remove ¶
func Remove() error
Remove deletes StatePath(). It is not an error if the file is already gone.
func RemovePid ¶
func RemovePid() error
RemovePid deletes PidPath(). It is not an error if the file is already gone.
func Save ¶
Save writes state to StatePath(), creating Dir() if needed. The write is atomic, so a crash mid-save never leaves a half-written state file for the next `status` invocation to choke on.
Types ¶
type ControlServer ¶
type ControlServer struct {
// contains filtered or unexported fields
}
ControlServer is the supervisor side of the control protocol: a loopback TCP listener that answers STATUS and STOP requests from separate `vpngate status`/`vpngate disconnect` invocations. Neither of those commands touches OpenVPN's management socket directly — only the supervisor can tell "OpenVPN exited, reconnect" apart from "the user asked to disconnect".
func NewControlServer ¶
func NewControlServer(listener net.Listener, onStatus func() (Snapshot, error), onStop func()) *ControlServer
NewControlServer wraps an already-open listener. onStatus answers STATUS requests; onStop (may be nil) is invoked in its own goroutine, after the client has already been acknowledged, to tear the daemon down.
func (*ControlServer) Addr ¶
func (c *ControlServer) Addr() string
Addr returns the address clients should dial.
func (*ControlServer) Serve ¶
func (c *ControlServer) Serve()
Serve accepts connections until the listener is closed.
type Management ¶
type Management struct {
// contains filtered or unexported fields
}
Management is a client for OpenVPN's plaintext management protocol. It is used only by the supervisor process, which is the sole client of a given OpenVPN instance's management socket — status/disconnect never dial it directly (see docs/superpowers/specs/2026-07-22-daemon-mode-design.md).
func DialManagement ¶
func DialManagement(addr string, timeout time.Duration) (*Management, error)
DialManagement connects to addr and discards OpenVPN's greeting line.
func (*Management) Close ¶
func (m *Management) Close() error
Close closes the underlying connection.
func (*Management) Disconnect ¶
func (m *Management) Disconnect() error
Disconnect asks OpenVPN to shut down cleanly.
func (*Management) State ¶
func (m *Management) State() (string, error)
State queries OpenVPN's current connection state (e.g. "CONNECTED", "RECONNECTING", "EXITING").
type Snapshot ¶
type Snapshot struct {
State string `json:"state"`
HostName string `json:"hostname"`
IPAddr string `json:"ip_addr"`
CountryLong string `json:"country"`
StartedAt time.Time `json:"started_at"`
PID int `json:"pid"`
}
Snapshot is the supervisor's answer to a STATUS control request.
type State ¶
type State struct {
PID int `json:"pid"`
OpenVPNPID int `json:"openvpn_pid"`
ControlAddr string `json:"control_addr"`
HostName string `json:"hostname"`
IPAddr string `json:"ip_addr"`
CountryLong string `json:"country"`
StartedAt time.Time `json:"started_at"`
}
State is the on-disk record of a running daemon, written by the supervisor once OpenVPN reports a successful connection and read by `status`/`disconnect` in separate process invocations.