Documentation
¶
Index ¶
- Variables
- func Bool(key string) (bool, error)
- func CheckSettings(appliers []Applier) error
- func DefaultPaths() []string
- func DefaultString(key, defaultValue string) string
- func Int(key string) (int, error)
- func Int64(key string) (int64, error)
- func IsSupportedConfigPath(path string) bool
- func Keys() []string
- func Load(path string) error
- func LoadCandidates(paths ...string) error
- func LoadDefault() error
- func Path() string
- func RestartRequired(_, _ *Snapshot) error
- func SetPreferredPath(path string)
- func String(key string) string
- func SupportedExtensions() []string
- func Unowned(appliers []Applier) []string
- type AppConfig
- type Applier
- type AuthConfig
- type BridgeConfig
- type BridgeDisplayConfig
- type BridgeDisplayEndpoint
- type Failure
- type FeatureConfig
- type LogConfig
- type NetworkConfig
- type P2PConfig
- type ProxyConfig
- type Report
- type RuntimeConfig
- type SSLConfig
- type SecurityConfig
- type Snapshot
- type WebConfig
- type WebhookConfig
Constants ¶
This section is empty.
Variables ¶
var ErrRestartRequired = errors.New("restart required")
ErrRestartRequired is what Apply of an Applier returns for settings that are only read at startup: a reload keeps them as they were.
Functions ¶
func CheckSettings ¶ added in v0.35.0
CheckSettings returns an error for a key of the appliers that nps does not know or that two of them own.
func DefaultPaths ¶
func DefaultPaths() []string
DefaultPaths returns the candidate nps server config paths in load order.
func DefaultString ¶
func IsSupportedConfigPath ¶
IsSupportedConfigPath reports whether the file extension maps to a parser.
func Keys ¶ added in v0.35.0
func Keys() []string
Keys returns the config keys nps knows, sorted: those the snapshot is built from, the alternatives of a key included.
func LoadCandidates ¶
LoadCandidates loads the first readable config file from the provided paths.
func LoadDefault ¶
func LoadDefault() error
LoadDefault loads the server config from the default candidate paths.
func RestartRequired ¶ added in v0.35.0
RestartRequired is the Apply of the settings only read at startup.
func SetPreferredPath ¶
func SetPreferredPath(path string)
SetPreferredPath configures an explicit config file path to try before defaults.
func SupportedExtensions ¶
func SupportedExtensions() []string
SupportedExtensions returns all supported config file extensions.
Types ¶
type AppConfig ¶
type AppConfig struct {
Name string
Timezone string
DNSServer string
PprofIP string
PprofPort string
NTPServer string
NTPInterval int
// GeoIPPath and GeoSitePath are the geodata files of the access lists,
// relative to the run path unless absolute.
GeoIPPath string
GeoSitePath string
// AclMaxRules limits the rules of each access list users may write;
// 0 means no limit.
AclMaxRules int
// IPRegisterMaxHours bounds registrations made on the registration page
// with the public key, and with the key of a client that sets no limit.
IPRegisterMaxHours int
// IPRegisterIP and IPRegisterPort, when the port is set, serve the
// registration page on a listener of its own.
IPRegisterIP string
IPRegisterPort int
// IPRegisterCertFile and IPRegisterKeyFile, when both are set, serve
// the listener of the registration page over TLS.
IPRegisterCertFile string
IPRegisterKeyFile string
}
type Applier ¶ added in v0.35.0
type Applier struct {
// Name names the Applier in reports.
Name string
// Settings are the config keys the Applier owns, such as "log_level".
// A key changes when what it gives differs, also when it is not set
// and the key it defaults to changed.
Settings []string
// Apply makes the changes of the settings take effect once cur is the
// current snapshot; it is called only when one of them changed between
// old and cur. Nil means the settings are read where they are used, so
// that they take effect with the snapshot. RestartRequired reports
// settings that take effect at the next start.
Apply func(old, cur *Snapshot) error
}
An Applier owns some config keys and says how a reload makes their changes take effect. Every key nps knows (Keys) is owned by exactly one Applier (CheckSettings, Unowned), so that the Appliers are the one record of what a reload applies.
type AuthConfig ¶
type BridgeConfig ¶
type BridgeConfig struct {
Addr string
Type string
PrimaryType string
SelectMode string
CertFile string
KeyFile string
TCPEnable bool
KCPEnable bool
QUICEnable bool
TLSEnable bool
WSEnable bool
WSSEnable bool
ServerTCPEnabled bool
ServerKCPEnabled bool
ServerQUICEnabled bool
ServerTLSEnabled bool
ServerWSEnabled bool
ServerWSSEnabled bool
Display BridgeDisplayConfig
}
type BridgeDisplayConfig ¶
type BridgeDisplayConfig struct {
Path string
TCP BridgeDisplayEndpoint
KCP BridgeDisplayEndpoint
QUIC BridgeDisplayEndpoint
TLS BridgeDisplayEndpoint
WS BridgeDisplayEndpoint
WSS BridgeDisplayEndpoint
}
type BridgeDisplayEndpoint ¶
type Failure ¶ added in v0.35.0
type Failure struct {
Name string `json:"name"`
Settings []string `json:"settings"`
Error string `json:"error"`
}
Failure is an Applier that failed in a reload.
type FeatureConfig ¶
type FeatureConfig struct {
AllowUserLogin bool
AllowUserRegister bool
AllowUserVkeyLogin bool
AllowUserChangeUsername bool
OpenCaptcha bool
AllowFlowLimit bool
// FlowLimitActual makes flow limits count the actual usage, twice the
// inbound and outbound traffic, rather than the traffic itself.
FlowLimitActual bool
AllowRateLimit bool
AllowTimeLimit bool
AllowConnectionNumLimit bool
AllowMultiIP bool
AllowTunnelNumLimit bool
AllowLocalProxy bool
AllowUserLocal bool
SystemInfoDisplay bool
AllowPorts string
}
type LogConfig ¶
type LogConfig struct {
Type string // stdout, file, both, off
Format string // auto (pretty on a terminal, else logfmt), text or json
Level string // "info,bridge=debug"
Path string
Security string // security log file; empty for none
MaxFiles int
MaxDays int
MaxSize int // MB
Memory int // entries kept for the log viewer of the web manager; 0 for none
Compress bool
Secrets bool // write keys and passwords in lines, for development
Instance string // instance= on every line, to tell instances apart where logs meet
Access string // access log file of the domain proxy; empty for none
AccessFormat string // combined or json
}
type NetworkConfig ¶
type NetworkConfig struct {
BridgeIP string
BridgeHost string
BridgeTCPIP string
BridgeKCPIP string
BridgeQUICIP string
BridgeTLSIP string
BridgeWSIP string
BridgeWSSIP string
BridgePort int
BridgeTCPPort int
BridgeKCPPort int
BridgeQUICPort int
BridgeTLSPort int
BridgeWSPort int
BridgeWSSPort int
BridgePath string
BridgeTrustedIPs string
BridgeRealIPHeader string
// NewProtocolTLSALPN is the ALPN list of the TLS bridge with NewProtocol
// (nps.conf new_protocol_tls_alpn, comma-separated); empty selects none.
NewProtocolTLSALPN []string
// NewProtocolQUICALPN is the ALPN list of the core protocol's QUIC
// carrier (nps.conf new_protocol_quic_alpn, default h3). It must not
// share a name with QUICALPNList, whose names are the old protocol's
// (§12), nor contain h3 where HTTP/3 uses the port (MixHTTP3).
NewProtocolQUICALPN []string
// NewProtocolWSPaths are the WebSocket paths whose requests go to the
// core protocol whatever their subprotocol (nps.conf
// new_protocol_ws_paths, comma-separated, default none). On BridgePath
// the subprotocol decides: binary is the core protocol, none the old one.
NewProtocolWSPaths []string
// MixPort is the mixed port (nps.conf mix_port, 0 off; TCP and UDP on
// the same number), MixIP its address (mix_ip, default bridge_ip).
// MixPlain lets it take plaintext carriers (mix_plain, default off);
// MixLegacy the old protocol where the first bytes tell it (mix_legacy,
// default on), which also applies to bridge://mix.
MixIP string
MixPort int
MixPlain bool
MixLegacy bool
// BridgeGeneric: the config names only the generic bridge_port, which
// is then a full mixed port (see legacy.go).
BridgeGeneric bool
// BridgeKCPQUIC: the KCP port also takes QUIC (conn.UDPSplit), which is
// how npc reaches a port configured for kcp. It goes with old KCP.
BridgeKCPQUIC bool
// ClientMaxPipes limits the pipes of one client over all its sessions
// (client_max_pipes, 0 unlimited).
ClientMaxPipes int
// CompressMaxWindow and CompressMaxRatio are the receive limits of
// compressed links on the core protocol (nps.conf compress_max_window
// in bytes, compress_max_ratio; 0 is the default, a negative ratio
// disables that check).
CompressMaxWindow uint64
// Shaping source: shaping_url, shaping_token, shaping_pubkey and the
// local shaping_file. None is the default.
ShapingURL, ShapingToken, ShapingPubKey, ShapingFile string
CompressMaxRatio int64
HTTPProxyIP string
HTTPProxyPort int
HTTPSProxyPort int
// HTTPProxyAccessPort and HTTPSProxyAccessPort are the ports visitors
// reach the host proxy on from outside, behind a reverse proxy or port
// mapping; they default to the listen ports and only build links.
HTTPProxyAccessPort int
HTTPSProxyAccessPort int
HTTP3ProxyPort int
WebIP string
WebPort int
P2PIP string
P2PPort int
QUICALPN string
QUICALPNList []string
QUICKeepAlivePeriod int
QUICMaxIdleTimeout int
QUICMaxIncomingStreams int64
MuxPingInterval int
}
func (NetworkConfig) CheckQUICALPN ¶ added in v0.35.0
func (n NetworkConfig) CheckQUICALPN(http3 bool) error
CheckQUICALPN reports a QUIC ALPN configuration that cannot tell the protocols apart: a name in both quic_alpn (old protocol) and new_protocol_quic_alpn, or h3 in either where HTTP/3 uses the same UDP port. ALPN alone decides (§13).
func (NetworkConfig) MixHTTP3 ¶ added in v0.35.0
func (n NetworkConfig) MixHTTP3() bool
MixHTTP3 reports whether the UDP side of the mixed port serves HTTP/3 too: the HTTP/3 port of the domain proxy is the mixed port. Then ALPN h3 is HTTP/3's and the QUIC carrier uses the quic_alpn names (§13).
type ProxyConfig ¶
type ProxyConfig struct {
AddOriginHeader bool
ResponseTimeout int
ErrorPage string
ErrorPageTimeLimit string
ErrorPageFlowLimit string
ErrorAlways bool
// Fallback404File is the body of the 404 that bridge connections of no
// known route get (nps.conf fallback_404_file); empty selects a minimal
// built-in body.
Fallback404File string
BridgeHTTP3 bool
ForceAutoSSL bool
SSL SSLConfig
}
type Report ¶ added in v0.35.0
type Report struct {
Path string `json:"path"`
Error string `json:"error,omitempty"`
Applied []string `json:"applied"`
Restart []string `json:"restart"`
Failed []Failure `json:"failed"`
RollbackFailed []Failure `json:"rollback_failed,omitempty"`
}
Report is the outcome of a reload. When Error is set, the file could not be read and nothing changed. When Failed is not empty, the reload was undone: the previous snapshot is current again and the Appliers that had applied it were applied back, RollbackFailed lists those that could not.
func Reload ¶
Reload reads the loaded config file again, or the default candidates when none is loaded, and hands the changes to the appliers. A file that cannot be read changes nothing. Otherwise the new snapshot becomes current and the appliers whose settings changed are applied in order. When one fails, the previous snapshot becomes current again and those applied before are applied back in reverse order, so that a reload takes effect as a whole or not at all. Reloads run one at a time.
type RuntimeConfig ¶
type RuntimeConfig struct {
ClientHistoryLimit int
PublicVKey string
VisitorVKey string
DisconnectTimeout int
// DeadS and IdleS are dead_s and idle_s of the new protocol's sessions
// (§5, 0: not set): idle from session_idle_s, dead only from a
// disconnect_timeout the config names.
DeadS, IdleS int
// SessionResumeTimeout is how long a new protocol session that lost its
// pipes waits for one, in seconds (session_resume_timeout, 0: 30,
// negative: no resume).
SessionResumeTimeout int
// SessionMaxLanes is the lanes accepted per QUIC pipe of a new protocol
// session (session_max_lanes, 0: 16, 1: no lanes).
SessionMaxLanes int
// SessionMaxServices bounds the virtual services one session may report
// (session_max_services, 0: 4096, negative: no limit).
SessionMaxServices int
FlowStoreInterval int
}
type SecurityConfig ¶
type Snapshot ¶
type Snapshot struct {
App AppConfig
Log LogConfig
Web WebConfig
Auth AuthConfig
Feature FeatureConfig
Security SecurityConfig
Runtime RuntimeConfig
Webhook WebhookConfig
Network NetworkConfig
Bridge BridgeConfig
Proxy ProxyConfig
P2P P2PConfig
// Legacy holds a warning for each key of an earlier version the config
// sets (legacyKeys).
Legacy []string
// contains filtered or unexported fields
}
type WebConfig ¶
type WebConfig struct {
InstanceKeyFile string
// AdmitKey overrides the admission key of the exchange carrier, 64 hex
// digits; "" derives it from the instance key.
AdmitKey string
BaseURL string
HeadCustomCode string
Host string
IP string
Port int
OpenSSL bool
CloseOnNotFound bool
// RequirePassword blocks the admin login until web_username and a
// password or TOTP secret are set.
RequirePassword bool
// TunnelPortRangeMax limits the ports one tunnel added from the web may
// expand to; 0 means no limit.
TunnelPortRangeMax int
KeyFile string
CertFile string
Username string
Password string
TOTPSecret string
}