service

package
v0.0.0-...-48af030 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package service contains all the services used by XrayR To implement a service, one needs to implement the interface below.

Index

Constants

View Source
const (
	DefaultStartTimeout = 2 * time.Minute
	DefaultCloseTimeout = 30 * time.Second
	DefaultJoinTimeout  = 30 * time.Second
	DefaultSyncTimeout  = 30 * time.Second
)
View Source
const DefaultReadinessStaleAfter = 3 * time.Minute

Variables

This section is empty.

Functions

func CleanupContext

func CleanupContext(ctx context.Context) (context.Context, context.CancelFunc)

func CloseContext

func CloseContext(ctx context.Context, runtime Service) error

func JoinContext

func JoinContext(ctx context.Context, owner any) error

func RecordSnapshotSyncApplied

func RecordSnapshotSyncApplied(target any, scope SnapshotSyncScope)

func SortRuntimeSnapshots

func SortRuntimeSnapshots(snapshots []RuntimeSnapshot)

func StartContext

func StartContext(ctx context.Context, runtime Service) error

func WithDefaultTimeout

func WithDefaultTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

Types

type ContextCloser

type ContextCloser interface {
	CloseContext(context.Context) error
}

type ContextJoiner

type ContextJoiner interface {
	JoinContext(context.Context) error
}

type ContextStarter

type ContextStarter interface {
	StartContext(context.Context) error
}

type FailureStage

type FailureStage string
const (
	FailureStageNone        FailureStage = "none"
	FailureStageStart       FailureStage = "start"
	FailureStageSync        FailureStage = "sync"
	FailureStageWebSocket   FailureStage = "websocket"
	FailureStageReconcile   FailureStage = "reconcile"
	FailureStageReport      FailureStage = "report"
	FailureStageCertificate FailureStage = "certificate"
	FailureStageRuntime     FailureStage = "runtime"
	FailureStageClose       FailureStage = "close"
	FailureStageCleanup     FailureStage = "cleanup"
)

type Readiness

type Readiness struct {
	Ready    bool
	Degraded bool
	Reasons  []ReadinessReason
}

func EvaluateReadiness

func EvaluateReadiness(snapshot RuntimeSnapshot, now time.Time, staleAfter time.Duration) Readiness

type ReadinessReason

type ReadinessReason string
const (
	ReadinessReasonShutdown           ReadinessReason = "shutdown"
	ReadinessReasonLifecycle          ReadinessReason = "lifecycle"
	ReadinessReasonCleanupPending     ReadinessReason = "cleanup_pending"
	ReadinessReasonSyncUnavailable    ReadinessReason = "sync_unavailable"
	ReadinessReasonSyncStale          ReadinessReason = "sync_stale"
	ReadinessReasonCertificateExpired ReadinessReason = "certificate_expired"
)

type ReloadPhase

type ReloadPhase string
const (
	ReloadPhaseNone      ReloadPhase = "none"
	ReloadPhaseCandidate ReloadPhase = "candidate"
	ReloadPhaseStop      ReloadPhase = "stop"
	ReloadPhaseStart     ReloadPhase = "start"
	ReloadPhaseCommit    ReloadPhase = "commit"
	ReloadPhaseRollback  ReloadPhase = "rollback"
)

type ReloadSnapshot

type ReloadSnapshot struct {
	Phase                    ReloadPhase
	Attempts                 uint64
	Successes                uint64
	Failures                 uint64
	LastCandidateDuration    time.Duration
	LastStopDuration         time.Duration
	LastStartDuration        time.Duration
	LastCommitDuration       time.Duration
	LastRollbackDuration     time.Duration
	LastInterruptionDuration time.Duration
}

type Restart

type Restart interface {
	Start() error
	Close() error
}

Restart the service

type RuntimeHealthSnapshot

type RuntimeHealthSnapshot struct {
	LastSuccessfulSync time.Time
	LastFailureStage   FailureStage
	LastFailureAt      time.Time
	TrafficBacklog     int
	CertificateExpiry  time.Time
}

type RuntimeHealthState

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

func (*RuntimeHealthState) RecordFailure

func (s *RuntimeHealthState) RecordFailure(stage FailureStage, at time.Time)

func (*RuntimeHealthState) RecordSuccessfulSync

func (s *RuntimeHealthState) RecordSuccessfulSync(at time.Time)

func (*RuntimeHealthState) SetCertificateExpiry

func (s *RuntimeHealthState) SetCertificateExpiry(expiry time.Time)

func (*RuntimeHealthState) SetTrafficBacklog

func (s *RuntimeHealthState) SetTrafficBacklog(backlog int)

func (*RuntimeHealthState) Snapshot

type RuntimeKind

