Documentation
¶
Overview ¶
Package daemonctl is the local control channel for the optional background service (ADR-035). It lives in cli-core so both the daemon (which serves it) and the GUI (which probes "does a daemon already own receiving?") share one implementation. The transport is a per-user unix socket on Linux/macOS (a named pipe on Windows is Phase 3), authenticated by a 0600 per-user token; the protocol is one newline-delimited JSON request and response per connection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("another share2us daemon is already running")
ErrAlreadyRunning is returned by Listen when another daemon already holds the per-user control endpoint (the single-instance guard).
Functions ¶
func Listen ¶
Listen binds the per-user control endpoint and serves control requests with handler until the returned Closer is closed. Binding the endpoint is the single-instance lock: if another live daemon holds it, Listen returns ErrAlreadyRunning. A stale socket left by a crashed daemon (nobody answering a ping) is removed and rebound.
func LoadOrCreateToken ¶
LoadOrCreateToken returns the per-user control token, creating it (32 random bytes, hex, 0600) on first use. The token authenticates control requests so no other local user can drive this daemon.
func OwnsReceiver ¶
func OwnsReceiver() bool
OwnsReceiver reports whether a running daemon is holding the account-inbox and/or LAN receiver, so a second process (the GUI tray) can defer to it instead of double-binding the LAN port or double-downloading the inbox.
Types ¶
type Request ¶
Request is a control-channel message. Every request must carry the per-user token; a mismatch is rejected. Ops: "ping" (liveness), "status" (pid/version/uptime/what it owns), "stop" (self-cancel), "owns-receiver" (the cheap probe the GUI uses to decide whether to run its own receiver).
type Response ¶
type Response struct {
OK bool `json:"ok"`
PID int `json:"pid,omitempty"`
Version string `json:"version,omitempty"`
OwnsLAN bool `json:"owns_lan,omitempty"`
OwnsInbox bool `json:"owns_inbox,omitempty"`
Since string `json:"since,omitempty"`
Err string `json:"err,omitempty"`
}
Response is the reply to a Request.