config

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 13 Imported by: 1 module, 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 (
	LocalTCP         = "tcp"
	LocalUDP         = "udp"
	LocalTCPUDP      = "tcp_udp"
	LocalMixed       = "mixed"       // HTTP and SOCKS5 proxy
	LocalSOCKS5      = "socks5"      // the SOCKS5 half of mixed alone
	LocalHTTP        = "http"        // the HTTP half of mixed alone
	LocalTransparent = "transparent" // transparent proxy (Linux)
)

Listener types of a LocalServer.

View Source
const (
	ConnAuto   = "auto"   // direct when hole punching succeeds, else relayed by nps
	ConnRelay  = "relay"  // always relayed by nps
	ConnDirect = "direct" // only direct; fails when hole punching does
)

Connection modes of a LocalServer, as the later major version names them.

Variables

LocalTypes and ConnModes are the accepted values.

Functions

func IsAccountType added in v0.35.0

func IsAccountType(t string) bool

IsAccountType reports whether a listener type is a mixed, socks5 or http proxy, the types that take proxy accounts.

func IsProxyType added in v0.35.0

func IsProxyType(t string) bool

IsProxyType reports whether a listener type is a proxy that reads the destination from each connection: mixed, socks5 and http, and transparent.

func LegacyLocal added in v0.35.0

func LegacyLocal(p2pSection bool, localType, targetType string, fallback bool) (typ, mode string)

LegacyLocal maps the old settings to a listener type and connection mode: p2p is direct with relay fallback (auto), or direct only when fallback_secret=false; secret is relayed. target_type tcp/udp/all chose the listeners of p2p and secret.

Types

type CommonConfig

type CommonConfig struct {
	Server           string
	VKey             string
	Tp               string //bridgeType kcp or tcp
	Pipes            string // connprofile.PipesSingle or PipesMulti
	SchedulerUp      string // connprofile.Schedulers, new protocol
	AutoReconnection bool
	ProxyUrl         string
	LocalIP          string
	DnsServer        string
	NtpServer        string
	NtpInterval      int
	Client           *model.Client
	DisconnectTime   int
	// Role is the set of roles of the connection, as connprofile.NormalizeRole
	// writes it (launch key role): empty means the roles follow from what
	// is written for the connection.
	Role string
	CoreSettings
}

func NewCommonConfig added in v0.35.0

func NewCommonConfig() *CommonConfig

NewCommonConfig returns a [common] section with no key set: the defaults of CommonDefaults and of the keys. dealCommon and the command line build their connection settings from it, so that both have the same defaults.

type Config

type Config struct {
	CommonConfig *CommonConfig
	Hosts        []*model.Host
	Tasks        []*model.Tunnel
	LocalServer  []*LocalServer
	// contains filtered or unexported fields
}

func NewConfig

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

NewConfig loads and parses an npc configuration file.

func Parse added in v0.35.0

func Parse(content string) (*Config, error)

Parse parses npc configuration text, as NewConfig does for a file.

func ParseUntrusted added in v0.35.0

func ParseUntrusted(raw string) (*Config, error)

ParseUntrusted parses configuration text from a source other than the local user. Nothing in it reaches the local machine: templates and the keys in localKeys are refused before any section is read, so parsing reads no file and opens no listener.

func (*Config) ConvertFileTunnels added in v0.35.0

func (c *Config) ConvertFileTunnels()

ConvertFileTunnels applies model.ConvertFileTunnel to the tunnels of c: a file tunnel with a listening port becomes a virtual backend and a tcp tunnel to it. It is idempotent.

func (*Config) UsesLegacyPointToPoint added in v0.35.0

func (c *Config) UsesLegacyPointToPoint() bool

UsesLegacyPointToPoint reports whether c held point-to-point access settings of an earlier version, which were converted. Launch payloads, never released with them, refuse such a config.

type CoreSettings added in v0.35.0

type CoreSettings struct {
	MaxLanes      int    // session_max_lanes: 0 is 16, 1 turns lanes off
	RelayIdle     int    // relay_idle, seconds: 0 is 60
	KeepServer    bool   // p2p_visitor_keep_server
	ResumeTimeout int    // session_resume_timeout, seconds: 0 is 30, negative no resume
	UsageInterval int    // session_usage_interval, seconds between reports of direct traffic: 0 is 60, negative never
	Pin           string // new_protocol_pin: hex key id the server must have, "" for none
}

CoreSettings are the [common] keys of the new protocol; the zero value of each is the protocol's own default.

type Defaults added in v0.35.0

type Defaults struct {
	Pipes       string
	SchedulerUp string
	CoreSettings
}

Defaults are the values a [common] section starts from. The command line sets them before any file is read, so that a flag is the default of every file and launch payload that does not set the key itself.

var CommonDefaults Defaults

CommonDefaults is set once at start-up, before configuration is parsed.

type LocalServer

type LocalServer struct {
	Type       string // LocalTCP, LocalUDP, LocalTCPUDP, LocalMixed, LocalTransparent
	ConnMode   string // ConnAuto, ConnRelay, ConnDirect
	Port       int
	Ip         string // listen address; empty for all
	Password   string
	Target     string // the destination the visitor names, within the tunnel's destination list; empty for the tunnel's default target
	LocalProxy bool
	Auth       map[string]string // proxy accounts of a mixed, socks5 or http listener, none for no authentication
}

LocalServer is a point-to-point access listener of a visitor npc: a [secret...] section, the -password command line or a launch payload. It reaches the secret tunnel of another client whose password it gives, directly (hole punching) or relayed by nps as ConnMode says.

Jump to

Keyboard shortcuts

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