core

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelRelease Channel = "release"
	ChannelAlpha   Channel = "alpha"

	DefaultCheckInterval = 24 * time.Hour
	ManagedBinaryPath    = "/var/lib/m-ui/core/current/mihomo"
)
View Source
const (
	UpstreamRepository = "MetaCubeX/mihomo"
	AlphaTag           = "Prerelease-Alpha"
)

Variables

View Source
var (
	ErrDegraded              = errors.New("core updates are disabled while the system is degraded")
	ErrExternal              = errors.New("external Mihomo core is not managed by m-ui")
	ErrNoBackup              = errors.New("no previous managed Mihomo core backup is available")
	ErrMihomoRestartRequired = errors.New("mihomo restart is required before core mutation")
)
View Source
var AllowedCheckIntervals = []time.Duration{
	6 * time.Hour,
	12 * time.Hour,
	24 * time.Hour,
	168 * time.Hour,
}

Functions

func ValidateCheckInterval

func ValidateCheckInterval(value time.Duration) error

Types

type Activation

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

type Channel

type Channel string

func ParseChannel

func ParseChannel(value string) (Channel, error)

type EndpointRestartGate added in v0.1.1

type EndpointRestartGate interface {
	MihomoRestartRequired(context.Context) (bool, error)
}

EndpointRestartGate is implemented by the durable settings store. Core activation restarts Mihomo, so it must not be allowed to apply a different binary while a previously saved endpoint candidate still awaits its explicit restart boundary.

type FileStore

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

func NewFileStore

func NewFileStore(root string) (*FileStore, error)

func (*FileStore) Activate

func (store *FileStore) Activate(stagedDirectory string) (Activation, error)

func (*FileStore) BinaryPath

func (store *FileStore) BinaryPath() string

func (*FileStore) ClearFailClosed

func (store *FileStore) ClearFailClosed() error

func (*FileStore) CreateDownloadStage

func (store *FileStore) CreateDownloadStage() (string, string, error)

func (*FileStore) Current

func (store *FileStore) Current() (Manifest, error)

func (*FileStore) FailClosed

func (store *FileStore) FailClosed() (bool, error)

FailClosed reports the durable safety sentinel used when a core rollback cannot be completed. The sentinel is intentionally separate from the SQLite bit so a database outage cannot make an unsafe core look healthy.

func (*FileStore) FinalizeDownloadedStage

func (store *FileStore) FinalizeDownloadedStage(
	directory string,
	identity ReleaseIdentity,
	compressedSHA, reportedVersion string,
	installedAt time.Time,
) (Manifest, error)

func (*FileStore) LatestBackup

func (store *FileStore) LatestBackup() (string, Manifest, error)

func (*FileStore) ManifestPath

func (store *FileStore) ManifestPath() string

func (*FileStore) MarkFailClosed

func (store *FileStore) MarkFailClosed() error

func (*FileStore) Prepare

func (store *FileStore) Prepare() error

func (*FileStore) Recover

func (store *FileStore) Recover() error

func (*FileStore) RemoveStage

func (store *FileStore) RemoveStage(directory string)

func (*FileStore) Restore

func (store *FileStore) Restore(activation Activation) error

func (*FileStore) RevertActivation

func (store *FileStore) RevertActivation(activation Activation) error

func (*FileStore) SetStagedVersion

func (store *FileStore) SetStagedVersion(
	directory string,
	manifest Manifest,
	reportedVersion string,
) (Manifest, error)

func (*FileStore) StageAdopted

func (store *FileStore) StageAdopted(
	sourcePath, reportedVersion string,
	now time.Time,
) (string, Manifest, error)

func (*FileStore) StageBackup

func (store *FileStore) StageBackup(backupPath string) (string, error)

func (*FileStore) StageBootstrap

func (store *FileStore) StageBootstrap(
	binaryPath, manifestPath string,
) (string, Manifest, error)

type GitHubClient

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

func NewGitHubClient

func NewGitHubClient(options GitHubClientOptions) (*GitHubClient, error)

func (*GitHubClient) Download

func (client *GitHubClient) Download(
	ctx context.Context,
	identity ReleaseIdentity,
	destination io.Writer,
) (string, int64, error)

func (*GitHubClient) Resolve

func (client *GitHubClient) Resolve(
	ctx context.Context,
	channel Channel,
	architecture string,
) (ReleaseIdentity, error)

type GitHubClientOptions

type GitHubClientOptions struct {
	HTTPClient    *http.Client
	APIBase       string
	Token         string
	UserAgent     string
	AllowTestHTTP bool
}

type Manager

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

func NewManager

func NewManager(options ManagerOptions) (*Manager, error)

func (*Manager) AdoptExternal

func (manager *Manager) AdoptExternal(
	ctx context.Context,
	sourcePath string,
) (Manifest, bool, error)

func (*Manager) BinaryPath

func (manager *Manager) BinaryPath() string

func (*Manager) Bootstrap

func (manager *Manager) Bootstrap(
	ctx context.Context,
	binaryPath, manifestPath string,
) (Manifest, bool, error)

func (*Manager) Check

func (manager *Manager) Check(
	ctx context.Context,
	actorAdminID string,
) (ReleaseIdentity, error)

func (*Manager) Due

func (manager *Manager) Due(ctx context.Context, now time.Time) (bool, error)

func (*Manager) FailClosed

func (manager *Manager) FailClosed() bool

func (*Manager) Recover

func (manager *Manager) Recover(ctx context.Context) error

func (*Manager) Rollback

func (manager *Manager) Rollback(
	ctx context.Context,
	actorAdminID string,
) (result Manifest, resultErr error)

func (*Manager) SafetyBlocked

func (manager *Manager) SafetyBlocked(ctx context.Context) (bool, error)

SafetyBlocked exposes the same durable and in-memory fail-closed decision used by every core operation. Configuration publication and background schedulers use this gate as well, so a rollback failure cannot leave another mutating path active when persisting degraded state also failed.

func (*Manager) ScheduleStartupCheck added in v0.2.0

func (manager *Manager) ScheduleStartupCheck(ctx context.Context) error

ScheduleStartupCheck makes a persisted automatic-update preference take effect on every m-ui start. This is intentionally independent of the m-ui binary version: upgrades, container recreation, and ordinary service restarts all converge to the newest build in the user's selected channel.

func (*Manager) SetWake

func (manager *Manager) SetWake(wake func())

SetWake installs the scheduler wake-up hook after both components have been constructed. It is deliberately optional so short-lived CLI control planes do not need a scheduler.

func (*Manager) Settings

func (manager *Manager) Settings(
	ctx context.Context,
) (Settings, error)

func (*Manager) Status

func (manager *Manager) Status(ctx context.Context) (Status, error)

func (*Manager) Update

func (manager *Manager) Update(
	ctx context.Context,
	actorAdminID string,
) (Manifest, bool, error)

func (*Manager) UpdateSettings

func (manager *Manager) UpdateSettings(
	ctx context.Context,
	actorAdminID string,
	settings Settings,
) error

type ManagerOptions

type ManagerOptions struct {
	Repository     Repository
	Upstream       Upstream
	Files          *FileStore
	Process        mihomo.CoreProcess
	Controller     mihomo.CoreController
	Coordinator    *operation.Coordinator
	EndpointGate   EndpointRestartGate
	ConfigPath     string
	Architecture   string
	Clock          func() time.Time
	HealthCheck    func(context.Context) error
	HealthTimeout  time.Duration
	HealthInterval time.Duration
	Logger         *slog.Logger
	NewCLI         func(string) (mihomo.CoreCLI, error)
}

type Manifest

