runtime

package
v0.9.6-dev.8 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: GPL-3.0 Imports: 36 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 LoggingRuntime added in v0.9.2

type LoggingRuntime interface {
	Apply(context.Context, logging.Config)
	Config() logging.Config
	Dir() string
}

LoggingRuntime is the daemon-owned file logging configuration boundary.

type LoggingUpdate added in v0.9.2

type LoggingUpdate struct {
	Level     *string
	MaxSizeMB *int64
	MaxFiles  *int64
}

LoggingUpdate is a partial file logging configuration mutation.

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) CheckCoreVersion added in v0.9.5

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

CheckCoreVersion reads upstream metadata for the committed core channel. Network work runs outside the mutation gate; no state or revision is changed.

func (*Manager) CheckPanelVersion added in v0.9.5

func (m *Manager) CheckPanelVersion(ctx context.Context, id string) (protocol.VersionCheck, error)

CheckPanelVersion reads metadata for a supported panel, including uninstalled ones.

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) EgressStatus added in v0.9.6

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

EgressStatus returns saved selection and a fresh local adapter snapshot.

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(ctx context.Context) (geoip.Status, error)

GeoIPStatus returns the current redacted database health.

func (*Manager) GetInstallationStatus added in v0.9.3

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

GetInstallationStatus reports installation observations without a mutation path.

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 prepares a validated build outside the commit section, then installs and 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) LoggingStatus added in v0.9.2

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

LoggingStatus returns the complete effective file logging configuration.

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) PrepareCoreStart added in v0.9.5

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

PrepareCoreStart prepares saved configuration and holds mutation ownership until the caller has started the child and invoked the returned release.

func (*Manager) Proxies

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

func (*Manager) ProxyCatalog added in v0.9.4

func (m *Manager) ProxyCatalog(ctx context.Context) (mihomo.Proxies, []string, error)

ProxyCatalog returns complete display metadata and duplicate names. The raw global namespace remains available separately through Proxies for routing.

func (*Manager) RefreshProvider added in v0.9.3

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

RefreshProvider delegates native provider refresh to mihomo through the mutation coordinator.

func (*Manager) RefreshSubscription

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

func (*Manager) Reinstall added in v0.9.6

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

Reinstall resolves a new official candidate in the last accepted channel. It never replays an interrupted transaction or executes an uncertain old core.

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) RestoreRouting added in v0.9.4

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

RestoreRouting reconciles persisted intent before the supervisor reports a healthy core. The supervisor owns its context and retries; no UI is required.

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) RoutingProxyCatalog added in v0.9.4

func (m *Manager) RoutingProxyCatalog(ctx context.Context) (mihomo.Proxies, []string, uint64, string, error)

RoutingProxyCatalog binds complete display metadata and duplicate names to the candidate list's mutation revision and subscription.

func (*Manager) RoutingStatus added in v0.9.4

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

RoutingStatus returns saved routing intent and live kernel observation.

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) SetupRequired added in v0.9.4

func (m *Manager) SetupRequired(ctx context.Context) (bool, error)

SetupRequired derives required setup from effective runtime resources. Optional subscriptions/GeoIP and the historical welcome marker do not force onboarding.

func (*Manager) Snapshot

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

func (*Manager) StartupNetworkStatus added in v0.9.6

func (m *Manager) StartupNetworkStatus() *protocol.StartupNetworkStatus

StartupNetworkStatus observes initial network application without waiting for mutation ownership. Later restarts and explicit actions never restart it.

func (*Manager) Stream

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

func (*Manager) SubscriptionChanges added in v0.9.4

func (m *Manager) SubscriptionChanges() <-chan struct{}

SubscriptionChanges supplies coalesced committed-edit notifications to the single subscription scheduler. The Manager owns this channel for its lifetime; it is never closed.

func (*Manager) SubscriptionURL added in v0.9.4

func (m *Manager) SubscriptionURL(ctx context.Context, id string) (string, error)

SubscriptionURL reveals the current source to authenticated local clients.

func (*Manager) Subscriptions

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

func (*Manager) SyncLogging added in v0.9.5

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

SyncLogging observes and adopts the current core level without changing it.

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) UpdateEgress added in v0.9.6

func (m *Manager) UpdateEgress(ctx context.Context, op Operation, selection protocol.EgressSelection) (protocol.EgressStatus, error)

UpdateEgress applies an instance-wide selection through the configuration transaction.

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) UpdateLogging added in v0.9.2

func (m *Manager) UpdateLogging(ctx context.Context, operation Operation, update LoggingUpdate) (protocol.LoggingStatus, error)

UpdateLogging atomically persists and applies a partial file logging update.

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) UpdateRouting added in v0.9.4

func (m *Manager) UpdateRouting(ctx context.Context, op Operation, mode string) (protocol.RoutingStatus, error)

UpdateRouting persists and applies a routing mode without closing connections.

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(ctx 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 {
	// ListInterfaces is the adapter snapshot boundary; nil uses the platform enumerator.
	ListInterfaces func(context.Context) ([]platform.NetworkInterface, error)
	TrustedCore    *core.TrustedExecution

	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
	// Logging applies daemon-owned file logging settings at runtime.
	Logging LoggingRuntime
	// LoggingWait injects the observation interval wait for lifecycle tests.
	LoggingWait func(context.Context, time.Duration) error
	// RefreshLogSecrets replaces the exact subscription URL redaction snapshot.
	RefreshLogSecrets func(catalogURLs []string)
	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
	// SaveSettings persists an independently prepared settings candidate.
	// Nil uses config.SaveWithCommit.
	SaveSettings func(string, config.Settings) (config.CommitResult, error)
	// DiagnosticReporter records internal diagnostics for actual operation execution.
	DiagnosticReporter diagnostics.Reporter
	// 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)
	// InstallationStatus is a read-only app inspector; nil reports unknown.
	InstallationStatus func(context.Context) (protocol.InstallationStatus, 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)
	// ValidationMode is the no-business install-validation daemon. It refuses
	// mutation, background refresh, and core start.
	ValidationMode bool
	// ActivationPhase is the durable install journal phase. Empty means no Unix
	// install journal (Windows / non-root private / already complete).
	ActivationPhase string
	// CoreRepairRequired keeps ordinary mutations and automatic starts blocked.
	CoreRepairRequired bool
}

type PanelService

type PanelService interface {
	List() []panel.PanelInfo
	Active() (panel.Active, error)
	ActiveDir() (string, error)
	PanelDir(panelID string) (string, error)
	PrepareInstall(ctx context.Context, panelID, pinBuild string) (panel.PreparedMutation, 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