config

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const FakeClientHello = "" +
	"\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x9a\x8f\xa7" +
	"\x6a\x5d\x57\xf3\x62\x19\xbe\x46\x82\x45\xe2\x59\x5c\xb4" +
	"\x48\x31\x12\x15\x14\x79\x2c\xaa\xcd\xea\xda\xf0\xe1\xfd" +
	"\xbb\x20\xf4\x83\x2a\x94\xf1\x48\x3b\x9d\xb6\x74\xba\x3c" +
	"\x81\x63\xbc\x18\xcc\x14\x45\x57\x6c\x80\xf9\x25\xcf\x9c" +
	"\x86\x60\x50\x31\x2e\xe9\x00\x22\x13\x01\x13\x03\x13\x02" +
	"\xc0\x2b\xc0\x2f\xcc\xa9\xcc\xa8\xc0\x2c\xc0\x30\xc0\x0a" +
	"\xc0\x09\xc0\x13\xc0\x14\x00\x9c\x00\x9d\x00\x2f\x00\x35" +
	"\x01\x00\x01\x91\x00\x00\x00\x14\x00\x12\x00\x00\x0f\x77" +
	"\x77\x77\x2e\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d\x00" +
	"\x17\x00\x00\xff\x01\x00\x01\x00\x00\x0a\x00\x0e\x00\x0c" +
	"\x00\x1d\x00\x17\x00\x18\x00\x19\x01\x00\x01\x01\x00\x0b" +
	"\x00\x02\x01\x00\x00\x23\x00\x00\x00\x10\x00\x0e\x00\x0c" +
	"\x02\x68\x32\x08\x68\x74\x74\x70\x2f\x31\x2e\x31\x00\x05" +
	"\x00\x05\x01\x00\x00\x00\x00\x00\x0d\x00\x18\x00\x16\x04" +
	"\x03\x05\x03\x06\x03\x08\x04\x08\x05\x08\x06\x04\x01\x05" +
	"\x01\x06\x01\x02\x03\x02\x01\x00\x12\x00\x00\x00\x33\x00" +
	"\x6b\x00\x69\x00\x1d\x00\x20\x67\xb1\x88\x18\x47\x6e\xc3" +
	"\xc1\x83\x73\xb1\xa9\x80\x42\x36\xb6\xe1\x66\x6e\xb6\x6c" +
	"\x32\x9b\xc3\xf3\x18\x29\x7c\xff\xc1\x77\x7c\x00\x17\x00" +
	"\x41\x04\xa6\xb6\xb1\xb1\xc6\x4d\xb1\x86\xa1\x8a\x80\x4d" +
	"\xa6\x35\x57\xa1\xc4\x88\x9a\x9c\xa9\x6d\x6e\x67\xa6\x47" +
	"\x59\xc6\x82\x10\x06\xc9\x9b\x12\x91\x6c\xa1\xc4\x8d\xb1" +
	"\xc6\x95\xa9\xc7\x9c\x06\xa1\xa3\x83\xb6\x59\xa6\x40\x73" +
	"\x83\xc6\x95\x59\xa9\xb1\x18\xc1\x6d\x9b\xa6\x49\x9c\x47" +
	"\x16\xc1\xa6\x59\xa9\x18\xc7\x9c\x18\x4d\xa6\x9b\x4d\x6d" +
	"\x57\x16\x16\x95\xa6\xc7\x96\x67\x96\x16\x69\x82\x95\x91" +
	"\x83\x49\xc7\x06\x82\x6c\xb6\x6c\x96\xa3\xc1\xb1\xc1\x86" +
	"\x16\xa3\xc1\xb1\xc4\x95\xa6\x67\xb1\x86\xa3\xc1\xa6\x16" +
	"\xa6\xc4\x06\x6e\x6d\x99\x47\x6c\xa1\x82\x06\xc4\x18\xa6" +
	"\xc4\x69\xa3\x9b\xa3\x40\x6e\xa9\xb1\xa6\x95\x73\xc1\x88" +
	"\x06\x95\x4d\xa9\x40\x4d\x67\x88\x96\xa6\x67\x18\x06\x69" +
	"\x99\xa3\x88\x88\xa9\x6e\xa1\x99\x06\x95\x06\xa9\x83\x4d" +
	"\x16\x73\x47\x88\x67\xa6\x6c\xa6\x18\xc1\xa6\x95\x59\xa3" +
	"\x9b\x96\xa3\x73\xb6\x06\xa1\x18\x6e\x67\x67\xa1\x91\x4d" +
	"\xa6\x59\x9c\x82\x86\x95\x16\xa3\x47\x95\x18\x96\x95\x06" +
	"\xa6\xc7\x47\xc7\x82\x47\x9b\x18\x73\x9b\x18\x91\x99\x18" +
	"\x9c\xa6\x9c\xa9\x67\xc7\x96\x18\x06\xc4\x9c\xc4\x83\x47" +
	"\x18\x59\x96\x47\x91\xa1\x47\x06\xb6\x69\x6c\x99\x4d\x69" +
	"\xa1\x59\x18\xc1\x47\x6c\x6e\x91\x9b\x6e\x67\xa6\x91\xa3" +
	"\xc4\x47\xb1\x47\xa3\x95\x49\x73\x95\x88\x18\x59\x82\xc7" +
	"\xa9\x99\xc6\x99\xa3\x88\x6c\x67\x6c\xa6\xa6\xb1\xc7\x67" +
	"\x59\x99\x06\x4d\xa3\x95\x49\xc4\x69\x6e\x4d\x96\x47\x4d" +
	"\xa1\xa1\xa1\x99\xa9\xb1\x82\xa9\x16\x40\x95\x95\x82\x82" +
	"\x91\x47\xa6\x40\x91\x91\x99\xa9\x06\xa9\x88\x9c\xa9\xa9" +
	"\x18\x47\x6e\x9b\x9b\xa3\xa9\xc7\x6e\xa3\xa3\xc7\xb1\x47" +
	"\x4d\x83\xa9\xc4\x49\x4d\x9c\x91\xa9\x47\xb6\xa9\x4d\x47"

