package main // Data model for the xray control-plane. This is the parsed, typed form of the // UCI desired-state (/etc/config/shater) plus subscription-cache nodes. Every // generator/apply step consumes *Model; nothing downstream touches raw UCI. import ( "strconv" "strings" ) // Model is the whole desired-state. type Model struct { Globals Globals Inbounds []Inbound Subscriptions []Subscription Nodes []Node // manual nodes + subscription-cache nodes (see Node.FromSub) Groups []Group Chains []Chain Egresses []Egress Rulesets []Ruleset Rules []Rule Resolvers []Resolver DNSRules []DNSRule } // Globals is the single `config globals` section. type Globals struct { Enabled bool LogLevel string KillSwitch string // closed|open DNSMode string // nftset|fakeip IPv6 bool FwmarkBase uint32 TableBase uint32 ConfirmTimeout int ResolverFallback string ProbeURL string // observatory health-probe URL (default gstatic/generate_204) ProbeInterval string // observatory probe interval (e.g. 60s) } func defaultGlobals() Globals { return Globals{ Enabled: true, LogLevel: "warning", KillSwitch: "closed", DNSMode: "nftset", IPv6: true, FwmarkBase: 0x2000, TableBase: 0x2000, } } // Inbound is a `config inbound` (multi-LAN tproxy entry). type Inbound struct { Name string Enabled bool Network string TproxyPort int TCP bool UDP bool Sniff bool } // Subscription is a `config subscription`. type Subscription struct { Name string Enabled bool URL string UpdateInterval string FetchVia string // direct|proxy UA string HWID string // auto| DeviceOS string VerOS string DeviceModel string Headers []string // raw "Key: val" } // Node is a manual node (`config node`) or a subscription-cache node. type Node struct { Name string Enabled bool URI string FromSub string // "" = manual; else subscription name Fingerprint string Stale bool // Per-node multiplexing + sockopt (T1). All optional; zero values = off, so // existing nodes emit byte-identical outbounds. See applyNodeOpts in generate.go. Mux bool // enable outbound mux MuxConcurrency int // streams per mux connection (xray `concurrency`) XUDPConcurrency int // vless/vmess only (UDP-over-mux) XUDPProxyUDP443 string // reject|allow|skip (vless/vmess only) Mark uint32 // sockopt mark; 0 = use loop-guard 255 (a different value is refused) TCPFastOpen string // "" inherit | "1" on | "0" off TCPKeepAliveIdle int // seconds; 0 = omit } // Group is a `config group`. type Group struct { Name string Source string // subscription|manual Subscription string Nodes []string // manual node names Strategy string // leastping|random|roundrobin|failover|single Include []string Exclude []string ProbeURL string ProbeInterval string } // Chain is a `config chain` (multi-hop L1..Ln). type Chain struct { Name string Hops []string // "group:" | "node:" } // Egress is a `config egress`. type Egress struct { Name string Type string // interface|proxy|direct|block Interface string Target string } // Ruleset is a `config ruleset` (reusable domain/ip list). type Ruleset struct { Name string Type string // domain|ipcidr Source string // inline|file|url URL string Path string Format string UpdateInterval string Entries []string } // Rule is a `config rule` (ordered, first-match). type Rule struct { Name string Enabled bool Order int Src []string DstDomain []string DstRuleset []string DstIP []string DstPort string Proto string Target string // chain:|group:|node:|direct|block Egress string Kill string } // Resolver is a `config resolver`. type Resolver struct { Name string Type string // doh|dot|plain|local|fakeip Address string Detour string Pool string // fakeip CIDR pool (e.g. 198.18.0.0/15) } // DNSRule is a `config dns_rule`. type DNSRule struct { Order int MatchDomain []string MatchSrc []string Resolver string } // --- small parse helpers shared across uci/sub --- func parseBool(s string) bool { switch strings.ToLower(strings.TrimSpace(s)) { case "1", "true", "yes", "on", "enabled": return true } return false } func parseUint32(s string, def uint32) uint32 { s = strings.TrimSpace(s) if s == "" { return def } base := 10 if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") { base = 16 s = s[2:] } v, err := strconv.ParseUint(s, base, 32) if err != nil { return def } return uint32(v) } func parseInt(s string, def int) int { v, err := strconv.Atoi(strings.TrimSpace(s)) if err != nil { return def } return v } // splitTarget splits "kind:name" into ("kind","name"); bare "direct"/"block" // return (value, ""). func splitTarget(t string) (kind, name string) { t = strings.TrimSpace(t) if i := strings.IndexByte(t, ':'); i >= 0 { return t[:i], t[i+1:] } return t, "" }