proxycore

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 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     = "::"
)
View Source
const LineChainRealityClientFingerprint = "chrome"

LineChainRealityClientFingerprint is the reviewed strict-alpha uTLS profile bound into every canonical line-chain fragment.

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 LineChainFragment added in v0.2.3

type LineChainFragment struct {
	JSON   string
	SHA256 string
}

func RenderLineChainFragment added in v0.2.3

func RenderLineChainFragment(opts LineChainOutboundOptions) (LineChainFragment, error)

RenderLineChainFragment renders the narrow E3 partial config: exactly one VLESS+REALITY outbound and one route from the source inbound.

type LineChainOutboundOptions added in v0.2.3

type LineChainOutboundOptions struct {
	Tag               string
	SourceInboundTag  string
	Server            string
	ServerPort        int
	UUID              string
	Flow              string
	SNI               string
	RealityPublicKey  string
	RealityShortID    string
	ClientFingerprint string
}

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
	// NodeServiceStates carries the design-19 liveness verdict per node id.
	// Only "down" excludes a profile; unknown and restarting serve as before,
	// because a probe outage must never empty a subscription and a flapping
	// service must not churn the rendered set.
	NodeServiceStates map[string]string
}

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 NewVLESSRealityEndpoint added in v0.2.3

func NewVLESSRealityEndpoint(opts VLESSRealityEndpointOptions) (VLESSRealityEndpoint, error)

NewVLESSRealityEndpoint is the single validated constructor for typed VLESS+REALITY+TCP subscription output. Callers must not assemble links from ShareURL or concatenate credential-bearing URIs themselves.

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

type VLESSRealityEndpointOptions added in v0.2.3

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

Jump to

Keyboard shortcuts

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