Variables

View Source
var (
	WarnMsgs []string
)

Functions

func AddWarnMsg added in v1.5.2

func AddWarnMsg(msg string)

func CreateCommand

func CreateCommand(
	runFunc func(ctx context.Context, configDir string, cfg *Config) error,
	version string,
	commit string,
	build string,
) *cli.Command

func MustParseBytes

func MustParseBytes(s string) []byte

func MustParseHexCSV

func MustParseHexCSV(data []byte) string

func MustParseIPv4 added in v1.6.0

func MustParseIPv4(s string) net.IP

func MustParseLogLevel

func MustParseLogLevel(s string) zerolog.Level

func MustParseTCPAddr

func MustParseTCPAddr(s string) net.TCPAddr

Types

type AppModeType

type AppModeType int
const (
	AppModeHTTP AppModeType = iota
	AppModeSOCKS5
	AppModeTUN
)

func MustParseServerModeType

func MustParseServerModeType(s string) AppModeType

func (AppModeType) MarshalText added in v1.5.0

func (t AppModeType) MarshalText() ([]byte, error)

func (AppModeType) String

func (t AppModeType) String() string

type AppOptions

type AppOptions struct {
	NoTUI                bool          `toml:"no-tui"`
	LogLevel             zerolog.Level `toml:"log-level"`
	Silent               bool          `toml:"silent"`
	AutoConfigureNetwork bool          `toml:"auto-configure-network"`
	Mode                 AppModeType   `toml:"mode"`
	ListenAddr           net.TCPAddr   `toml:"listen-addr"`
	Gateway              net.IP        `toml:"gateway"`     // nil: discover from the routing table
	FreebsdFIB           int           `toml:"freebsd-fib"` // FreeBSD only: FIB ID for routing (2-15)
}

func (*AppOptions) UnmarshalTOML

func (o *AppOptions) UnmarshalTOML(data any) (err error)

type Config

type Config struct {
	App   AppOptions
	Rules []Rule
	RuntimeConfig
}

Config is the fully-loaded configuration.

  • App is read once at boot (logger setup, mode selection, network setup) and is not needed at request time.
  • Rules holds the fully-resolved per-rule configurations. Populated by Load.resolveRules (in load.go) after defaults+TOML+CLI are merged, so each rule's Config is pre-filled from the base RuntimeConfig and consumers can use rule.Config.X directly without re-merging at request time.
  • The embedded RuntimeConfig is the base per-request configuration. Its sections are promoted, so they are accessed as cfg.Conn, cfg.HTTPS, etc.

func DefaultConfig added in v1.5.0

func DefaultConfig() *Config

DefaultConfig returns a fully-populated Config with default values for every field. Used as the starting point of the load pipeline (defaults → TOML → CLI → Finalize → Validate). Tests that need a single section (e.g. base RuntimeConfig for resolveRules) reach in via DefaultConfig().RuntimeConfig / .App.

func Load added in v1.5.0

func Load(cmd *cli.Command, cliOverrides []func(*Config)) (*Config, string, error)

Load assembles the effective Config from three sources, in precedence order: defaults → TOML → CLI flags. After all layers are merged it runs Finalize (cross-field defaults), resolveRules (eager-resolve rules on top of the finalized base RuntimeConfig), and Validate (semantic checks). Returns the resolved Config and the path of the TOML file that was used (or "" if none).

