Documentation
¶
Overview ¶
Package xray parses and renders xray-core configuration documents.
Index ¶
- Variables
- func DefaultTemplate(opts TemplateOptions) (json.RawMessage, error)
- func GeneratePassword(bytes int) string
- func GenerateShortIDs(count int) ([]string, error)
- func ParseInbounds(raw json.RawMessage) ([]domain.ConfigProfileInbound, error)
- func Render(profile json.RawMessage, opts RenderOptions) ([]byte, string, error)
- func SortedTags(raw json.RawMessage) []string
- func Validate(raw json.RawMessage) error
- type Client
- type Document
- type RealityKeyPair
- type RenderOptions
- type Routing
- type TemplateOptions
Constants ¶
This section is empty.
Variables ¶
var ErrNoInbounds = fmt.Errorf("configuration has no inbounds")
ErrNoInbounds signals a profile document that cannot serve any traffic.
Functions ¶
func DefaultTemplate ¶
func DefaultTemplate(opts TemplateOptions) (json.RawMessage, error)
DefaultTemplate builds a VLESS + REALITY profile that is ready to serve traffic as soon as a node picks it up, so a fresh install is never staring at an empty editor.
func GeneratePassword ¶
GeneratePassword returns a base64 secret suitable for trojan or the 2022-blake3 shadowsocks ciphers, which require a 32-byte key.
func GenerateShortIDs ¶
GenerateShortIDs returns REALITY shortIds: even-length hex strings of at most 16 characters.
func ParseInbounds ¶
func ParseInbounds(raw json.RawMessage) ([]domain.ConfigProfileInbound, error)
ParseInbounds extracts the inbound summary rows persisted alongside a profile.
func Render ¶
func Render(profile json.RawMessage, opts RenderOptions) ([]byte, string, error)
Render produces the exact configuration a node should run, together with a hash that lets the agent skip a restart when nothing changed.
func SortedTags ¶
func SortedTags(raw json.RawMessage) []string
SortedTags returns the inbound tags of a document in a stable order.
func Validate ¶
func Validate(raw json.RawMessage) error
Validate checks that a profile document is well formed and every inbound carries a unique, non-empty tag. Tags are the join key between profiles, nodes, squads and hosts, so a missing tag is a hard error rather than a warning.
Types ¶
type Document ¶
type Document struct {
Log json.RawMessage `json:"log,omitempty"`
DNS json.RawMessage `json:"dns,omitempty"`
Inbounds []json.RawMessage `json:"inbounds"`
Outbounds []json.RawMessage `json:"outbounds,omitempty"`
Routing *Routing `json:"routing,omitempty"`
Policy json.RawMessage `json:"policy,omitempty"`
API json.RawMessage `json:"api,omitempty"`
Stats json.RawMessage `json:"stats,omitempty"`
Transport json.RawMessage `json:"transport,omitempty"`
Reverse json.RawMessage `json:"reverse,omitempty"`
FakeDNS json.RawMessage `json:"fakedns,omitempty"`
Metrics json.RawMessage `json:"metrics,omitempty"`
Observ json.RawMessage `json:"observatory,omitempty"`
Burst json.RawMessage `json:"burstObservatory,omitempty"`
}
Document is the subset of an xray-core config the panel needs to reason about. Everything else is preserved verbatim through Extra.
type RealityKeyPair ¶
type RealityKeyPair struct {
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"`
}
RealityKeyPair is an x25519 pair in the encoding xray-core expects.
func GenerateRealityKeys ¶
func GenerateRealityKeys() (*RealityKeyPair, error)
GenerateRealityKeys mirrors `xray x25519`, so the panel can provision REALITY inbounds without shelling out to the binary.
type RenderOptions ¶
type RenderOptions struct {
// ActiveTags restricts the rendered document to these inbounds. Empty means
// every inbound of the profile.
ActiveTags []string
// ClientsByTag maps an inbound tag to the users allowed to use it.
ClientsByTag map[string][]Client
// APIListen is the address the stats API listens on inside the node.
APIListen string
APIPort int
}
RenderOptions controls how a node-specific config is produced from a profile.
type Routing ¶
type Routing struct {
DomainStrategy string `json:"domainStrategy,omitempty"`
DomainMatcher string `json:"domainMatcher,omitempty"`
Rules []json.RawMessage `json:"rules,omitempty"`
Balancers []json.RawMessage `json:"balancers,omitempty"`
}