Documentation
¶
Overview ¶
Package glivela defines Petauron's runtime-independent account, access, routing, quota, deployment, and subscription rules for managed Xray entries.
Index ¶
- Constants
- func CompositePublicIP(address netip.Addr) bool
- func Hysteria2LinkForCredential(endpoint HysteriaEndpoint, material CredentialMaterial, name string) (string, error)
- func HysteriaCertificateNotAfter(endpoint HysteriaEndpoint) (time.Time, error)
- func Identity(secret string) string
- func LinkForCredential(endpoint RealityEndpoint, material CredentialMaterial, name string) (string, error)
- func PublicTransportIPv4(value string) bool
- func RenderLinks(entries []NativeEntry, accountID string, mode PublishingMode, ...) ([]byte, error)
- func RenderMihomo(entries []NativeEntry, accountID string, mode PublishingMode, ...) ([]byte, error)
- func RenderXrayConfiguration(plan XrayPlan) ([]byte, error)
- func RouteUser(grantID string) string
- func SealImportMaterial(m ImportMaterial, key []byte, snapshotID string) ([]byte, error)
- func SubscriptionTokenFingerprint(token string) string
- func ValidIdentifier(value string) bool
- func ValidIdentity(value string) bool
- func ValidateCompositeExitPair(ipv6, ipv4 RoutePeer) error
- func ValidateCompositePeers(grant RouteGrant, ipv6, ipv4 RoutePeer) error
- func ValidateEndpointImport(material ImportMaterial, endpoints []ImportEndpoint) error
- func VerifyAppliedReceipt(desired DesiredArtifact, receipt AppliedReceipt) error
- type AccessGate
- type Account
- type AccountPlan
- type AppliedReceipt
- type BusinessOwnership
- type CounterSnapshot
- type Credential
- type CredentialKind
- type CredentialMaterial
- type DesiredArtifact
- type EgressPolicy
- type HysteriaEndpoint
- type ImportAccount
- type ImportApplication
- type ImportEndpoint
- type ImportLandingSelection
- type ImportMaterial
- type ImportNode
- type ImportPlan
- type ImportPublication
- type ImportReferences
- type ImportResetSchedule
- type ImportService
- type ImportTrafficCounters
- type NativeEntry
- type PrivateTransport
- type ProtocolKind
- type PublishedRoute
- type PublishingMode
- type QuotaProjection
- type RealityEndpoint
- type RouteGrant
- type RoutePeer
- type UsageMember
- type XrayPlan
Constants ¶
const ( MaxIdentifierLength = 128 MaxDisplayNameLength = 512 MaxResetDays = 3650 )
const ( DefaultRealityPort = 443 RealityBackendPort = 10443 DefaultLandingSOCKSPort = 1080 XrayAPIListenPort = 10085 XrayMinimumClient = "0.0.0" )
const SS2022Method = "2022-blake3-aes-128-gcm"
Variables ¶
This section is empty.
Functions ¶
func CompositePublicIP ¶
CompositePublicIP validates reported public exit addresses before publication.
func Hysteria2LinkForCredential ¶
func Hysteria2LinkForCredential(endpoint HysteriaEndpoint, material CredentialMaterial, name string) (string, error)
func HysteriaCertificateNotAfter ¶
func HysteriaCertificateNotAfter(endpoint HysteriaEndpoint) (time.Time, error)
func LinkForCredential ¶
func LinkForCredential(endpoint RealityEndpoint, material CredentialMaterial, name string) (string, error)
func PublicTransportIPv4 ¶
PublicTransportIPv4 permits a single canonical unicast endpoint, never a subnet, wildcard, private management address or DNS-dependent destination.
func RenderLinks ¶
func RenderLinks(entries []NativeEntry, accountID string, mode PublishingMode, routes []PublishedRoute, encoded bool) ([]byte, error)
func RenderMihomo ¶
func RenderMihomo(entries []NativeEntry, accountID string, mode PublishingMode, routes []PublishedRoute) ([]byte, error)
func RenderXrayConfiguration ¶
func SealImportMaterial ¶
func SealImportMaterial(m ImportMaterial, key []byte, snapshotID string) ([]byte, error)
SealImportMaterial uses standard authenticated encryption with an externally supplied 256-bit transfer key. Nonces come from Go's GCM implementation. The authenticated snapshot identifier prevents swapping material between exports. Successful decryption is not evidence that the legacy writer is fenced.
func ValidIdentifier ¶
func ValidIdentity ¶
func ValidateCompositePeers ¶
func ValidateCompositePeers(grant RouteGrant, ipv6, ipv4 RoutePeer) error
Composite routes keep one client credential and one quota membership. The private transport family is independent of each exit's final public family.
func ValidateEndpointImport ¶
func ValidateEndpointImport(material ImportMaterial, endpoints []ImportEndpoint) error
ValidateEndpointImport covers every credential's existing entry, not just entries selected for the first landing migration. Empty account inventories may legitimately coexist with configured endpoints and vice versa.
func VerifyAppliedReceipt ¶
func VerifyAppliedReceipt(desired DesiredArtifact, receipt AppliedReceipt) error
Types ¶
type AccessGate ¶
type Account ¶
type Account struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
Plan AccountPlan `json:"plan"`
DesiredRevision uint64 `json:"desiredRevision"`
AppliedRevision uint64 `json:"appliedRevision"`
}
type AccountPlan ¶
type AccountPlan struct {
TotalBytes int64 `json:"totalBytes"`
ExpiryTime int64 `json:"expiryTime"`
ResetDays int `json:"resetDays"`
Enabled bool `json:"enabled"`
}
func (AccountPlan) Validate ¶
func (p AccountPlan) Validate() error
type AppliedReceipt ¶
type BusinessOwnership ¶
type BusinessOwnership struct {
SourceSHA256 string `json:"sourceSha256"`
CaptureSHA256 string `json:"captureSha256"`
PreviousWriterID string `json:"previousWriterId"`
StoppedAt string `json:"stoppedAt"`
CapturedAt string `json:"capturedAt"`
}
BusinessOwnership is sealed with the business data by the one-time offline handover tool after it verifies the final backup and stopped old writer. It records data authority, never current process/route health. The previous writer identity is opaque to the controller, not a host capability contract.
func (BusinessOwnership) Validate ¶
func (o BusinessOwnership) Validate(sourceSHA256 string) error
type CounterSnapshot ¶
type CounterSnapshot struct {
CredentialID string `json:"credentialId"`
UpBytes int64 `json:"upBytes"`
DownBytes int64 `json:"downBytes"`
}
func ParseXrayUserCounters ¶
func ParseXrayUserCounters(materials []CredentialMaterial, payload []byte) ([]CounterSnapshot, error)
ParseXrayUserCounters accepts the bounded result of Xray's StatsService query. Names are matched against the complete expected name, so an imported user label containing Xray's delimiter remains unambiguous.
func (CounterSnapshot) TotalBytes ¶
func (s CounterSnapshot) TotalBytes() int64
type Credential ¶
type Credential struct {
ID string `json:"id"`
AccountID string `json:"accountId"`
Kind CredentialKind `json:"kind"`
User string `json:"user"`
Identity string `json:"identity"`
EntryID string `json:"entryId"`
EgressID string `json:"egressId,omitempty"`
Enabled bool `json:"enabled"`
}
func (Credential) Validate ¶
func (c Credential) Validate() error
type CredentialKind ¶
type CredentialKind string
const ( NativeCredential CredentialKind = "native" RouteCredential CredentialKind = "route" )
type CredentialMaterial ¶
type CredentialMaterial struct {
Credential Credential `json:"credential"`
ProtocolID string `json:"protocolId"`
HysteriaAuth string `json:"hysteriaAuth,omitempty"`
HysteriaIdentity string `json:"hysteriaIdentity,omitempty"`
}
func (CredentialMaterial) Validate ¶
func (m CredentialMaterial) Validate() error
type DesiredArtifact ¶
type DesiredArtifact struct {
Revision uint64 `json:"revision"`
Config []byte `json:"config"`
ConfigSHA256 string `json:"configSha256"`
}
func BuildDesiredArtifact ¶
func BuildDesiredArtifact(plan XrayPlan) (DesiredArtifact, error)
func (DesiredArtifact) Validate ¶
func (a DesiredArtifact) Validate() error
type EgressPolicy ¶
type EgressPolicy string
EgressPolicy controls the final destination family of native traffic. Fixed routes keep their SOCKS transport and the landing's own egress policy.
const ( EgressAuto EgressPolicy = "auto" EgressIPv4Only EgressPolicy = "ipv4_only" EgressIPv6Only EgressPolicy = "ipv6_only" )
func (EgressPolicy) Validate ¶
func (p EgressPolicy) Validate() error
The zero value keeps automatic family selection, not the host/control-plane resolver. Every native policy uses Glivela's explicit business DNS.
type HysteriaEndpoint ¶
type HysteriaEndpoint struct {
ID string `json:"id"`
EntryID string `json:"entryId"`
InboundTag string `json:"inboundTag"`
ListenPort int `json:"listenPort"`
AdvertiseHost string `json:"advertiseHost"`
AdvertisePort int `json:"advertisePort"`
ServerName string `json:"serverName"`
CertificatePEM string `json:"certificatePem"`
PrivateKeyPEM string `json:"privateKeyPem"`
}
func (HysteriaEndpoint) Validate ¶
func (e HysteriaEndpoint) Validate() error
type ImportAccount ¶
type ImportAccount struct {
Account Account `json:"account"`
SubscriptionTokenFingerprint string `json:"subscriptionTokenFingerprint"`
Credentials []Credential `json:"credentials"`
HysteriaIdentities map[string]string `json:"hysteriaIdentities,omitempty"`
Grants []RouteGrant `json:"grants"`
Usage []UsageMember `json:"usage"`
}
type ImportApplication ¶
type ImportEndpoint ¶
type ImportEndpoint struct {
Reality RealityEndpoint `json:"reality"`
Hysteria *HysteriaEndpoint `json:"hysteria,omitempty"`
ServiceID string `json:"serviceId"`
RuntimeCertificateID string `json:"runtimeCertificateId,omitempty"`
RuntimeConfigSHA256 string `json:"runtimeConfigSha256,omitempty"`
TargetIP string `json:"targetIp"`
VLESSEnabled bool `json:"vlessEnabled"`
HysteriaEnabled bool `json:"hysteriaEnabled"`
TotalBytes int64 `json:"totalBytes"`
UsedBytes int64 `json:"usedBytes"`
QuotaAppliedEnabled bool `json:"quotaAppliedEnabled"`
ResetDay int `json:"resetDay"`
ResetSchedule ImportResetSchedule `json:"resetSchedule"`
DesiredRevision uint64 `json:"desiredRevision"`
AppliedRevision uint64 `json:"appliedRevision"`
HistoricalHealthy bool `json:"historicalHealthy"`
PreviousStatus string `json:"previousStatus"`
PreviousError string `json:"previousError"`
LegacyRetired bool `json:"legacyRetired"`
// Retired is the current endpoint policy. LegacyRetired above only
// records retirement of the old implementation, not this endpoint.
Retired bool `json:"retired"`
SourcePeerJSON json.RawMessage `json:"sourcePeer"`
CertificateNotAfter string `json:"certificateNotAfter"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
ImportEndpoint retains the existing proxy configuration and historical observations. None of PreviousStatus, AppliedRevision or HistoricalHealthy is fresh runtime evidence for the newly enrolled controller.
func (ImportEndpoint) Validate ¶
func (e ImportEndpoint) Validate() error
type ImportLandingSelection ¶
type ImportLandingSelection struct {
NodeIDs []string `json:"nodeIds"`
LandingRegionCodes map[string]string `json:"landingRegionCodes,omitempty"`
LandingNameSuffixes map[string]string `json:"landingNameSuffixes,omitempty"`
RetiringNodeIDs []string `json:"retiringNodeIds,omitempty"`
Revision uint64 `json:"revision"`
}
type ImportMaterial ¶
type ImportMaterial struct {
SourceSHA256 string `json:"sourceSha256"`
RetainedSource json.RawMessage `json:"retainedSource"`
Endpoints []ImportEndpoint `json:"endpoints"`
References ImportReferences `json:"references"`
Plan ImportPlan `json:"plan"`
SubscriptionTokens map[string]string `json:"subscriptionTokens"`
ProtocolSecrets map[string]string `json:"protocolSecrets"`
HysteriaSecrets map[string]string `json:"hysteriaSecrets"`
ResetSchedules map[string]ImportResetSchedule `json:"resetSchedules"`
TrafficCounters map[string]ImportTrafficCounters `json:"trafficCounters"`
Ownership *BusinessOwnership `json:"ownership,omitempty"`
}
ImportMaterial is one atomic, sensitive handover checkpoint. RetainedSource is immutable migration evidence/history, never a second live configuration source. Do not send this material in a node receipt or publish it in logs.
func OpenImportMaterial ¶
func OpenImportMaterial(sealed, key []byte, snapshotID string) (ImportMaterial, error)
func (ImportMaterial) Validate ¶
func (m ImportMaterial) Validate() error
type ImportNode ¶
type ImportNode struct {
Name string `json:"name"`
PreviousStatus string `json:"previousStatus"`
ServiceAddress string `json:"serviceAddress"`
PrivateAddress string `json:"privateAddress"`
PeerJSON json.RawMessage `json:"peer,omitempty"`
EgressAddressesJSON json.RawMessage `json:"egressAddresses,omitempty"`
}
type ImportPlan ¶
type ImportPlan struct {
Accounts []ImportAccount `json:"accounts"`
SHA256 string `json:"sha256"`
}
func PlanImport ¶
func PlanImport(accounts []ImportAccount) (ImportPlan, error)
PlanImport validates a complete one-time authority transfer before a caller writes any state. It carries only the subscription-token fingerprint; the caller must move the raw token directly between encrypted stores.
type ImportPublication ¶
type ImportPublication struct {
ServiceID string `json:"serviceId"`
EntryNodeID string `json:"entryNodeId"`
Kind string `json:"kind"`
IngressOwner string `json:"ingressOwner"`
Hostname string `json:"hostname"`
SNIHostname string `json:"sniHostname"`
DNSProvider string `json:"dnsProvider"`
DNSRecordID string `json:"dnsRecordId"`
AccessApplicationID string `json:"accessApplicationId"`
TLSEnabled bool `json:"tlsEnabled"`
DesiredRevision uint64 `json:"desiredRevision"`
AppliedRevision uint64 `json:"appliedRevision"`
PreviousStatus string `json:"previousStatus"`
PreviousError string `json:"previousError"`
ActionRequired bool `json:"actionRequired"`
CleanupPending bool `json:"cleanupPending"`
CleanupAttempt int64 `json:"cleanupAttempt"`
CleanupRetryAt string `json:"cleanupRetryAt"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
type ImportReferences ¶
type ImportReferences struct {
Nodes map[string]ImportNode `json:"nodes"`
Applications map[string]ImportApplication `json:"applications"`
Services map[string]ImportService `json:"services"`
Publications map[string]ImportPublication `json:"publications"`
LandingSelection *ImportLandingSelection `json:"landingSelection,omitempty"`
}
ImportReferences preserves object identities and display/publication data. PreviousStatus and saved network observations are not current reachability or write authority. No platform credentials/capability matrix are imported.
type ImportResetSchedule ¶
type ImportResetSchedule struct {
NextResetAt string `json:"nextResetAt"`
LastResetAt string `json:"lastResetAt"`
}
Preserve the recorded schedule, not a newly calculated cycle from import time. Strings retain the source timestamp's precision and offset verbatim.
type ImportService ¶
type ImportService struct {
Timezone string `json:"timezone"`
ApplicationID string `json:"applicationId"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
RegionCode string `json:"regionCode"`
Protocol string `json:"protocol"`
ApplicationProtocol string `json:"applicationProtocol"`
ContainerPort int `json:"containerPort"`
HostPort int `json:"hostPort"`
Endpoint string `json:"endpoint"`
PreviousStatus string `json:"previousStatus"`
}
type ImportTrafficCounters ¶
type ImportTrafficCounters struct {
UploadBytes int64 `json:"uploadBytes"`
DownloadBytes int64 `json:"downloadBytes"`
RawUploadBytes int64 `json:"rawUploadBytes"`
RawDownloadBytes int64 `json:"rawDownloadBytes"`
StartedAt string `json:"startedAt"`
ObservedAt string `json:"observedAt"`
WatermarkObservedAt string `json:"watermarkObservedAt"`
}
Directional totals and raw counter watermarks have different meanings from the account quota baseline. Neither may be reconstructed from their sum.
type NativeEntry ¶
type NativeEntry struct {
Material CredentialMaterial `json:"material"`
Protocol ProtocolKind `json:"protocol"`
Link string `json:"link"`
}
type PrivateTransport ¶
type PrivateTransport struct {
Protocol string `json:"protocol,omitempty"`
Key string `json:"key,omitempty"`
PublicAddress string `json:"publicAddress,omitempty"`
}
PrivateTransport belongs only to the entry-to-landing connection. Its key must never be included in public subscriptions or diagnostic output. Empty values describe the retained pre-migration SOCKS configuration, not fallback.
func (PrivateTransport) Endpoint ¶
func (t PrivateTransport) Endpoint(privateAddress string) string
func (PrivateTransport) Validate ¶
func (t PrivateTransport) Validate() error
type ProtocolKind ¶
type ProtocolKind string
const ( VLESSReality ProtocolKind = "vless-reality" Hysteria2 ProtocolKind = "hysteria2" )
func (ProtocolKind) Valid ¶
func (p ProtocolKind) Valid() bool
type PublishedRoute ¶
type PublishedRoute struct {
Grant RouteGrant `json:"grant"`
Protocol ProtocolKind `json:"protocol"`
EntryName string `json:"entryName"`
EgressNameSuffix string `json:"egressNameSuffix,omitempty"`
EgressRegionPrefix string `json:"egressRegionPrefix,omitempty"`
IPv4EgressRegionPrefix string `json:"ipv4EgressRegionPrefix,omitempty"`
BaseLink string `json:"baseLink"`
RouteLink string `json:"routeLink"`
BaseProtocolIdentity string `json:"baseProtocolIdentity"`
RouteProtocolIdentity string `json:"routeProtocolIdentity"`
}
type PublishingMode ¶
type PublishingMode string
const FixedMode PublishingMode = "fixed"
func (PublishingMode) Valid ¶
func (m PublishingMode) Valid() bool
type QuotaProjection ¶
type QuotaProjection struct {
UsedBytes int64 `json:"usedBytes"`
Enabled bool `json:"enabled"`
Gates []AccessGate `json:"gates"`
}
func ProjectQuota ¶
func ProjectQuota(plan AccountPlan, members []UsageMember) (QuotaProjection, error)
ProjectQuota computes one account-wide usage value and projects only an on/off gate to each credential. It never splits the remaining quota between credentials, which would duplicate the plan or rewrite Xray on every sample.
type RealityEndpoint ¶
type RealityEndpoint struct {
ID string `json:"id"`
EntryID string `json:"entryId"`
InboundTag string `json:"inboundTag"`
ListenAddress string `json:"listenAddress"`
ListenPort int `json:"listenPort"`
AdvertiseHost string `json:"advertiseHost"`
AdvertisePort int `json:"advertisePort"`
Target string `json:"target"`
ServerNames []string `json:"serverNames"`
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"`
ShortIDs []string `json:"shortIds"`
Fingerprint string `json:"fingerprint"`
}
func (RealityEndpoint) Validate ¶
func (e RealityEndpoint) Validate() error
type RouteGrant ¶
type RouteGrant struct {
ID string `json:"id"`
AccountID string `json:"accountId"`
EntryID string `json:"entryId"`
EgressID string `json:"egressId"`
IPv4EgressID string `json:"ipv4EgressId,omitempty"`
InboundTag string `json:"inboundTag"`
Base Credential `json:"base"`
Route Credential `json:"route"`
Mode PublishingMode `json:"mode"`
Enabled bool `json:"enabled"`
HideNative bool `json:"hideNative"`
DesiredRev uint64 `json:"desiredRevision"`
AppliedRev uint64 `json:"appliedRevision"`
RuntimeGood bool `json:"runtimeHealthy"`
}
func (RouteGrant) Deployable ¶
func (g RouteGrant) Deployable() bool
Deployable reports whether the desired grant belongs in the next Xray projection. AppliedRev and RuntimeGood describe the previous receipt, so they deliberately do not gate creation of a newer desired configuration.
func (RouteGrant) Publishable ¶
func (g RouteGrant) Publishable() bool
func (RouteGrant) Validate ¶
func (g RouteGrant) Validate() error
type RoutePeer ¶
type RoutePeer struct {
Transport PrivateTransport `json:"transport,omitzero"`
EgressID string `json:"egressId"`
Address string `json:"address"`
Port int `json:"port"`
ExitFamily EgressPolicy `json:"exitFamily,omitempty"`
Ready bool `json:"ready,omitempty"`
}
type UsageMember ¶
type UsageMember struct {
CredentialID string `json:"credentialId"`
Baseline int64 `json:"baseline"`
Observed int64 `json:"observed"`
Active bool `json:"active"`
}
func ObserveUsage ¶
func ObserveUsage(members []UsageMember, counters map[string]int64) ([]UsageMember, error)
func ResetUsage ¶
func ResetUsage(members []UsageMember) []UsageMember
type XrayPlan ¶
type XrayPlan struct {
Revision uint64 `json:"revision"`
NativeEgress EgressPolicy `json:"nativeEgress,omitempty"`
RealityEndpoints []RealityEndpoint `json:"realityEndpoints,omitempty"`
HysteriaEndpoints []HysteriaEndpoint `json:"hysteriaEndpoints,omitempty"`
Credentials []CredentialMaterial `json:"credentials"`
Grants []RouteGrant `json:"grants"`
Peers []RoutePeer `json:"peers"`
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
glivela
command
Glivela owns node communication; the installer only supplies bootstrap files.
|
Glivela owns node communication; the installer only supplies bootstrap files. |
|
Package control implements Glivela's direct, authenticated node channel.
|
Package control implements Glivela's direct, authenticated node channel. |
|
Package landing contains the node-local boundary for optional SOCKS5 egress.
|
Package landing contains the node-local boundary for optional SOCKS5 egress. |