cliOverrides is the slice of closures appended by Flag.Action callbacks during cmd.Run — one per flag the user actually set. Applying them after loadTOML is what makes CLI win over TOML.

func (*Config) Finalize added in v1.5.0

func (c *Config) Finalize() error

Finalize applies defaults that depend on other fields (e.g. ListenAddr per Mode). Called after defaults+TOML+CLI layers are merged, before Validate. Rule resolution is handled separately by Load via resolveRules so Config doesn't need to carry load-time scratch state into the runtime config.

func (*Config) NeedsPcap added in v1.5.2

func (c *Config) NeedsPcap() bool

NeedsPcap reports whether any raw packet capture is needed.

func (*Config) NeedsPcapTCP added in v1.5.2

func (c *Config) NeedsPcapTCP() bool

NeedsPcapTCP reports whether any TCP fake-packet feature is enabled — either in the base config or in any rule. The TCP raw packet IO (sniffer + writer) is only set up when this returns true.

func (*Config) NeedsPcapUDP added in v1.5.2

func (c *Config) NeedsPcapUDP() bool

NeedsPcapUDP is the UDP counterpart of NeedsPcapTCP.

func (*Config) NeedsRoute added in v1.5.6

func (c *Config) NeedsRoute() bool

NeedsRoute reports whether the default route must be discovered at startup: raw packet capture needs the gateway, and TUN mode routes traffic through it.

func (*Config) UnmarshalTOML

func (c *Config) UnmarshalTOML(data any) (err error)

func (*Config) Validate added in v1.5.0

func (c *Config) Validate() error

Validate runs cross-field semantic checks on the resolved Config. Format-level validation (e.g. "valid log level") happens earlier during UnmarshalTOML / CLI Validators; this pass catches issues that can only be detected once defaults+TOML+CLI are merged and rules are eager-resolved.

type ConnOptions

type ConnOptions struct {
	DefaultFakeTTL uint8         `toml:"default-fake-ttl"`
	DNSTimeout     time.Duration `toml:"dns-timeout"`
	TCPTimeout     time.Duration `toml:"tcp-timeout"`
	UDPIdleTimeout time.Duration `toml:"udp-idle-timeout"`
}

func (ConnOptions) MarshalJSON added in v1.5.0

func (o ConnOptions) MarshalJSON() ([]byte, error)

MarshalJSON renders durations via String() (e.g. "10s") instead of raw nanoseconds so trace logs are readable.

func (*ConnOptions) UnmarshalTOML

func (o *ConnOptions) UnmarshalTOML(data any) (err error)

type DNSModeType

type DNSModeType int
const (
	DNSModeUDP DNSModeType = iota
	DNSModeHTTPS
	DNSModeSystem
)

func MustParseDNSModeType

func MustParseDNSModeType(s string) DNSModeType

func (DNSModeType) MarshalText added in v1.5.0

func (t DNSModeType) MarshalText() ([]byte, error)

func (DNSModeType) String

func (t DNSModeType) String() string

type DNSOptions

type DNSOptions struct {
	Mode     DNSModeType  `toml:"mode"`
	Addr     net.TCPAddr  `toml:"addr"`
	HTTPSURL string       `toml:"https-url"`
	QType    DNSQueryType `toml:"qtype"`
	Cache    bool         `toml:"cache"`
}

func (DNSOptions) MarshalJSON added in v1.5.0

func (o DNSOptions) MarshalJSON() ([]byte, error)

