Documentation
¶
Overview ¶
Package application holds Kumo's use cases. The desktop app, the CLI and the guardian process all drive the same services, so every surface starts, stops and configures the core the same way.
Index ¶
- Constants
- func GroupsFromConfig(config string) ([]proxy.Group, error)
- func Prompt(page, intent string) (string, error)
- type Bus
- type Check
- type CoreExited
- type CoreSettings
- type Dependencies
- type Event
- type Guide
- type ImportRequest
- type InspectService
- func (s *InspectService) CloseConnection(ctx context.Context, id string) error
- func (s *InspectService) Connections(ctx context.Context) (inspect.Connections, error)
- func (s *InspectService) Providers(ctx context.Context) ([]inspect.ProxyProvider, []inspect.RuleProvider, error)
- func (s *InspectService) RecentLogs(limit int) ([]inspect.LogEntry, error)
- func (s *InspectService) Rules(ctx context.Context) ([]inspect.Rule, error)
- func (s *InspectService) SetRuleEnabled(ctx context.Context, index int, enabled bool) error
- func (s *InspectService) StreamLogs(ctx context.Context, level string)
- func (s *InspectService) StreamTraffic(ctx context.Context)
- func (s *InspectService) UpdateProvider(ctx context.Context, kind, name string) error
- func (s *InspectService) UpgradeGeoData(ctx context.Context) error
- func (s *InspectService) Version(ctx context.Context) (inspect.Version, error)
- type Intent
- type Kumo
- type Lifecycle
- func (l *Lifecycle) Monitor(ctx context.Context)
- func (l *Lifecycle) Recover() (Status, error)
- func (l *Lifecycle) Refresh() (Status, error)
- func (l *Lifecycle) Reload(ctx context.Context) error
- func (l *Lifecycle) Restart(ctx context.Context, opts StartOptions) (Status, error)
- func (l *Lifecycle) RuntimeConfig(rt core.Runtime) (string, error)
- func (l *Lifecycle) Shutdown(ctx context.Context) ShutdownReport
- func (l *Lifecycle) Start(ctx context.Context, opts StartOptions) (Status, error)
- func (l *Lifecycle) Status() (Status, error)
- func (l *Lifecycle) Stop(ctx context.Context) (Status, error)
- type LogReceived
- type OverrideDetail
- type OverrideService
- func (s *OverrideService) Delete(ctx context.Context, id string) error
- func (s *OverrideService) Get(id string) (OverrideDetail, error)
- func (s *OverrideService) List() ([]override.Override, error)
- func (s *OverrideService) Reorder(ctx context.Context, ids []string) error
- func (s *OverrideService) Save(ctx context.Context, req SaveRequest) (override.Override, error)
- func (s *OverrideService) SetDisabled(ctx context.Context, id string, disabled bool) error
- type PreferenceService
- type ProfileService
- func (s *ProfileService) Content(id string) (string, error)
- func (s *ProfileService) Delete(ctx context.Context, id string) error
- func (s *ProfileService) Get(id string) (profile.Summary, error)
- func (s *ProfileService) Import(ctx context.Context, req ImportRequest) (profile.Summary, error)
- func (s *ProfileService) List() ([]profile.Summary, error)
- func (s *ProfileService) Refresh(ctx context.Context, id string) (profile.Summary, error)
- func (s *ProfileService) RefreshDue(ctx context.Context) ([]profile.Summary, error)
- func (s *ProfileService) Select(ctx context.Context, id string) error
- func (s *ProfileService) Update(ctx context.Context, req UpdateRequest) (profile.Summary, error)
- type ProfilesChanged
- type ProxyService
- func (s *ProxyService) Groups(ctx context.Context) ([]proxy.Group, error)
- func (s *ProxyService) Select(ctx context.Context, group, name string) error
- func (s *ProxyService) TestGroup(ctx context.Context, group string) (map[string]int, error)
- func (s *ProxyService) TestNode(ctx context.Context, name, testURL string) (int, error)
- type Report
- type SaveRequest
- type SettingsService
- func (s *SettingsService) Get() (CoreSettings, error)
- func (s *SettingsService) GrantTUN(ctx context.Context) (TUNPermission, error)
- func (s *SettingsService) InstallCore(ctx context.Context) (mihomo.Installed, error)
- func (s *SettingsService) SetController(ctx context.Context, host string, port int, secret *string) (Status, error)
- func (s *SettingsService) SetCorePath(path string) error
- func (s *SettingsService) SetMode(ctx context.Context, mode core.Mode) (Status, error)
- func (s *SettingsService) SetTUN(ctx context.Context, enabled bool) (Status, error)
- func (s *SettingsService) Update(ctx context.Context, settings core.RuntimeSettings) (Status, error)
- type ShutdownReport
- type StartOptions
- type Status
- type StatusChanged
- type Step
- type SystemProxyContended
- type SystemProxyService
- func (s *SystemProxyService) Apply() (SystemProxyStatus, error)
- func (s *SystemProxyService) Check()
- func (s *SystemProxyService) Release() error
- func (s *SystemProxyService) Services() ([]string, error)
- func (s *SystemProxyService) SetEnabled(enabled bool) (Status, error)
- func (s *SystemProxyService) UpdateSettings(settings systemproxy.Settings) (Status, error)
- type SystemProxyStatus
- type TUNPermission
- type TopologyService
- type TrafficSampled
- type UpdateRequest
Constants ¶
const DelayTimeout = 5 * time.Second
DelayTimeout bounds one delay test.
Variables ¶
This section is empty.
Functions ¶
func GroupsFromConfig ¶
GroupsFromConfig reads proxy groups out of a configuration.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus fans events out to subscribers. Publishing never blocks on a slow subscriber's work: subscribers return quickly or hand off.
type CoreExited ¶
CoreExited reports a core that ended without Kumo stopping it.
type CoreSettings ¶
type CoreSettings struct {
Mode core.Mode `json:"mode"`
Settings core.RuntimeSettings `json:"settings"`
ControllerHost string `json:"controllerHost"`
ControllerPort int `json:"controllerPort"`
HasSecret bool `json:"hasSecret"`
CorePath string `json:"corePath"`
Candidates []mihomo.Candidate `json:"candidates"`
TUNPermission TUNPermission `json:"tunPermission"`
}
CoreSettings is what the Core and Configure pages edit.
type Dependencies ¶
type Dependencies struct {
Paths paths.Paths
Runtime core.Store
Profiles profile.Repository
Overrides override.Repository
Preferences preferences.Store
SystemProxy systemproxy.Platform
Fetcher interface {
profile.Fetcher
Get(url string, proxyPort int) ([]byte, map[string][]string, error)
}
Transformer runtimeconfig.Transformer
// Owner is the surface these services run in.
Owner core.Owner
// BundledDir holds a Mihomo shipped with the app, if any.
BundledDir string
// ReadyTimeout bounds how long a start waits for the controller.
ReadyTimeout time.Duration
// WatchInterval is how often the system proxy is checked for
// contention while Kumo holds it.
WatchInterval time.Duration
Now func() time.Time
}
Dependencies are the adapters the services run on. Tests and simulations swap the system proxy for an in-memory one.
func DefaultDependencies ¶
func DefaultDependencies(p paths.Paths, owner core.Owner) Dependencies
DefaultDependencies wires the real adapters under p.
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is something the surfaces may want to show.
type ImportRequest ¶
type ImportRequest struct {
URL string `json:"url,omitempty"`
Path string `json:"path,omitempty"`
YAML string `json:"yaml,omitempty"`
Name string `json:"name,omitempty"`
// UseProxy fetches the URL through the running core.
UseProxy bool `json:"useProxy,omitempty"`
// Activate makes the imported profile current.
Activate bool `json:"activate,omitempty"`
}
ImportRequest describes a profile to import from a URL, a file or text.
type InspectService ¶
type InspectService struct {
// contains filtered or unexported fields
}
InspectService reads what a running core reports.
func (*InspectService) CloseConnection ¶
func (s *InspectService) CloseConnection(ctx context.Context, id string) error
CloseConnection closes one connection, or every one when id is "".
func (*InspectService) Connections ¶
func (s *InspectService) Connections(ctx context.Context) (inspect.Connections, error)
Connections lists open connections with per-connection speeds, computed from the change since the previous call.
func (*InspectService) Providers ¶
func (s *InspectService) Providers(ctx context.Context) ([]inspect.ProxyProvider, []inspect.RuleProvider, error)
Providers lists proxy and rule providers.
func (*InspectService) RecentLogs ¶
func (s *InspectService) RecentLogs(limit int) ([]inspect.LogEntry, error)
RecentLogs reads the last lines of the core's log file.
func (*InspectService) SetRuleEnabled ¶
SetRuleEnabled turns a rule off or on until the core restarts.
func (*InspectService) StreamLogs ¶
func (s *InspectService) StreamLogs(ctx context.Context, level string)
StreamLogs publishes log lines at level and above while ctx lives.
func (*InspectService) StreamTraffic ¶
func (s *InspectService) StreamTraffic(ctx context.Context)
StreamTraffic publishes throughput every second while the core runs and ctx lives, reconnecting when the core restarts.
func (*InspectService) UpdateProvider ¶
func (s *InspectService) UpdateProvider(ctx context.Context, kind, name string) error
UpdateProvider refreshes a proxy ("proxy") or rule ("rule") provider.
func (*InspectService) UpgradeGeoData ¶
func (s *InspectService) UpgradeGeoData(ctx context.Context) error
UpgradeGeoData downloads fresh geo databases.
type Intent ¶
Intent is one thing a user may want an agent to do on a page, with the kumo commands that do it.
type Kumo ¶
type Kumo struct {
Events *Bus
Lifecycle *Lifecycle
SystemProxy *SystemProxyService
Profiles *ProfileService
Overrides *OverrideService
Proxies *ProxyService
Inspect *InspectService
Settings *SettingsService
Topology *TopologyService
Preferences *PreferenceService
// contains filtered or unexported fields
}
Kumo is every use case, sharing one set of adapters and one event bus.
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle starts, stops and watches the core.
func (*Lifecycle) Monitor ¶
Monitor keeps the status current while ctx lives: it notices cores that other surfaces start or stop, and system proxy changes by other apps.
func (*Lifecycle) Recover ¶
Recover is the first thing the app does: it adopts a core that still runs from an earlier session, records one that died, and takes Kumo's settings out of the system when no core serves them any more.
func (*Lifecycle) Reload ¶
Reload rebuilds the configuration and has the running core read it, keeping its process and connections. When the core is off, it only writes the file for the next start.
func (*Lifecycle) RuntimeConfig ¶
RuntimeConfig builds the configuration the core would run with now.
func (*Lifecycle) Shutdown ¶
func (l *Lifecycle) Shutdown(ctx context.Context) ShutdownReport
Shutdown is the quit path: release the system proxy and stop the core, whichever surface started it. Every step runs even when an earlier one failed, and failures are reported rather than returned, so the app can always quit.
func (*Lifecycle) Start ¶
Start launches the core with the current profile and waits until its controller answers.
type LogReceived ¶
LogReceived carries one line of the core's log.
type OverrideDetail ¶
OverrideDetail is an override with its content.
type OverrideService ¶
type OverrideService struct {
// contains filtered or unexported fields
}
OverrideService manages the overrides applied on top of every profile.
func (*OverrideService) Delete ¶
func (s *OverrideService) Delete(ctx context.Context, id string) error
Delete removes an override.
func (*OverrideService) Get ¶
func (s *OverrideService) Get(id string) (OverrideDetail, error)
Get returns an override with its content.
func (*OverrideService) List ¶
func (s *OverrideService) List() ([]override.Override, error)
List returns overrides in the order they apply.
func (*OverrideService) Reorder ¶
func (s *OverrideService) Reorder(ctx context.Context, ids []string) error
Reorder changes the order overrides apply in.
func (*OverrideService) Save ¶
func (s *OverrideService) Save(ctx context.Context, req SaveRequest) (override.Override, error)
Save validates and stores an override, then reloads a running core.
func (*OverrideService) SetDisabled ¶
SetDisabled turns an override off or on without deleting it.
type PreferenceService ¶
type PreferenceService struct {
// contains filtered or unexported fields
}
PreferenceService keeps app-level preferences.
func (*PreferenceService) Get ¶
func (s *PreferenceService) Get() (preferences.Preferences, error)
Get returns the preferences.
func (*PreferenceService) Save ¶
func (s *PreferenceService) Save(p preferences.Preferences) error
Save stores the preferences.
func (*PreferenceService) Update ¶
func (s *PreferenceService) Update(fn func(*preferences.Preferences)) (preferences.Preferences, error)
Update changes the preferences with fn and stores them.
type ProfileService ¶
type ProfileService struct {
// contains filtered or unexported fields
}
ProfileService imports, refreshes and switches profiles.
func (*ProfileService) Content ¶
func (s *ProfileService) Content(id string) (string, error)
Content returns a profile's YAML.
func (*ProfileService) Delete ¶
func (s *ProfileService) Delete(ctx context.Context, id string) error
Delete removes a profile; when it was current, the core switches to the next one.
func (*ProfileService) Get ¶
func (s *ProfileService) Get(id string) (profile.Summary, error)
Get returns one profile.
func (*ProfileService) Import ¶
func (s *ProfileService) Import(ctx context.Context, req ImportRequest) (profile.Summary, error)
Import adds a profile and, when asked, switches to it.
func (*ProfileService) List ¶
func (s *ProfileService) List() ([]profile.Summary, error)
List returns every profile, the current one marked.
func (*ProfileService) Refresh ¶
Refresh downloads a remote profile again, keeping its ID and settings.
func (*ProfileService) RefreshDue ¶
RefreshDue refreshes every remote profile whose interval has passed.
func (*ProfileService) Select ¶
func (s *ProfileService) Select(ctx context.Context, id string) error
Select makes a profile current and has a running core switch to it.
func (*ProfileService) Update ¶
func (s *ProfileService) Update(ctx context.Context, req UpdateRequest) (profile.Summary, error)
Update edits a profile's metadata and, optionally, its YAML.
type ProfilesChanged ¶
type ProfilesChanged struct{}
ProfilesChanged reports that profiles were added, changed or removed.
type ProxyService ¶
type ProxyService struct {
// contains filtered or unexported fields
}
ProxyService lists proxy groups, selects nodes and measures delays.
func (*ProxyService) Groups ¶
Groups returns the live groups of a running core. When the core is off it reads them from the configuration instead, marked not live: Mihomo decides the actual selection when it starts.
func (*ProxyService) Select ¶
func (s *ProxyService) Select(ctx context.Context, group, name string) error
Select picks a group's node and closes connections that used the old one, so traffic moves at once.
type Report ¶
type Report struct {
Status Status `json:"status"`
Checks []Check `json:"checks"`
Cores []mihomo.Candidate `json:"cores"`
SystemProxy *systemproxy.Snapshot `json:"observedSystemProxy,omitempty"`
DataDir string `json:"dataDir"`
Platform string `json:"platform"`
}
Report is a broad snapshot for diagnosing Kumo.
type SaveRequest ¶
type SaveRequest struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Format override.Format `json:"format"`
Content string `json:"content"`
URL string `json:"url,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
SaveRequest creates or edits an override. With a URL and no content, the content is downloaded.
type SettingsService ¶
type SettingsService struct {
// contains filtered or unexported fields
}
SettingsService changes how the core runs.
func (*SettingsService) Get ¶
func (s *SettingsService) Get() (CoreSettings, error)
Get returns the stored settings and the cores Kumo can find.
func (*SettingsService) GrantTUN ¶
func (s *SettingsService) GrantTUN(ctx context.Context) (TUNPermission, error)
GrantTUN asks the system for the permission TUN needs.
func (*SettingsService) InstallCore ¶
InstallCore downloads the latest Mihomo and selects it.
func (*SettingsService) SetController ¶
func (s *SettingsService) SetController(ctx context.Context, host string, port int, secret *string) (Status, error)
SetController moves the external controller, which takes a restart.
func (*SettingsService) SetCorePath ¶
func (s *SettingsService) SetCorePath(path string) error
SetCorePath chooses the Mihomo executable; "" goes back to discovery.
func (*SettingsService) SetMode ¶
SetMode switches the outbound mode, at once when the core runs, and closes connections so they follow the new mode.
func (*SettingsService) Update ¶
func (s *SettingsService) Update(ctx context.Context, settings core.RuntimeSettings) (Status, error)
Update replaces the runtime settings and reloads a running core.
type ShutdownReport ¶
type ShutdownReport struct {
Status Status `json:"status"`
Diagnostics []string `json:"diagnostics"`
}
ShutdownReport says what a shutdown did and what failed along the way.
type StartOptions ¶
type StartOptions struct {
// CorePath overrides the executable for this start.
CorePath string `json:"corePath,omitempty"`
// ResolvePortConflicts moves Kumo to free ports instead of failing when
// another process holds the mixed or controller port.
ResolvePortConflicts bool `json:"resolvePortConflicts,omitempty"`
}
StartOptions tune one start.
type Status ¶
type Status struct {
State core.RunState `json:"state"`
PID int `json:"pid,omitempty"`
Owner core.Owner `json:"owner,omitempty"`
Readiness core.Readiness `json:"readiness,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
Message string `json:"message,omitempty"`
Mode core.Mode `json:"mode"`
// Controller is the external controller's address.
Controller string `json:"controller"`
MixedPort int `json:"mixedPort"`
CorePath string `json:"corePath,omitempty"`
TUN bool `json:"tun"`
SystemProxy SystemProxyStatus `json:"systemProxy"`
Profile profile.Summary `json:"profile"`
LastExit *core.Exit `json:"lastExit,omitempty"`
}
Status is the runtime as the surfaces show it.
type StatusChanged ¶
type StatusChanged struct{ Status Status }
StatusChanged carries the new status after any change of the runtime.
type SystemProxyContended ¶
type SystemProxyContended struct {
Ownership systemproxy.Ownership `json:"ownership"`
Observed systemproxy.Snapshot `json:"observed"`
// Holder is the process listening where the system now points, when
// that is on this machine.
Holder string `json:"holder,omitempty"`
// Reclaimed is true when Kumo put its proxy back.
Reclaimed bool `json:"reclaimed"`
}
SystemProxyContended reports that another app changed the system proxy while Kumo had it.
type SystemProxyService ¶
type SystemProxyService struct {
// contains filtered or unexported fields
}
SystemProxyService points the operating system at the core, and notices when another app points it elsewhere.
func (*SystemProxyService) Apply ¶
func (s *SystemProxyService) Apply() (SystemProxyStatus, error)
Apply writes Kumo's settings into the system and checks that they took.
func (*SystemProxyService) Check ¶
func (s *SystemProxyService) Check()
Check looks whether the system still shows Kumo's settings. Another app's proxy is reported (and replaced, when the user asked Kumo to reclaim it); a proxy someone turned off stays off.
func (*SystemProxyService) Release ¶
func (s *SystemProxyService) Release() error
Release takes Kumo's settings out of the system, if they are still there. Settings another app put in since are left alone: Kumo never clears a proxy it does not own.
func (*SystemProxyService) Services ¶
func (s *SystemProxyService) Services() ([]string, error)
Services lists the network services the proxy can be set on.
func (*SystemProxyService) SetEnabled ¶
func (s *SystemProxyService) SetEnabled(enabled bool) (Status, error)
SetEnabled records the user's wish and acts on it: with the core running, Kumo's settings go into the system; turned off, they come out.
func (*SystemProxyService) UpdateSettings ¶
func (s *SystemProxyService) UpdateSettings(settings systemproxy.Settings) (Status, error)
UpdateSettings stores new settings and applies them when active.
type SystemProxyStatus ¶
type SystemProxyStatus struct {
// Enabled is what the user asked for; it survives restarts.
Enabled bool `json:"enabled"`
// Active is true while Kumo's settings are in the system.
Active bool `json:"active"`
Ownership systemproxy.Ownership `json:"ownership,omitempty"`
Settings systemproxy.Settings `json:"settings"`
Applied *systemproxy.Applied `json:"applied,omitempty"`
}
SystemProxyStatus is the system proxy as the surfaces show it.
type TUNPermission ¶
type TUNPermission struct {
Granted bool `json:"granted"`
// Method is how it was granted: "root" when Kumo itself runs as root,
// "setuid" when the core is owned by root with the setuid bit, or
// "capability" for Linux file capabilities.
Method string `json:"method,omitempty"`
}
TUNPermission says whether the core can create a TUN interface.
type TopologyService ¶
type TopologyService struct {
// contains filtered or unexported fields
}
TopologyService draws the configuration as a graph.
type TrafficSampled ¶
TrafficSampled carries one second of throughput.