runtime

package
v0.9.0-dev.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: GPL-3.0 Imports: 25 Imported by: 0 modules, 0 packages

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddSubscriptionInput

type AddSubscriptionInput struct {
	Name string
	URL  string
	// ProxyMode selects the per-subscription refresh transport (direct/proxy/auto).
	ProxyMode string
}

type Controller

type Controller interface {
	Proxies(context.Context) (mihomo.Proxies, error)
	SelectProxy(context.Context, string, string) error
	DelayGroup(context.Context, string, string, int) (mihomo.Delays, error)
	DelayProxy(context.Context, string, string, int) (uint16, error)
	Connections(context.Context) (mihomo.Connections, error)
	CloseConnection(context.Context, string) error
	CloseAllConnections(context.Context) error
	Rules(context.Context) (mihomo.Rules, error)
	RuleProviders(context.Context) (mihomo.RuleProviders, error)
	UpdateRuleProvider(context.Context, string) error
	Configs(context.Context) (map[string]any, error)
	PatchConfigs(context.Context, map[string]any) error
	Stream(context.Context, mihomo.StreamKind, func(json.RawMessage) error) error
}

type CoreInstaller

type CoreInstaller interface {
	Prepare(context.Context, core.InstallRequest) (core.PreparedCore, error)
	DetectVersion(context.Context, string) (string, error)
}

type CoreSupervisor

type CoreSupervisor interface {
	Run(context.Context) error
	Restart(context.Context) error
}

type GeoIPCandidate

type GeoIPCandidate interface {
	Identity() string
	Valid() bool
	Commit() error
	Cleanup()
}

GeoIPCandidate is the minimal prepared-pair contract used by the mutation coordinator.

type GeoIPService

type GeoIPService interface {
	Status() geoip.Status
	Lookup(netip.Addr) (geoip.Record, error)
}

GeoIPService is the local lookup and health boundary used by the runtime.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(options Options) *Manager

func (*Manager) ActivatePanel

func (m *Manager) ActivatePanel(ctx context.Context, operation Operation, panelID string) error

ActivatePanel switches the active panel pointer under the mutation lock.

func (*Manager) ActivePanel

func (m *Manager) ActivePanel(context.Context) (panel.Active, error)

ActivePanel returns the active panel pointer without secrets.

func (*Manager) AddSubscription

func (m *Manager) AddSubscription(ctx context.Context, operation Operation, input AddSubscriptionInput) (subscription.PublicProfile, error)

func (*Manager) ApplyDesiredSystemProxy

func (m *Manager) ApplyDesiredSystemProxy(ctx context.Context) error

ApplyDesiredSystemProxy best-effort enables the OS proxy when settings desire it. Intended for daemon startup; failures are returned but callers may ignore them.

func (*Manager) BrowserSessions

func (m *Manager) BrowserSessions() int

BrowserSessions returns the approximate concurrent authenticated Web gateway sessions.

func (*Manager) Capabilities

func (m *Manager) Capabilities() []string

func (*Manager) ClearOwnedSystemProxy

func (m *Manager) ClearOwnedSystemProxy(ctx context.Context) error

ClearOwnedSystemProxy best-effort disables the OS proxy when Mihari owns it. Intended for graceful daemon shutdown; failures are returned but callers may ignore them.

func (*Manager) CloseAllConnections

func (m *Manager) CloseAllConnections(ctx context.Context, operation Operation) error

func (*Manager) CloseConnection

func (m *Manager) CloseConnection(ctx context.Context, operation Operation, id string) error

func (*Manager) Connections

func (m *Manager) Connections(ctx context.Context) (mihomo.Connections, error)

func (*Manager) DelayGroup

func (m *Manager) DelayGroup(ctx context.Context, group, testURL string, timeoutMilliseconds int) (mihomo.Delays, error)

func (*Manager) DelayProxy

func (m *Manager) DelayProxy(ctx context.Context, name, testURL string, timeoutMilliseconds int) (uint16, error)

func (*Manager) DisableSystemProxy

func (m *Manager) DisableSystemProxy(ctx context.Context, op Operation) (protocol.SystemProxyStatus, error)

DisableSystemProxy clears Mihari-owned system proxy (policy i). Foreign proxies are refused without OS write or desired-state change.

func (*Manager) DisableTun

func (m *Manager) DisableTun(ctx context.Context, op Operation) (protocol.TunStatus, error)

DisableTun persists managed TUN enable=false (block stays non-empty so subscription tun stays overridden).

func (*Manager) EnableSystemProxy

func (m *Manager) EnableSystemProxy(ctx context.Context, op Operation, force bool) (protocol.SystemProxyStatus, error)

EnableSystemProxy turns on the OS system proxy for the mixed endpoint. When a foreign proxy is active, force must be true to overwrite it.

func (*Manager) EnableTun

func (m *Manager) EnableTun(ctx context.Context, op Operation, force bool) (protocol.TunStatus, error)

EnableTun persists managed TUN enable=true and applies it to the running core. When other TUN adapters are detected (routing conflict or loop risk), force must be true to proceed. Disable is never gated (see mutateTun).