MarshalJSON renders Addr as "host:port" (net.TCPAddr's default JSON dumps each field separately) and lets the enums use their MarshalText for string output.

func (*DNSOptions) UnmarshalTOML

func (o *DNSOptions) UnmarshalTOML(data any) (err error)

type DNSQueryType

type DNSQueryType int
const (
	DNSQueryIPv4 DNSQueryType = iota
	DNSQueryIPv6
	DNSQueryAll
)

func MustParseDNSQueryType

func MustParseDNSQueryType(s string) DNSQueryType

func (DNSQueryType) MarshalText added in v1.5.0

func (t DNSQueryType) MarshalText() ([]byte, error)

func (DNSQueryType) String

func (t DNSQueryType) String() string

type HTTPSOptions

type HTTPSOptions struct {
	Disorder           bool               `toml:"disorder"`
	FakeCount          uint8              `toml:"fake-count"`
	FakePacket         *proto.TLSMessage  `toml:"fake-packet"`
	SplitMode          HTTPSSplitModeType `toml:"split-mode"`
	ChunkSize          uint8              `toml:"chunk-size"`
	Skip               bool               `toml:"skip"`
	CustomSegmentPlans []SegmentPlan      `toml:"custom-segments"`
}

func (HTTPSOptions) MarshalJSON added in v1.5.0

func (o HTTPSOptions) MarshalJSON() ([]byte, error)

MarshalJSON omits FakePacket (a 64-byte buffer that's noise in trace logs), surfaces fake-packet length separately, and renders CustomSegmentPlans as a compact "N items" count for the same reason MatchAttrs does — segment plans are static config the user defined, not something to re-dump on every match trace.

func (*HTTPSOptions) UnmarshalTOML

func (o *HTTPSOptions) UnmarshalTOML(data any) (err error)

type HTTPSSplitModeType

type HTTPSSplitModeType int
const (
	HTTPSSplitModeSNI HTTPSSplitModeType = iota
	HTTPSSplitModeRandom
	HTTPSSplitModeChunk
	HTTPSSplitModeFirstByte
	HTTPSSplitModeCustom
	HTTPSSplitModeNone
)

func (HTTPSSplitModeType) MarshalText added in v1.5.0

func (k HTTPSSplitModeType) MarshalText() ([]byte, error)

func (HTTPSSplitModeType) String

func (k HTTPSSplitModeType) String() string

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type MatchAttrs

type MatchAttrs struct {
	Domains []string `toml:"domains"`
	CIDRs   []string `toml:"cidrs"`
}

func (MatchAttrs) MarshalJSON added in v1.5.0

func (a MatchAttrs) MarshalJSON() ([]byte, error)

func (*MatchAttrs) UnmarshalTOML

func (a *MatchAttrs) UnmarshalTOML(data any) (err error)

type Rule

type Rule struct {
	Name     string        `toml:"name"     json:"name"`
	Priority uint16        `toml:"priority" json:"priority"`
	Block    bool          `toml:"block"    json:"block"`
	Match    *MatchAttrs   `toml:"match"    json:"match,omitempty"`
	Config   RuntimeConfig `toml:"-"        json:"config"`
}

func (*Rule) Clone

func (r *Rule) Clone() *Rule

Clone returns a shallow copy of r. Matchers use this so callers receive a rule they can't accidentally mutate back into the matcher's state.

func (*Rule) JSON

func (r *Rule) JSON() []byte

JSON returns the rule serialized for trace logging. Per-section MarshalJSON handles enum-as-string, addr-as-"host:port", duration-as-string, IPNet-as-CIDR, and elides large fake-packet buffers in favor of a length, so the output is compact and human-readable on a single line.

func (*Rule) UnmarshalTOML

func (r *Rule) UnmarshalTOML(data any) (err error)

UnmarshalTOML decodes the standalone fields of a Rule. The per-section config overrides (dns/https/udp/connection) are NOT decoded here — resolveRules in load.go handles them so it can pre-fill from the finalized base RuntimeConfig before overlaying the rule's TOML.

type RuntimeConfig added in v1.5.0

type RuntimeConfig struct {
	Conn  ConnOptions  `json:"conn"`
	DNS   DNSOptions   `json:"dns"`
	HTTPS HTTPSOptions `json:"https"`
	UDP   UDPOptions   `json:"udp"`
}

RuntimeConfig holds the sections accessed on the request hot path. Handlers take a pointer to RuntimeConfig (not the individual *XOptions) so adding a new section doesn't require touching every signature, and rule overrides can swap the whole RuntimeConfig in a single assignment.

type SegmentFromType

type SegmentFromType int
const (
	SegmentFromHead SegmentFromType = iota
	SegmentFromSNI
)

func (SegmentFromType) MarshalText added in v1.5.0

func (s SegmentFromType) MarshalText() ([]byte, error)

func (SegmentFromType) String

func (s SegmentFromType) String() string

type SegmentPlan

type SegmentPlan struct {
	From  SegmentFromType `toml:"from"`
	At    int             `toml:"at"`
	Lazy  bool            `toml:"lazy"`
	Noise int             `toml:"noise"`
}

func (*SegmentPlan) UnmarshalTOML

func (s *SegmentPlan) UnmarshalTOML(data any) (err error)

type UDPOptions

type UDPOptions struct {
	Skip       bool   `toml:"skip"`
	FakeCount  uint8  `toml:"fake-count"`
	FakePacket []byte `toml:"fake-packet"`
}

func (UDPOptions) MarshalJSON added in v1.5.0

func (o UDPOptions) MarshalJSON() ([]byte, error)

MarshalJSON omits the raw FakePacket bytes (default is 64 zeros, dumped as base64 they're trace-log noise) but surfaces the length so the user can tell whether a packet is configured.

func (*UDPOptions) UnmarshalTOML

func (o *UDPOptions) UnmarshalTOML(data any) (err error)

Jump to

Keyboard shortcuts

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