Documentation
¶
Overview ¶
Package config defines cheburbox.json schema types and provides loading, discovery, and validation for server configurations.
Index ¶
- Constants
- func Discover(projectRoot string) ([]string, error)
- func UserName(users []InboundUser) []string
- func Validate(cfg Config) error
- type AmneziaConfig
- type BrutalConfig
- type CacheFileConfig
- type Config
- type DNS
- type DNSServer
- type Experimental
- type Inbound
- type InboundMultiplex
- type InboundTLS
- type InboundUser
- type MasqueradeConfig
- type ObfsConfig
- type Outbound
- type OutboundMultiplex
- type PersistedCredentials
- type RealityConfig
- type RealityHandshake
- type RealityKeyPair
- type Route
- type UserCredentials
- type WireGuardEndpointCreds
- type WireGuardPeerCreds
Constants ¶
const CurrentSchemaVersion = 1
CurrentSchemaVersion is the only supported cheburbox.json schema version.
Variables ¶
This section is empty.
Functions ¶
func Discover ¶
Discover finds all direct child directories under projectRoot that contain cheburbox.json or .cheburbox.jsonnet. Returns sorted directory names.
func UserName ¶
func UserName(users []InboundUser) []string
UserName returns a slice of user names from InboundUser entries.
Types ¶
type AmneziaConfig ¶
type AmneziaConfig struct {
Protocol string `json:"protocol,omitempty"` // quic|dns|dtls|stun|sip|rtp|random; default quic
Preset string `json:"preset,omitempty"` // amnezigo preset name; empty → random params
MTU int `json:"mtu,omitempty"` // default 1280
}
AmneziaConfig holds AmneziaWG obfuscation preferences. Protocol, Preset, and MTU are user-facing; the actual Jc/S1/H1/I1 parameters are produced by amnezigo (from the named preset or, when Preset is empty, fully random) and persisted in config.json so they stay stable across runs.
type BrutalConfig ¶
type BrutalConfig struct {
Enabled bool `json:"enabled,omitempty"`
UpMbps int `json:"up_mbps,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
}
BrutalConfig holds TCP Brutal congestion-control configuration for multiplex. It mirrors sing-box BrutalOptions and only takes effect when the multiplex brutal block is enabled.
type CacheFileConfig ¶
type CacheFileConfig struct {
Enabled *bool `json:"enabled,omitempty"`
}
CacheFileConfig controls the sing-box cache_file feature.
type Config ¶
type Config struct {
DNS DNS `json:"dns"`
Log json.RawMessage `json:"log,omitempty"`
Inbounds []Inbound `json:"inbounds,omitempty"`
Outbounds []Outbound `json:"outbounds,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Version int `json:"version"`
Route *Route `json:"route,omitempty"`
Experimental *Experimental `json:"experimental,omitempty"`
}
Config is the top-level cheburbox.json configuration.
func LoadServerWithJsonnet ¶
LoadServerWithJsonnet reads, evaluates (if .cheburbox.jsonnet), and parses the config from dir. If jpath is non-empty, it is used as the jsonnet library search path. .cheburbox.jsonnet takes precedence over cheburbox.json.
type DNS ¶
type DNS struct {
Final *string `json:"final,omitempty"`
Strategy *string `json:"strategy,omitempty"`
CacheCapacity *uint32 `json:"cache_capacity,omitempty"`
Servers []DNSServer `json:"servers"`
Rules json.RawMessage `json:"rules,omitempty"`
}
DNS holds the DNS configuration section.
type DNSServer ¶
type DNSServer struct {
Type string `json:"type"`
Tag string `json:"tag"`
Server string `json:"server,omitempty"`
Detour string `json:"detour,omitempty"`
ServerPort int `json:"server_port,omitempty"`
}
DNSServer represents a single DNS server entry.
type Experimental ¶
type Experimental struct {
CacheFile *CacheFileConfig `json:"cache_file,omitempty"`
}
Experimental holds optional experimental sing-box settings.
type Inbound ¶
type Inbound struct {
Amnezia *AmneziaConfig `json:"amnezia,omitempty"`
Obfs *ObfsConfig `json:"obfs,omitempty"`
TLS *InboundTLS `json:"tls,omitempty"`
Masq *MasqueradeConfig `json:"masquerade,omitempty"`
Multiplex *InboundMultiplex `json:"multiplex,omitempty"`
Type string `json:"type"`
Stack string `json:"stack,omitempty"`
Tag string `json:"tag"`
Listen string `json:"listen,omitempty"`
InterfaceName string `json:"interface_name,omitempty"`
ExcludeInterface []string `json:"exclude_interface,omitempty"`
Address []string `json:"address,omitempty"`
Users []InboundUser `json:"users,omitempty"`
RouteExcludeAddress []string `json:"route_exclude_address,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
UpMbps int `json:"up_mbps,omitempty"`
MTU int `json:"mtu,omitempty"`
ListenPort int `json:"listen_port,omitempty"`
IPRoute2TableIndex int `json:"iproute2_table_index,omitempty"`
IPRoute2RuleIndex int `json:"iproute2_rule_index,omitempty"`
AutoRoute bool `json:"auto_route,omitempty"`
AutoRedirect bool `json:"auto_redirect,omitempty"`
StrictRoute bool `json:"strict_route,omitempty"`
EndpointIndependentNAT bool `json:"endpoint_independent_nat,omitempty"`
}
Inbound represents a single inbound configuration. Use Type field to determine which fields are relevant.
type InboundMultiplex ¶
type InboundMultiplex struct {
Brutal *BrutalConfig `json:"brutal,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Padding bool `json:"padding,omitempty"`
}
InboundMultiplex holds sing-box multiplex (mux) configuration for VLESS inbounds. It mirrors sing-box InboundMultiplexOptions: the server accepts whichever protocol the client selects, so no protocol field is present.
type InboundTLS ¶
type InboundTLS struct {
Reality *RealityConfig `json:"reality,omitempty"`
ServerName string `json:"server_name,omitempty"`
ALPN []string `json:"alpn,omitempty"`
}
InboundTLS holds TLS configuration for an inbound.
type InboundUser ¶
InboundUser represents a user declaration on an inbound. Name is required. Flow is optional and only used for VLESS inbounds.
type MasqueradeConfig ¶
type MasqueradeConfig struct {
Type string `json:"type"`
URL string `json:"url,omitempty"`
RewriteHost bool `json:"rewrite_host,omitempty"`
}
MasqueradeConfig holds masquerade configuration for hysteria2.
type ObfsConfig ¶
ObfsConfig holds obfuscation configuration for hysteria2.
type Outbound ¶
type Outbound struct {
Multiplex *OutboundMultiplex `json:"multiplex,omitempty"`
URL string `json:"url,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`
Inbound string `json:"inbound,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Flow string `json:"flow,omitempty"`
DomainResolver string `json:"domain_resolver,omitempty"`
Interval string `json:"interval,omitempty"`
Type string `json:"type"`
Server string `json:"server,omitempty"`
Tag string `json:"tag"`
User string `json:"user,omitempty"`
Delay string `json:"delay,omitempty"`
Strategy string `json:"strategy,omitempty"`
BlacklistTimeout string `json:"blacklist_timeout,omitempty"`
Address []string `json:"address,omitempty"`
Outbounds []string `json:"outbounds,omitempty"`
MTU int `json:"mtu,omitempty"`
Tolerance uint16 `json:"tolerance,omitempty"`
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
}
Outbound represents a single outbound configuration. Use Type field to determine which fields are relevant.
type OutboundMultiplex ¶
type OutboundMultiplex struct {
Brutal *BrutalConfig `json:"brutal,omitempty"`
Protocol string `json:"protocol,omitempty"`
MaxConnections int `json:"max_connections,omitempty"`
MinStreams int `json:"min_streams,omitempty"`
MaxStreams int `json:"max_streams,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Padding bool `json:"padding,omitempty"`
}
OutboundMultiplex holds sing-box multiplex (mux) configuration for VLESS outbounds. It mirrors sing-box OutboundMultiplexOptions: the client selects the protocol and connection/stream limits. Protocol must be one of the sing-box mux protocols (h2mux, smux, yamux); empty defaults to h2mux.
type PersistedCredentials ¶
type PersistedCredentials struct {
InboundUsers map[string]map[string]UserCredentials
RealityKeys map[string]RealityKeyPair
ObfsPasswords map[string]string
WireGuardEndpoints map[string]WireGuardEndpointCreds
}
PersistedCredentials holds all credentials extracted from a sing-box config.json.
func EmptyPersistedCredentials ¶
func EmptyPersistedCredentials() PersistedCredentials
EmptyPersistedCredentials returns a zero-value PersistedCredentials with initialized maps.
func ExtractCredentials ¶
func ExtractCredentials(opts *option.Options) PersistedCredentials
ExtractCredentials extracts all credentials from a parsed sing-box Options struct, including VLESS users with UUIDs, Hysteria2 users with passwords, Reality key pairs, obfuscation passwords, and AmneziaWG wireguard endpoints (private keys, amnezia params, and per-peer public/preshared keys).
func LoadPersistedCredentials ¶
func LoadPersistedCredentials(configPath string) (PersistedCredentials, error)
LoadPersistedCredentials reads a sing-box config.json from configPath, parses it using sing-box option structs, and extracts all credentials. A generated config.json carries its wireguard endpoints under the top-level "endpoints" array; option.Options deserializes them into Endpoints, where ExtractCredentials picks up the AmneziaWG ones. Returns empty credentials if the file does not exist.
type RealityConfig ¶
type RealityConfig struct {
Handshake *RealityHandshake `json:"handshake"`
ShortID []string `json:"short_id,omitempty"`
}
RealityConfig holds TLS reality configuration for VLESS inbounds.
type RealityHandshake ¶
RealityHandshake holds the handshake server details for reality.
type RealityKeyPair ¶
RealityKeyPair holds Reality TLS key material for an inbound.
type Route ¶
type Route struct {
Final string `json:"final,omitempty"`
DefaultDomainResolver string `json:"default_domain_resolver,omitempty"`
RuleSets json.RawMessage `json:"rule_sets,omitempty"`
CustomRuleSets []string `json:"custom_rule_sets,omitempty"`
Rules json.RawMessage `json:"rules,omitempty"`
AutoDetectInterface bool `json:"auto_detect_interface,omitempty"`
}
Route holds the routing configuration section.
type UserCredentials ¶
UserCredentials holds UUID or password for a single inbound user.
type WireGuardEndpointCreds ¶
type WireGuardEndpointCreds struct {
Amnezia *option.WireGuardAmnezia
Peers map[string]WireGuardPeerCreds
PrivateKey string
}
WireGuardEndpointCreds holds persisted credentials for one wireguard endpoint. Only endpoints with a non-nil Amnezia block (i.e. AmneziaWG) are persisted; plain wireguard endpoints are skipped.
type WireGuardPeerCreds ¶
type WireGuardPeerCreds struct {
PublicKey string
}
WireGuardPeerCreds holds persisted per-peer key material. The endpoint's own private key lives at WireGuardEndpointCreds.PrivateKey (set for both server and client endpoints); per-peer we keep the peer PublicKey and PresharedKey. The map is keyed by peer PublicKey since wireguard peers carry no name field.