func (*Manager) GeoIPStatus

func (m *Manager) GeoIPStatus(context.Context) (geoip.Status, error)

GeoIPStatus returns the current redacted database health.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, operation Operation) (core.InstallResult, error)

func (*Manager) InstallPanel

func (m *Manager) InstallPanel(ctx context.Context, operation Operation, panelID, pinBuild string) error

InstallPanel downloads and installs outside the commit section, then bumps revision.

func (*Manager) ListPanels

func (m *Manager) ListPanels(context.Context) ([]panel.PanelInfo, error)

ListPanels returns redacted panel install state.

func (*Manager) LocalCore added in v0.4.0

func (m *Manager) LocalCore(ctx context.Context) (core.LocalCoreInfo, error)

LocalCore reports whether the configured core binary already satisfies setup locally (mihomo -v succeeds), so onboarding can hint "use existing" without a network install. Read-only: no lock, no store mutation. Mirrors the Install setup fast-path predicate (design §4.3), DRY — same DetectVersion judgment.

func (*Manager) LookupGeoIP

func (m *Manager) LookupGeoIP(_ context.Context, addresses []netip.Addr) ([]geoip.Record, error)

LookupGeoIP resolves a bounded batch from daemon-owned local databases.

func (*Manager) Observe

func (m *Manager) Observe(observation supervisor.Observation)

func (*Manager) OnboardingStatus

func (m *Manager) OnboardingStatus(ctx context.Context) (onboarding.Snapshot, error)

func (*Manager) OpenWebGUI

func (m *Manager) OpenWebGUI(_ context.Context, panelID string) (string, string, error)

OpenWebGUI returns a one-shot local open URL that includes the Web access token. panelID selects which installed panel to open; empty uses the default active panel. Callers must not log or persist the result beyond immediately launching a browser.

func (*Manager) Panels

func (m *Manager) Panels(context.Context) ([]panel.PanelInfo, error)

Panels returns the redacted panel catalog with install state.

func (*Manager) Proxies

func (m *Manager) Proxies(ctx context.Context) (mihomo.Proxies, error)

func (*Manager) RefreshSubscription

func (m *Manager) RefreshSubscription(ctx context.Context, operation Operation, id string) (subscription.PublicProfile, error)

func (*Manager) ReinstallPanel

func (m *Manager) ReinstallPanel(ctx context.Context, operation Operation, panelID string) error

ReinstallPanel uninstalls then reinstalls outside/inside commit as needed, then bumps revision. Download runs outside the commit section after uninstall clears local state.

func (*Manager) RemoveSubscription

func (m *Manager) RemoveSubscription(ctx context.Context, operation Operation, id string) error

func (*Manager) Restart

func (m *Manager) Restart(ctx context.Context, operation Operation) error

func (*Manager) RollbackPanel

func (m *Manager) RollbackPanel(ctx context.Context, operation Operation, panelID string) error

RollbackPanel restores the retained previous build under the mutation lock.

func (*Manager) RuleProviders

func (m *Manager) RuleProviders(ctx context.Context) (mihomo.RuleProviders, error)

func (*Manager) Rules

func (m *Manager) Rules(ctx context.Context) (mihomo.Rules, error)

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

func (*Manager) SelectProxy

func (m *Manager) SelectProxy(ctx context.Context, operation Operation, group, name string) error

func (*Manager) ServiceStatus added in v0.4.0

func (m *Manager) ServiceStatus(context.Context) (protocol.ServiceStatus, error)

ServiceStatus reports the OS service registration state for onboarding review. Advisory: a nil injector or any error resolves to "unknown" and never fails, so the endpoint stays 200 and onboarding is never blocked (design §5.3, §8).

func (*Manager) SetSubscription

func (m *Manager) SetSubscription(ctx context.Context, operation Operation, id string, input SetSubscriptionInput) (subscription.PublicProfile, error)

func (*Manager) SetSubscriptionEnabled

func (m *Manager) SetSubscriptionEnabled(ctx context.Context, operation Operation, id string, enabled bool) (subscription.PublicProfile, error)

func (*Manager) Snapshot

func (m *Manager) Snapshot() state.Snapshot

func (*Manager) Stream

func (m *Manager) Stream(ctx context.Context, kind mihomo.StreamKind, receive func(json.RawMessage) error) error

func (*Manager) Subscriptions

func (m *Manager) Subscriptions() subscription.PublicCatalog

func (*Manager) SystemProxyStatus

func (m *Manager) SystemProxyStatus(ctx context.Context) (protocol.SystemProxyStatus, error)

SystemProxyStatus returns desired intent plus live OS observation.

func (*Manager) TUIPreferences

func (m *Manager) TUIPreferences() preferences.Preferences

func (*Manager) TunStatus

func (m *Manager) TunStatus(ctx context.Context) (protocol.TunStatus, error)

TunStatus returns desired managed TUN intent plus live observation from mihomo when available.

func (*Manager) UninstallPanel

