config

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Index

Constants

View Source
const (
	DefaultPACRejectRuleURL      = "https://gcore.jsdelivr.net/gh/TG-Twilight/AWAvenue-Ads-Rule@main/Filters/AWAvenue-Ads-Rule-Clash.yaml"
	DefaultImplicitRejectRuleURL = "https://fastly.jsdelivr.net/gh/TG-Twilight/AWAvenue-Ads-Rule@main/Filters/AWAvenue-Ads-Rule-Clash.yaml"
)
View Source
const (
	RejectRulePrefix = "!"

	ProxyRulePrefixDash       = "-"
	ProxyRulePrefixUnderscore = "_"
)

Variables

This section is empty.

Functions

func BuildShortLinkFromConfig

func BuildShortLinkFromConfig(cfg *Config, advertiseHost string) (string, error)

BuildShortLinkFromConfig builds a sudoku:// short link from the provided config.

If cfg.ServerAddress is empty, advertiseHost can be used to provide the public host[:port]. For server configs, when advertiseHost is empty, we try to derive the host from fallback_address (host part) and use local_port as the advertised port.

func DefaultPACRuleURLs

func DefaultPACRuleURLs() []string

DefaultPACRuleURLs returns the recommended PAC rule sources.

The list is intentionally small and CDN-friendly, and should cover both IPv4 and IPv6 CN traffic.

func RuntimeRuleURLs added in v0.4.1

func RuntimeRuleURLs(proxyMode string, ruleURLs []string) (direct []string, proxy []string, reject []string)

func Save

func Save(path string, cfg *Config) error

Save writes the config to disk with indentation.

Types

type Config

type Config struct {
	Mode               string         `json:"mode"`      // "client" or "server"
	Transport          string         `json:"transport"` // "tcp" or "udp"
	LocalPort          int            `json:"local_port"`
	ServerAddress      string         `json:"server_address"`
	FallbackAddr       string         `json:"fallback_address"`
	Key                string         `json:"key"`
	AEAD               string         `json:"aead"`              // "aes-128-gcm", "chacha20-poly1305", "none"
	SuspiciousAction   string         `json:"suspicious_action"` // "fallback" or "silent"
	PaddingMin         int            `json:"padding_min"`
	PaddingMax         int            `json:"padding_max"`
	RuleURLs           []string       `json:"rule_urls"`            // Routing rule sources; supports "global"/"direct" keywords plus prefixed action sources.
	ProxyMode          string         `json:"proxy_mode"`           // Runtime state, populated by Load logic
	ASCII              string         `json:"ascii"`                // "prefer_entropy", "prefer_ascii", or directional "up_ascii_down_entropy"/"up_entropy_down_ascii"
	CustomTable        string         `json:"custom_table"`         // Optional: defines X/P/V layout, e.g. "xpxvvpvv"
	CustomTables       []string       `json:"custom_tables"`        // Optional: rotate among multiple X/P/V layouts
	EnablePureDownlink bool           `json:"enable_pure_downlink"` // Enable pure Sudoku downlink; false uses bandwidth-optimized packed encoding
	Multiplex          string         `json:"multiplex"`            // "off", "auto", or "on"; same setting as httpmask.multiplex for compatibility
	HTTPMask           HTTPMaskConfig `json:"httpmask"`

	Reverse *ReverseConfig `json:"reverse,omitempty"`
}
func BuildConfigFromShortLink(link string) (*Config, error)

BuildConfigFromShortLink parses a sudoku:// short link and returns a client config. The generated config is ready to run a PAC proxy.

func Load

func Load(path string) (*Config, error)

func (*Config) Finalize

func (c *Config) Finalize() error

Finalize normalizes and validates cross-field settings after loading/unmarshalling.

func (*Config) HTTPMaskSessionMuxEnabled

func (c *Config) HTTPMaskSessionMuxEnabled() bool

func (*Config) HTTPMaskTunnelEnabled

func (c *Config) HTTPMaskTunnelEnabled() bool

func (*Config) MultiplexMode added in v0.4.8

func (c *Config) MultiplexMode() string

func (*Config) SessionMuxEnabled added in v0.4.8

func (c *Config) SessionMuxEnabled() bool

type HTTPMaskConfig

type HTTPMaskConfig struct {
	Disable bool   `json:"disable"`
	Mode    string `json:"mode"`
	TLS     bool   `json:"tls"`
	Host    string `json:"host"`
	// PathRoot optionally prefixes all HTTP mask paths with a first-level segment.
	// Example: "aabbcc" => "/aabbcc/session", "/aabbcc/api/v1/upload", ...
	PathRoot string `json:"path_root"`
	// Multiplex is the legacy JSON location for Config.Multiplex:
	//   - "off": disable session mux and HTTPMask transport reuse
	//   - "auto": enable HTTPMask transport reuse only
	//   - "on": enable session mux over raw TCP or HTTPMask
	Multiplex string `json:"multiplex"`
}

HTTPMaskConfig groups all HTTP masking / tunnel related settings.

This is a "presentation layer" config that can be serialized to config.json as:

"httpmask": {
  "disable": false,
  "mode": "legacy|stream|poll|auto|ws",
  "tls": false,
  "host": "",
  "path_root": "",
  "multiplex": "off|auto|on"
}

type ReverseConfig

type ReverseConfig struct {
	// Listen enables the server-side reverse HTTP entrypoint.
	// Example: ":8081"
	// Empty disables the reverse HTTP server.
	Listen string `json:"listen,omitempty"`

	// ClientID is an optional stable identifier for this reverse client (used for logging).
	// When empty, the server may fall back to the handshake user hash (if available).
	ClientID string `json:"client_id,omitempty"`

	// Routes is the list of client services to expose.
	// Each route maps a public path prefix to a client-side TCP target (HTTP service).
	// Targets may use either an IP literal or a domain name.
	Routes []ReverseRoute `json:"routes,omitempty"`
}

ReverseConfig enables "reverse proxy over Sudoku tunnel": a client behind NAT keeps a tunnel to the server, and the server exposes client services via HTTP path prefixes (e.g. /gitea -> gitea.intra.example.com:3000 on client).

- Server mode: set Listen (e.g. ":8081") to start the reverse HTTP entry. - Client mode: set Routes to expose local services to the server.

type ReverseRoute

type ReverseRoute struct {
	// Path is the public path prefix for HTTP reverse. Examples: "/gitea", "/nas".
	//
	// When Path is empty, the route becomes a raw TCP reverse mapping on reverse.listen (no HTTP).
	// In that case, the server will forward non-HTTP connections to Target.
	// Only one TCP route is supported per reverse.listen entry.
	Path string `json:"path"`
	// Target is the client-side TCP target in "host:port" form.
	// The host may be an IP literal or a domain name.
	Target string `json:"target"`
	// StripPrefix controls whether the prefix should be stripped before proxying.
	// Default: true.
	StripPrefix *bool `json:"strip_prefix,omitempty"`
	// HostHeader optionally overrides the HTTP Host header when proxying.
	// When empty and Target uses a domain host, the proxy forwards that target host by default.
	HostHeader string `json:"host_header,omitempty"`
}

Jump to

Keyboard shortcuts

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