type RuntimeKind string
const (
	RuntimeKindPanel      RuntimeKind = "panel"
	RuntimeKindMachine    RuntimeKind = "machine"
	RuntimeKindController RuntimeKind = "controller"
	RuntimeKindAnyTLS     RuntimeKind = "anytls"
	RuntimeKindTUIC       RuntimeKind = "tuic"
	RuntimeKindHysteria2  RuntimeKind = "hysteria2"
)

type RuntimeLifecycle

type RuntimeLifecycle string
const (
	RuntimeLifecycleStopped     RuntimeLifecycle = "stopped"
	RuntimeLifecycleStarting    RuntimeLifecycle = "starting"
	RuntimeLifecycleRunning     RuntimeLifecycle = "running"
	RuntimeLifecycleReloading   RuntimeLifecycle = "reloading"
	RuntimeLifecycleStopping    RuntimeLifecycle = "stopping"
	RuntimeLifecycleFailed      RuntimeLifecycle = "failed"
	RuntimeLifecycleFailedOwned RuntimeLifecycle = "failed-owned"
	RuntimeLifecycleRetiring    RuntimeLifecycle = "retiring"
	RuntimeLifecycleClosed      RuntimeLifecycle = "closed"
)

type RuntimeMode

type RuntimeMode string
const (
	RuntimeModeStatic  RuntimeMode = "static"
	RuntimeModeMachine RuntimeMode = "machine"
)

type RuntimeSnapshot

type RuntimeSnapshot struct {
	Kind                 RuntimeKind
	Mode                 RuntimeMode
	NodeID               int
	Lifecycle            RuntimeLifecycle
	TopologyGeneration   uint64
	LastSuccessfulSync   time.Time
	WebSocket            WebSocketState
	LastFailureStage     FailureStage
	LastFailureAt        time.Time
	CleanupPending       bool
	TrafficReportBacklog int
	CertificateExpiresAt time.Time
	Reload               ReloadSnapshot
	Children             []RuntimeSnapshot
}

func (RuntimeSnapshot) Clone

func (s RuntimeSnapshot) Clone() RuntimeSnapshot

type RuntimeSnapshotProvider

type RuntimeSnapshotProvider interface {
	ObservabilitySnapshot() RuntimeSnapshot
}

type Service

type Service interface {
	Start() error
	Close() error
	Restart
}

Service is the interface of all the services running in the panel

type SnapshotSyncAppliedRecorder

type SnapshotSyncAppliedRecorder interface {
	RecordSnapshotSyncApplied(SnapshotSyncScope)
}

SnapshotSyncAppliedRecorder commits fetched candidates only after the runtime has successfully applied the corresponding authoritative snapshot.

type SnapshotSyncScope

type SnapshotSyncScope uint8

SnapshotSyncScope identifies authoritative panel snapshots that need refresh. Values are flags so burst triggers can be merged without an unbounded queue.

const (
	SnapshotSyncNode SnapshotSyncScope = 1 << iota
	SnapshotSyncUsers
	SnapshotSyncRules
	SnapshotSyncAll = SnapshotSyncNode | SnapshotSyncUsers | SnapshotSyncRules
)

func (SnapshotSyncScope) Includes

func (scope SnapshotSyncScope) Includes(required SnapshotSyncScope) bool

func (SnapshotSyncScope) Valid

func (scope SnapshotSyncScope) Valid() bool

type SnapshotSyncSource

type SnapshotSyncSource string
const (
	SnapshotSyncSourceWebSocket  SnapshotSyncSource = "websocket"
	SnapshotSyncSourceReconnect  SnapshotSyncSource = "reconnect"
	SnapshotSyncSourceParseError SnapshotSyncSource = "parse_error"
	SnapshotSyncSourcePolling    SnapshotSyncSource = "polling"
)

type SnapshotSyncSubmitter

type SnapshotSyncSubmitter interface {
	SubmitSnapshotSync(SnapshotSyncTrigger)
}

SnapshotSyncSubmitter accepts non-blocking authoritative snapshot triggers. Implementations must bound and coalesce pending work.

type SnapshotSyncTrigger

type SnapshotSyncTrigger struct {
	Scope      SnapshotSyncScope
	Source     SnapshotSyncSource
	OccurredAt time.Time
}

type WebSocketSnapshot

type WebSocketSnapshot struct {
	State         WebSocketState
	LastFailureAt time.Time
}

type WebSocketSnapshotProvider

type WebSocketSnapshotProvider interface {
	WebSocketObservabilitySnapshot() WebSocketSnapshot
}

type WebSocketState

type WebSocketState string
const (
	WebSocketDisabled     WebSocketState = "disabled"
	WebSocketDisconnected WebSocketState = "disconnected"
	WebSocketConnected    WebSocketState = "connected"
	WebSocketDegraded     WebSocketState = "degraded"
)

Directories

Path Synopsis
Package controller Package generate the InboundConfig used by add inbound
Package controller Package generate the InboundConfig used by add inbound
internal

Jump to

Keyboard shortcuts

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