daemonctl

package
v0.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: GPL-3.0 Imports: 14 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Listen(handler func(Request) Response) (io.Closer, error)

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

func LoadOrCreateToken() (string, error)

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.

func Running

func Running() bool

Running reports whether a daemon currently answers on the control endpoint.

Types

type Request

type Request struct {
	Token string `json:"token"`
	Op    string `json:"op"`
}

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.

func Query

func Query(op string) (Response, bool)

Query sends a control request to a running daemon, loading the token from disk. It returns (Response, true) when a daemon answered, or (_, false) when none is reachable. Used by `daemon status`/`stop` and the GUI handoff probe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL