Documentation
¶
Index ¶
- Constants
- func Due(catalog Catalog, now time.Time) []string
- func Generate(base Document, overrides map[string]any, settings config.Settings) ([]byte, error)
- func GeoResourcePath(kind GeoResourceKind) (string, error)
- func ProviderResourceID(subscriptionID string, generation uint64, kind, name string) (string, error)
- func RetryDelay(failures int, minimum, maximum time.Duration) time.Duration
- func Save(path string, catalog Catalog) error
- func ValidProxyMode(mode string) bool
- func VerifyGeoDigest(kind GeoResourceKind, digest string) error
- type Catalog
- type Document
- type Downloader
- type DownloaderOptions
- type FetchRequest
- type FetchResult
- type Fetcher
- type GeoResourceKind
- type PreparedRefresh
- type Profile
- type ProviderStore
- type PublicCatalog
- type PublicProfile
- type Receipt
- type Scheduler
- type SchedulerOptions
- type Service
- func (s *Service) Add(name, rawURL, proxyMode string) (Profile, error)
- func (s *Service) CachePath(id string) string
- func (s *Service) CommitRefresh(prepared PreparedRefresh) (Receipt, error)
- func (s *Service) Mutate(mutate func(*Catalog) error) (Catalog, Catalog, error)
- func (s *Service) PrepareRefresh(ctx context.Context, id string) (PreparedRefresh, error)
- func (s *Service) ReadCache(id string) ([]byte, Document, error)
- func (s *Service) RecordRefreshFailure(prepared PreparedRefresh, cause error) error
- func (s *Service) ResetRefreshSchedule(profile *Profile)
- func (s *Service) Restore(catalog Catalog) error
- func (s *Service) Rollback(receipt Receipt) error
- func (s *Service) Snapshot() Catalog
- type ServiceOptions
- type UserInfo
Constants ¶
const ( ProxyModeDirect = "" // fetch the provider directly ProxyModeProxy = "proxy" // fetch only through the configured mihomo mixed-port ProxyModeAuto = "auto" // proxy first, fall back to direct on network failure )
Per-subscription proxy modes select how a refresh fetch reaches its provider. The zero value (ProxyModeDirect) is backward compatible: catalogs persisted before this field existed fetch directly, matching the old behavior.
const CatalogSchema = "mihari.subscriptions/v1"
Variables ¶
This section is empty.
Functions ¶
func GeoResourcePath ¶ added in v0.9.3
func GeoResourcePath(kind GeoResourceKind) (string, error)
GeoResourcePath returns the only permitted core-home relative asset basename.
func ProviderResourceID ¶ added in v0.9.3
func ProviderResourceID(subscriptionID string, generation uint64, kind, name string) (string, error)
ProviderResourceID returns the versioned identity hash used for every provider source kind. Names remain data and never become filesystem components.
func ValidProxyMode ¶ added in v0.4.0
ValidProxyMode reports whether mode is a recognized per-subscription proxy mode.
func VerifyGeoDigest ¶ added in v0.9.3
func VerifyGeoDigest(kind GeoResourceKind, digest string) error
These fixed identities were approved from the retained artifact catalog. Country/ASN preserve the existing release lock. DAT orphan commits may become unavailable; failure retains old resources and never selects a mutable fallback. VerifyGeoDigest checks a digest against the compiled Geo artifact catalog.
Types ¶
type Catalog ¶
type Catalog struct {
Schema string `yaml:"schema"`
GlobalInterval string `yaml:"global-interval"`
ActiveID string `yaml:"active-id,omitempty"`
Profiles []Profile `yaml:"profiles,omitempty"`
}
func Load ¶
Catalog loading pipeline (Load) runs these stages after decode:
migrate — forward schema migrations (no-op for current schema);
extension point for future vN→vN+1 reshapes.
Normalize — validates schema and fields, repairs invariants. Reports
errors; does NOT fill defaults.
fillDefaults — fills zero values with intended defaults. Pure filling,
never validates. Runs last so cleared values get a default.
Contract: any caller that Normalize()s an in-memory catalog (Load, Save, service.Mutate, service.CommitRefresh) MUST follow with fillDefaults(). Add new "zero ≠ default" fields to fillDefaults; keep Normalize about validation and invariant repair only.
func LoadOrCreate ¶
func (Catalog) EffectiveInterval ¶
func (Catalog) Public ¶
func (c Catalog) Public() PublicCatalog
type Document ¶
func ParseDocument ¶
type Downloader ¶
type Downloader struct {
MaxBytes int64
Reporter diagnostics.Reporter
// contains filtered or unexported fields
}
Downloader fetches subscription documents over HTTP. The direct client is always present; the proxy client is optional and backs proxy/auto modes.
func NewDownloader ¶
func NewDownloader(opts DownloaderOptions) *Downloader
func (*Downloader) Fetch ¶
func (d *Downloader) Fetch(ctx context.Context, input FetchRequest) (FetchResult, error)
type DownloaderOptions ¶ added in v0.4.0
type DownloaderOptions struct {
Client *http.Client
ProxyURL *url.URL
MaxBytes int64
Reporter diagnostics.Reporter
}
DownloaderOptions configures a Downloader. Client is the direct transport; a default 30s client is used when nil. ProxyURL enables proxy/auto modes by routing fetches through the mihomo mixed-port.
type FetchRequest ¶
type FetchResult ¶
type FetchResult struct {
Content []byte
ETag string
LastModified string
// Userinfo is the raw subscription-userinfo response header when present.
Userinfo string
NotModified bool
// FellBack is true when the result came from a non-preferred client: in auto
// mode the proxy failed at the network layer and the direct client succeeded.
FellBack bool
}
type Fetcher ¶
type Fetcher interface {
Fetch(context.Context, FetchRequest) (FetchResult, error)
}
type GeoResourceKind ¶ added in v0.9.3
type GeoResourceKind string
GeoResourceKind selects one compiled global Geo asset; it is never a path.
const ( // GeoCountryMMDB contains country address classification data. GeoCountryMMDB GeoResourceKind = "country-mmdb" // GeoASNMMDB contains autonomous system address classification data. GeoASNMMDB GeoResourceKind = "asn-mmdb" // GeoIPDAT contains named IP category lists used in geodata mode. GeoIPDAT GeoResourceKind = "geoip-dat" // GeoSiteDAT contains named domain category lists and attributes. GeoSiteDAT GeoResourceKind = "geosite-dat" )
type PreparedRefresh ¶
type PreparedRefresh struct {
// contains filtered or unexported fields
}
func (PreparedRefresh) AdvancesGeneration ¶ added in v0.9.3
func (p PreparedRefresh) AdvancesGeneration() bool
func (PreparedRefresh) Document ¶
func (p PreparedRefresh) Document() Document
func (PreparedRefresh) ProfileID ¶
func (p PreparedRefresh) ProfileID() string
type Profile ¶
type Profile struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
URL string `yaml:"url"`
// CacheURL identifies the source of the last successfully committed cache.
CacheURL string `yaml:"cache-url,omitempty"`
// ScheduleFrom restarts the refresh interval without changing cache age.
ScheduleFrom time.Time `yaml:"schedule-from,omitempty"`
// IntervalRefreshRequired remains set until a refresh succeeds.
IntervalRefreshRequired bool `yaml:"interval-refresh-required,omitempty"`
Enabled bool `yaml:"enabled"`
AutoRefresh bool `yaml:"auto-refresh"`
Interval string `yaml:"interval,omitempty"`
// ProxyMode controls how refresh fetches reach this provider. Empty = direct.
ProxyMode string `yaml:"proxy-mode,omitempty"`
Version uint64 `yaml:"version,omitempty"`
Generation uint64 `yaml:"generation,omitempty"`
UpdatedAt time.Time `yaml:"updated-at,omitempty"`
ETag string `yaml:"etag,omitempty"`
LastModified string `yaml:"last-modified,omitempty"`
LastError string `yaml:"last-error,omitempty"`
// Traffic quota from subscription-userinfo (bytes). Zero means unknown.
Upload int64 `yaml:"upload,omitempty"`
Download int64 `yaml:"download,omitempty"`
Total int64 `yaml:"total,omitempty"`
Expire int64 `yaml:"expire,omitempty"` // unix seconds
}
type ProviderStore ¶ added in v0.9.3
type ProviderStore struct {
// contains filtered or unexported fields
}
ProviderStore holds daemon-owned fixed provider files and their recovery journal. Its only production constructor borrows a trusted Unix data root.
func NewProviderStore ¶ added in v0.9.3
func NewProviderStore(ctx context.Context, data *platform.TrustedRoot) (*ProviderStore, error)
NewProviderStore borrows a root-owned private D capability. The daemon or installer retains its lifecycle lease and D until all resource users close. Recover must finish before any core recovery, validation or execution.
func (*ProviderStore) Recover ¶ added in v0.9.3
func (s *ProviderStore) Recover(ctx context.Context) error
Recover restores unfinished replacements before workers, core recovery or execution. A durable done record accepts only the reloaded new file.
func (*ProviderStore) RecoverState ¶ added in v0.9.3
RecoverState settles the whole WAL before stores load. A pending settings participant invalidates any settings value loaded by an upstream caller.
type PublicCatalog ¶
type PublicCatalog struct {
ActiveID string `json:"active_id,omitempty"`
GlobalInterval string `json:"global_interval"`
Profiles []PublicProfile `json:"profiles"`
}
type PublicProfile ¶
type PublicProfile struct {
// CacheOutdated reports a cache fetched from a different current URL.
CacheOutdated bool `json:"cache_outdated,omitempty"`
// ScheduleFrom overrides cache age as the next refresh scheduling origin.
ScheduleFrom time.Time `json:"schedule_from,omitzero"`
// IntervalRefreshRequired forces expiry until a successful refresh.
IntervalRefreshRequired bool `json:"interval_refresh_required,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
AutoRefresh bool `json:"auto_refresh"`
Interval string `json:"interval"`
Cached bool `json:"cached"`
Generation uint64 `json:"generation"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
LastError string `json:"last_error,omitempty"`
// Traffic from subscription-userinfo (bytes). Omitted when unknown.
Upload int64 `json:"upload,omitempty"`
Download int64 `json:"download,omitempty"`
Total int64 `json:"total,omitempty"`
Expire int64 `json:"expire,omitempty"`
// ProxyMode is the per-subscription refresh transport (direct/proxy/auto).
ProxyMode string `json:"proxy_mode,omitempty"`
}
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶
func NewScheduler(options SchedulerOptions) *Scheduler
type SchedulerOptions ¶
type SchedulerOptions struct {
// Changes wakes the scheduler after a committed catalog edit. The owner must not close it while Run is active.
Changes <-chan struct{}
Snapshot func() Catalog
Refresh func(context.Context, string) error
Now func() time.Time
After func(time.Duration) <-chan time.Time
Jitter func(string, time.Duration) time.Duration
IdlePoll time.Duration
MinRetry time.Duration
MaxRetry time.Duration
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func Open ¶
func Open(options ServiceOptions) (*Service, error)
func (*Service) CommitRefresh ¶
func (s *Service) CommitRefresh(prepared PreparedRefresh) (Receipt, error)
func (*Service) PrepareRefresh ¶
func (*Service) RecordRefreshFailure ¶ added in v0.9.4
func (s *Service) RecordRefreshFailure(prepared PreparedRefresh, cause error) error
RecordRefreshFailure keeps a prepared refresh's failure on its original profile version only. Revision conflicts and cancellation do not invalidate a cache.
func (*Service) ResetRefreshSchedule ¶ added in v0.9.4
ResetRefreshSchedule starts a new interval on a candidate profile. Callers publish that candidate through Mutate, keeping it within the same transaction.
type ServiceOptions ¶
type UserInfo ¶
type UserInfo struct {
Upload int64
Download int64
Total int64
Expire int64 // unix seconds; 0 if unknown
}
UserInfo is traffic/quota metadata from a provider's subscription-userinfo header. Values are bytes unless noted.
func ParseUserInfo ¶
ParseUserInfo parses headers like:
upload=123; download=456; total=789; expire=1710000000