type Manifest struct {
	SchemaVersion         int             `json:"schema_version"`
	Source                string          `json:"source"`
	VerifiedSource        bool            `json:"verified_source"`
	Identity              ReleaseIdentity `json:"identity"`
	CompressedSHA256      string          `json:"compressed_sha256"`
	BinarySHA256          string          `json:"binary_sha256"`
	BinarySize            int64           `json:"binary_size"`
	BinaryReportedVersion string          `json:"binary_reported_version"`
	InstalledAt           time.Time       `json:"installed_at"`
}

func (Manifest) Validate

func (manifest Manifest) Validate() error

type ReleaseIdentity

type ReleaseIdentity struct {
	Channel               Channel   `json:"channel"`
	Repository            string    `json:"repository"`
	ReleaseID             int64     `json:"release_id"`
	TagName               string    `json:"tag_name"`
	Prerelease            bool      `json:"prerelease"`
	PublishedAt           time.Time `json:"published_at"`
	TargetCommitish       string    `json:"target_commitish,omitempty"`
	AssetID               int64     `json:"asset_id"`
	AssetName             string    `json:"asset_name"`
	AssetSize             int64     `json:"asset_size"`
	AssetDigestSHA256     string    `json:"asset_digest_sha256"`
	BrowserDownloadURL    string    `json:"-"`
	BinaryReportedVersion string    `json:"binary_reported_version,omitempty"`
}

func (ReleaseIdentity) SameRelease

func (identity ReleaseIdentity) SameRelease(other ReleaseIdentity) bool

func (ReleaseIdentity) Validate

func (identity ReleaseIdentity) Validate() error

type Repository

type Repository interface {
	CoreSettings(context.Context) (Settings, error)
	UpdateCoreSettings(context.Context, Settings, time.Time) error
	CoreState(context.Context) (State, error)
	SaveCoreState(context.Context, State) error
	CoreSystemDegraded(context.Context) (bool, error)
	MarkDegraded(context.Context, string, string, time.Time) error
	RecordCoreAudit(
		context.Context,
		string,
		string,
		string,
		string,
		time.Time,
	) error
}

type Settings

type Settings struct {
	Channel       Channel       `json:"channel"`
	AutoUpdate    bool          `json:"auto_update"`
	CheckInterval time.Duration `json:"check_interval"`
	Managed       bool          `json:"managed"`
	ExternalPath  string        `json:"external_path,omitempty"`
}

func (Settings) MarshalJSON

func (settings Settings) MarshalJSON() ([]byte, error)

func (Settings) Validate

func (settings Settings) Validate() error

type State

type State struct {
	Current           *Manifest        `json:"current,omitempty"`
	Available         *ReleaseIdentity `json:"available,omitempty"`
	LastCheckAt       *time.Time       `json:"last_check_at,omitempty"`
	LastCheckResult   string           `json:"last_check_result,omitempty"`
	LastUpdateAt      *time.Time       `json:"last_update_at,omitempty"`
	LastUpdateResult  string           `json:"last_update_result,omitempty"`
	LastErrorRedacted string           `json:"last_error_redacted,omitempty"`
	NextCheckAt       *time.Time       `json:"next_check_at,omitempty"`
	UpdateInProgress  bool             `json:"update_in_progress"`
}

type Status

type Status struct {
	Settings              Settings `json:"settings"`
	State                 State    `json:"state"`
	ActualVersion         string   `json:"actual_version"`
	ControllerVersion     string   `json:"controller_version,omitempty"`
	ProcessActive         bool     `json:"process_active"`
	ControllerReachable   bool     `json:"controller_reachable"`
	CurrentBinarySHA256   string   `json:"current_binary_sha256,omitempty"`
	Managed               bool     `json:"managed"`
	UpdateAvailable       bool     `json:"update_available"`
	RuntimeVersionMatches bool     `json:"runtime_version_matches"`
}

type Upstream

type Upstream interface {
	Resolve(context.Context, Channel, string) (ReleaseIdentity, error)
	Download(context.Context, ReleaseIdentity, io.Writer) (string, int64, error)
}

Jump to

Keyboard shortcuts

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