config

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP2WikiURL         = "https://github.com/Diniboy1123/usque/wiki/HTTP-2-support"
	DefaultEndpointH2V4  = "162.159.198.2"
	DefaultEndpointH2V6  = ""
	EndpointHelpSuffixH2 = " For details: https://github.com/Diniboy1123/usque/wiki/HTTP-2-support"
)

Variables

View Source
var ConfigLoaded bool

ConfigLoaded indicates whether the configuration has been successfully loaded.

Functions

func LoadConfig

func LoadConfig(configPath string) error

LoadConfig loads the application configuration from a JSON file.

Parameters:

  • configPath: string - The path to the configuration JSON file.

Returns:

  • error: An error if the configuration file cannot be loaded or parsed.

func LogHTTP2Endpoint

func LogHTTP2Endpoint(endpoint net.Addr)

LogHTTP2Endpoint prints the wiki reference and active endpoint when HTTP/2 mode is enabled.

func SelectEndpointFromConfig

func SelectEndpointFromConfig(useHTTP2 bool, useIPv6 bool, port int) (net.Addr, error)

SelectEndpointFromConfig returns a protocol-appropriate remote endpoint: TCP for HTTP/2 mode and UDP for HTTP/3 mode.

func WarnInsecure

func WarnInsecure()

WarnInsecure prints a warning when certificate pinning is disabled.

Types

type Config

type Config struct {
	PrivateKey     string `json:"private_key"`      // Base64-encoded ECDSA private key
	EndpointV4     string `json:"endpoint_v4"`      // IPv4 address of the endpoint
	EndpointV6     string `json:"endpoint_v6"`      // IPv6 address of the endpoint
	EndpointH2V4   string `json:"endpoint_h2_v4"`   // IPv4 address used in HTTP/2 mode
	EndpointH2V6   string `json:"endpoint_h2_v6"`   // IPv6 address used in HTTP/2 mode
	EndpointPubKey string `json:"endpoint_pub_key"` // PEM-encoded ECDSA public key of the endpoint to verify against
	License        string `json:"license"`          // Application license key
	ID             string `json:"id"`               // Device unique identifier
	AccessToken    string `json:"access_token"`     // Authentication token for API access
	IPv4           string `json:"ipv4"`             // Assigned IPv4 address
	IPv6           string `json:"ipv6"`             // Assigned IPv6 address

	// Expanded configuration sections
	Socks          SocksConfig          `json:"socks"`
	HTTPProxy      HTTPProxyConfig      `json:"http_proxy"`
	PortForward    PortFwConfig         `json:"port_forward"`
	TransparentTun TransparentTunConfig `json:"transparent_tun"`
	Log            LogConfig            `json:"log"`
}

Config represents the application configuration structure, containing essential details such as keys, endpoints, and access tokens.

var AppConfig Config

AppConfig holds the global application configuration.

func (*Config) GetEcEndpointPublicKey

func (*Config) GetEcEndpointPublicKey() (*ecdsa.PublicKey, error)

GetEcEndpointPublicKey retrieves the ECDSA public key from the stored PEM-encoded string.

Returns:

  • *ecdsa.PublicKey: The parsed ECDSA public key.
  • error: An error if decoding or parsing the public key fails.

func (*Config) GetEcPrivateKey

func (*Config) GetEcPrivateKey() (*ecdsa.PrivateKey, error)

GetEcPrivateKey retrieves the ECDSA private key from the stored Base64-encoded string.

Returns:

  • *ecdsa.PrivateKey: The parsed ECDSA private key.
  • error: An error if decoding or parsing the private key fails.

func (*Config) SaveConfig

func (*Config) SaveConfig(configPath string) error

SaveConfig writes the current application configuration to a prettified JSON file.

Parameters:

  • configPath: string - The path to save the configuration JSON file.

Returns:

  • error: An error if the configuration file cannot be written.

type HTTPProxyConfig

type HTTPProxyConfig struct {
	Enable   bool     `json:"enable"`
	Bind     string   `json:"bind"`
	Port     string   `json:"port"`
	Username string   `json:"username"`
	Password string   `json:"password"`
	DNS      []string `json:"dns"`
	LocalDNS bool     `json:"local_dns"`
}

type LogConfig

type LogConfig struct {
	Enable   bool   `json:"enable"`
	FilePath string `json:"file_path"`
	Level    string `json:"level"`
}

type PortFwConfig

type PortFwConfig struct {
	LocalPorts  []string `json:"local_ports"`
	RemotePorts []string `json:"remote_ports"`
}

type SocksConfig

type SocksConfig struct {
	Enable   bool     `json:"enable"`
	Bind     string   `json:"bind"`
	Port     string   `json:"port"`
	Username string   `json:"username"`
	Password string   `json:"password"`
	DNS      []string `json:"dns"`
	LocalDNS bool     `json:"local_dns"`
}

type TransparentTunConfig

type TransparentTunConfig struct {
	Enable        bool   `json:"enable"`
	InterfaceName string `json:"interface_name"`
	AutoRoute     bool   `json:"auto_route"`
	StrictRoute   bool   `json:"strict_route"`
}

Jump to

Keyboard shortcuts

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