Documentation
¶
Overview ¶
Package meridian defines Petauron's runtime-independent account, access, routing, quota, deployment, and subscription rules for managed Xray entries.
Index ¶
- Constants
- 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 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 SubscriptionTokenFingerprint(token string) string
- func ValidIdentifier(value string) bool
- func ValidIdentity(value string) bool
- func VerifyAppliedReceipt(desired DesiredArtifact, receipt AppliedReceipt) error
- type AccessGate
- type Account
- type AccountPlan
- type AppliedReceipt
- type CounterSnapshot
- type Credential
- type CredentialKind
- type CredentialMaterial
- type DesiredArtifact
- type EgressPolicy
- type HysteriaEndpoint
- type ImportAccount
- type ImportPlan
- type NativeEntry
- 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" )
Variables ¶
This section is empty.
Functions ¶
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 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 ValidIdentifier ¶
func ValidIdentity ¶
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 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 means the policy was not specified and leaves Xray's system address selection unchanged. Unknown policies must never become auto.
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 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 NativeEntry ¶
type NativeEntry struct {
Material CredentialMaterial `json:"material"`
Protocol ProtocolKind `json:"protocol"`
Link string `json:"link"`
}
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"`
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"`
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 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"`
}