proxycore

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package proxycore renders reviewed proxy-core artifacts from server-owned intent models. It is deliberately narrow at first: the MVP supports only sing-box VLESS over TCP with REALITY, and rejects every other combination.

Index

Constants

View Source
const (
	SubscriptionFormatBase64    = "base64"
	SubscriptionFormatPlain     = "plain"
	SubscriptionFormatSingBox   = "sing-box"
	SubscriptionFormatClash     = "clash"
	SubscriptionFormatClashMeta = "clash-meta"
)
View Source
const (
	DefaultSingBoxConfigPath = "/etc/sing-box/config.json"
	DefaultXrayConfigPath    = "/usr/local/etc/xray/config.json"
	DefaultListenAddress     = "::"
)

Variables

This section is empty.

Functions

func Base64Subscription

func Base64Subscription(links []string) []byte

func ClashMetaSubscription

func ClashMetaSubscription(endpoints []VLESSRealityEndpoint) []byte

ClashMetaSubscription renders a dependency-free Clash.Meta-compatible YAML proxy list for the supported VLESS+REALITY+TCP endpoints.

func GenerateRealityKeypair

func GenerateRealityKeypair() (privateKey, publicKey string, err error)

GenerateRealityKeypair returns a fresh X25519 keypair as base64.RawURLEncoding strings. The 32-byte keys encode to 43 chars of [A-Za-z0-9_-], satisfying the server's reality key regex.

func GenerateRealityShortID

func GenerateRealityShortID(n int) (string, error)

GenerateRealityShortID returns a random REALITY short_id: a lowercase, even-length hex string. n is the number of random bytes (clamped to 1..8, so the result is 2..16 hex chars), satisfying the short-id regex + even-length rule the core enforces.

func PlainSubscription

func PlainSubscription(links []string) []byte

func RealityPublicKeyFromPrivate

func RealityPublicKeyFromPrivate(privateKey string) (string, error)

RealityPublicKeyFromPrivate derives the base64.RawURLEncoding public key for an operator-supplied X25519 private key. It accepts the key in raw/std base64 with or without padding, and always returns the public key in the canonical base64.RawURLEncoding form used in subscription links.

func RenderSingBoxConfig

func RenderSingBoxConfig(profile model.ProxyNodeProfile, inbounds []model.ProxyInbound, users []model.ProxyUser, opts RenderOptions) (singBoxConfig, []string, error)

RenderSingBoxConfig builds the in-memory sing-box config. It returns structs rather than string templates so operator-controlled labels cannot break JSON syntax.

func RenderXrayConfig

func RenderXrayConfig(profile model.ProxyNodeProfile, inbounds []model.ProxyInbound, users []model.ProxyUser, opts RenderOptions) (xrayConfig, []string, error)

RenderXrayConfig builds the in-memory xray config from server-owned intent models. It uses structs rather than templates so operator input cannot break JSON syntax.

func SingBoxClientSubscription

func SingBoxClientSubscription(endpoints []VLESSRealityEndpoint) ([]byte, error)

SingBoxClientSubscription renders a minimal sing-box client outbound config for the supported VLESS+REALITY+TCP endpoints.

func SubscriptionUserinfo

func SubscriptionUserinfo(user model.ProxyUser) string
func VLESSRealityLinks(user model.ProxyUser, profiles []SubscriptionProfile, inbounds []model.ProxyInbound, opts SubscriptionOptions) ([]string, []string, error)

VLESSRealityLinks renders MVP VLESS+REALITY links for one subscriber across applied node profiles. It returns an empty slice for inactive users instead of an error so the public subscription endpoint can stay token-stable while enforcing expiry/quota server-side.

Types

type Artifact

type Artifact struct {
	Core         string
	ConfigJSON   string
	ConfigSHA256 string
	ConfigPath   string
	Warnings     []string
}

Artifact is the canonical renderer output for the plan/apply path. ConfigJSON contains user UUIDs and REALITY private keys and must be treated as a node-scoped secret-bearing artifact.

func RenderXrayConfigJSON

func RenderXrayConfigJSON(profile model.ProxyNodeProfile, inbounds []model.ProxyInbound, users []model.ProxyUser, opts RenderOptions) (Artifact, error)

RenderXrayConfigJSON renders a canonical xray config for one node profile. MVP support intentionally matches the sing-box slice: VLESS over TCP with REALITY only. Unsupported protocols/transports fail closed.

type RenderOptions

type RenderOptions struct {
	Now time.Time
}

RenderOptions controls deterministic render behavior. Now is used to filter expired users; zero means time.Now().UTC().

type SingBoxArtifact

type SingBoxArtifact = Artifact

SingBoxArtifact is kept as a compatibility alias for older call sites while xray support shares the same secret-bearing artifact contract.

func RenderSingBoxConfigJSON

func RenderSingBoxConfigJSON(profile model.ProxyNodeProfile, inbounds []model.ProxyInbound, users []model.ProxyUser, opts RenderOptions) (SingBoxArtifact, error)

RenderSingBoxConfigJSON renders a canonical sing-box config for one node profile. The output is valid JSON with a trailing newline and includes the direct outbound that server-side proxy deployments need by default.

type SubscriptionOptions

type SubscriptionOptions struct {
	Now time.Time
}

type SubscriptionProfile

type SubscriptionProfile struct {
	Profile  model.ProxyNodeProfile
	NodeName string
}

SubscriptionProfile is the small server-provided view needed to render links. It intentionally carries display-only node metadata, not Node secrets.

type VLESSRealityEndpoint

type VLESSRealityEndpoint struct {
	Label       string
	Tag         string
	NodeID      string
	InboundID   string
	Server      string
	ServerPort  int
	UUID        string
	Flow        string
	Network     string
	SNI         string
	Fingerprint string
	ALPN        []string
	PublicKey   string
	ShortID     string
}

VLESSRealityEndpoint is a validated, secret-free client subscription endpoint for the currently supported VLESS+REALITY+TCP shape.

func VLESSRealityEndpoints

func VLESSRealityEndpoints(user model.ProxyUser, profiles []SubscriptionProfile, inbounds []model.ProxyInbound, opts SubscriptionOptions) ([]VLESSRealityEndpoint, []string, error)

VLESSRealityEndpoints renders structured subscription endpoints for the currently supported VLESS+REALITY+TCP shape. All public subscription formats are derived from these endpoints so validation and secret stripping stay in one place.

func (e VLESSRealityEndpoint) Link() string

Jump to

Keyboard shortcuts

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