func (m *Manager) UninstallPanel(ctx context.Context, operation Operation, panelID string) error

UninstallPanel removes all local builds for a panel under the mutation lock.

func (*Manager) UpdateGeoIP

func (m *Manager) UpdateGeoIP(ctx context.Context, operation Operation) (geoip.Status, error)

UpdateGeoIP prepares outside the mutation gate and commits under revision control.

func (*Manager) UpdateOnboarding

func (m *Manager) UpdateOnboarding(ctx context.Context, operation Operation, update onboarding.Update) (onboarding.Snapshot, error)

func (*Manager) UpdatePanel

func (m *Manager) UpdatePanel(ctx context.Context, operation Operation, panelID string) error

UpdatePanel installs a newer build when available, then bumps revision.

func (*Manager) UpdateRuleProvider

func (m *Manager) UpdateRuleProvider(ctx context.Context, operation Operation, name string) error

func (*Manager) UpdateTUIPreferences

func (m *Manager) UpdateTUIPreferences(ctx context.Context, operation Operation, update preferences.Update) (preferences.Preferences, error)

func (*Manager) UseSubscription

func (m *Manager) UseSubscription(ctx context.Context, operation Operation, id string) (subscription.PublicProfile, error)

func (*Manager) WebGUIStatus

func (m *Manager) WebGUIStatus(context.Context) (protocol.WebGUIStatus, error)

WebGUIStatus returns a secret-free gateway and panel status for local clients.

func (*Manager) WebListenAddr

func (m *Manager) WebListenAddr() string

WebListenAddr returns the bound Web gateway address when available.

type Operation

type Operation struct {
	ID         string
	Source     string
	IfRevision *uint64
	Channel    *string
}

type Options

type Options struct {
	Store          *state.Store
	Coordinator    *state.Coordinator
	Installer      CoreInstaller
	InstallRequest core.InstallRequest
	Supervisor     CoreSupervisor
	Controller     Controller
	BinaryExists   func() bool
	Subscriptions  *subscription.Service
	Preferences    *preferences.Service
	Settings       config.Settings
	RuntimeConfig  string
	StagingDir     string
	ValidateConfig func(context.Context, string) error
	RunScheduler   func(context.Context) error
	GeoIP          GeoIPService
	PrepareGeoIP   func(context.Context) (GeoIPCandidate, error)
	Onboarding     *onboarding.Service
	Panels         PanelService
	// WebGateway is the optional loopback browser gateway. Failures do not stop the core supervisor.
	WebGateway WebGateway
	// WebOpenToken is the Web access credential used only to mint open-browser URLs for local clients.
	// It must never appear in status DTOs, logs, or default CLI output.
	WebOpenToken string
	// SysProxy is the OS system-proxy backend. Nil installs the platform default in New.
	SysProxy sysproxy.Backend
	// TunDetect is the TUN conflict detection backend. Nil installs the platform default in New.
	TunDetect tundetect.Backend
	// LookupTCPOccupant reports the PID listening on a host:port. Nil installs
	// platform.LookupTCPOccupant. Tests inject a fake to avoid real socket tables.
	LookupTCPOccupant func(string) (int, bool)
	// SettingsPath is where config.Save writes settings after system-proxy (and related) mutations.
	// Empty skips persistence (in-memory settings only).
	SettingsPath string
	// ServiceStatus reports the OS service registration state for onboarding review.
	// Optional; nil reports "unknown". Injected as a func (not *service.Manager) to keep
	// runtime free of the service package and break the main↔daemon assembly cycle.
	ServiceStatus func() (string, error)
	// OnBackgroundError receives non-cancellation failures from the web gateway
	// and owned scheduler. Optional; nil keeps the previous discard behavior.
	OnBackgroundError func(component string, err error)
}

type PanelService

type PanelService interface {
	List() []panel.PanelInfo
	Active() (panel.Active, error)
	ActiveDir() (string, error)
	PanelDir(panelID string) (string, error)
	Install(ctx context.Context, panelID, pinBuild string) error
	PrepareUpdate(ctx context.Context, panelID string) (panel.PreparedMutation, error)
	Activate(ctx context.Context, panelID string) error
	Rollback(ctx context.Context, panelID string) error
	Uninstall(ctx context.Context, panelID string) error
	PrepareReinstall(ctx context.Context, panelID string) (panel.PreparedMutation, error)
	SetupPath(gatewayHost string) string
	SetupPathFor(panelID, gatewayHost string) string
}

PanelService is the daemon-owned panel lifecycle boundary used by the mutation coordinator.

type PreparedCore

type PreparedCore = core.PreparedCore

type SetSubscriptionInput

type SetSubscriptionInput struct {
	Name         *string
	URL          *string
	Interval     *string
	AutoRefresh  *bool
	GlobalPeriod *string
	ProxyMode    *string
}

type WebGateway

type WebGateway interface {
	Serve(context.Context) error
	SessionCount() int
	ListenAddr() string
}

WebGateway is the loopback HTTP server for panel hosting and API proxying.

Jump to

Keyboard shortcuts

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