connprofile

package
v0.35.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: GPL-3.0 Imports: 12 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

Overview

Package connprofile parses the server address of one npc connection, a profile: one or more carrier candidates separated by "|". A candidate is a URL whose scheme names the carrier, or, without a scheme, the address syntax of earlier versions, addr:port@host:port/path, whose carrier is the profile's connection type. Separate profiles (a comma in -server) are split by the caller, not here.

The URL form and its parameters are those of the carrier entries of the next major version (CARRIER with CARRIER_URL, CARRIER_SNI, CARRIER_KINDS, CARRIER_DIRS, TIER, WEIGHT, CARRIER_STANDBY, CARRIER_COUNT, CARRIER_ALPN, CARRIER_HTTP), so that a Candidate converts to one field by field. Only this version has the kcp, ws and wss schemes (ws and wss are http and https with kinds=websocket).

Index

Constants

View Source
const (
	PipesSingle = "single"
	PipesMulti  = "multi"
)

Pipe modes of a profile (-pipes, npc.conf pipes=).

View Source
const (
	SchedulerAffinity           = "affinity"
	SchedulerSessionAffinity    = "session_affinity"
	SchedulerSpreadETA          = "spread_eta"
	SchedulerSpreadRoundRobin   = "spread_round_robin"
	SchedulerSpreadRateWeighted = "spread_rate_weighted"
)

Sending schedulers of a session (§5 scheduler_up, scheduler_down), indexed by their value on the wire.

View Source
const (
	KindWebSocket = "websocket"
	KindStreaming = "streaming"
	KindSplit     = "split"
	KindExchange  = "exchange"
	KindHTTP3     = "http3"
)

HTTP carrier kinds of http and https candidates (zmux CarrierKind names).

View Source
const (
	HTTP11 = "http/1.1"
	HTTP2  = "h2"
	HTTP3  = "h3"
)

HTTP versions of http and https carriers.

View Source
const (
	SepLegacy = ","
	SepURL    = ";"
)

Separators of a server list: earlier versions separate connections with a comma; once any connection uses the URL form, connections are separated by a semicolon and commas belong to parameter lists.

View Source
const (
	RoleClient  = "client"
	RoleVisitor = "visitor"
)

Roles of a connection, the items of the role parameter.

View Source
const AdmitKeySize = 32

AdmitKeySize is the length of an admission key in bytes.

View Source
const DefaultQUICALPN = "h3"

DefaultQUICALPN is the ALPN of quic carriers (§13).

View Source
const LinkScheme = "npc://"

LinkScheme is the scheme of a launch link.

View Source
const MaxLinkSize = 8 << 10

MaxLinkSize is the longest launch link text.

Variables

Schedulers lists the schedulers by wire value.

Functions

func CheckList

func CheckList(server string, types []string) error

CheckList checks the connections of server: each must parse, and a URL list that looks like comma-separated connections gets a hint to use ";".

func EnsurePort

func EnsurePort(addr, carrier string) string

EnsurePort adds the default port of carrier to addr when it has none.

func FormatLink(vkey, server, carrier, name string, common map[string]string) (string, error)

FormatLink writes the launch link of a connection: its server and carrier as Parse takes them, common keys as in Link.Common. A vkey of "" is written as the mask ***, for display. It is the inverse of ParseLink.

func IsLink(s string) bool

IsLink reports whether s is written as a launch link.

func ListSep

func ListSep(server string) string

ListSep returns the separator of the connections in server, and so of the lists that go with it (vkey, type, local_ip).

func NormalizeRole added in v0.35.2

func NormalizeRole(s string) (string, error)

NormalizeRole checks a comma-separated set of roles and returns it in the canonical form: no repeats, client before visitor. Unknown values and empty items are errors.

func ParsePipes

func ParsePipes(s string) (string, error)

ParsePipes returns the pipe mode s names; "" is PipesSingle.

func ParseScheduler

func ParseScheduler(s string) (string, error)

ParseScheduler returns the scheduler s names; "" is affinity.

func SplitList

func SplitList(s, sep string) []string

SplitList splits a list of server, vkey, type or local_ip values by sep, accepting the full-width forms of "," and ";" and dropping empty items.

func UseCoreDefaults

func UseCoreDefaults(cands []Candidate)

UseCoreDefaults gives cands the defaults of the new protocol.

func UsesType

func UsesType(server string) bool

UsesType reports whether a server list has a candidate without a scheme, whose carrier comes from the connection type (-type, conn_type).

Types

type Candidate

type Candidate struct {
	// The fields of the carrier entry of the next major version.
	URL     string   // scheme://dial-address[/path], scheme tcp, tls, quic, http, https (kcp in this version only)
	Host    string   // Host header and default SNI, host:port
	SNI     string   // TLS server name, "" for none (an IP address)
	Kinds   []string // HTTP carrier kinds of http and https, in order of preference
	Dirs    Dirs
	Standby bool
	// Auto marks a candidate that a type=auto address expanded to: the
	// candidates of the profile are raced, not tried in turn (§3).
	Auto bool
	// ALPNDefaulted: no ALPN was written for this quic candidate.
	ALPNDefaulted bool
	Tier          int // lower is tried first
	Weight        int // share of a pipe in multi mode
	Count         int // pipes in multi mode, at least 1

	ALPN []string // TLS ALPN of tls and quic, in order of preference
	// Subprotocol is the WebSocket subprotocol of ws and wss, "" for none.
	Subprotocol string

	HTTP []string // HTTP versions of http and https: http/1.1, h2, h3, in order of preference

	// AdmitKey is the admission key of the exchange kind, as hex (§13); ""
	// leaves that kind out.
	AdmitKey string

	// How this version dials it.
	Carrier string // tcp, tls, kcp, quic, ws, wss, http, https (scheme-less: the profile type as given)
	Addr    string // host:port to dial
	Path    string // HTTP path, escaped

	Index int    // position in the profile, from 0
	Raw   string // the candidate as written

	// Attempt names one (HTTP version, kind) of an http or https candidate
	// (Attempts), "" for the candidate as written.
	Attempt string
}

Candidate is one way to reach the server of a profile.

func Attempts

func Attempts(cands []Candidate) []Candidate

Attempts returns the attempts of every candidate, in order.

func MultiMembers

func MultiMembers(cands []Candidate) []Candidate

MultiMembers returns the candidates that carry pipes in multi mode, in the order the pools are built: the non-standby ones with a tier at most the best non-standby tier + 1, as written, then every standby one. Standby pipes are built but carry traffic only while no other pipe is alive.

func Order

func Order(cands []Candidate, last string) []Candidate

Order returns the candidates in the order to try them: the one with key last (the last that connected) first, then the others by tier ascending, then as written, standby candidates after all others.

func Parse

func Parse(s, carrier string) ([]Candidate, error)

Parse returns the candidates of the profile s; carrier is the connection type of scheme-less candidates. Empty candidates are skipped. A "|" or "?" inside a path or parameter is written %7C or %3F.

func (Candidate) Attempts

func (c Candidate) Attempts() []Candidate

Attempts returns the ways to dial c: one per (HTTP version, kind) it can carry, the versions in the order of its http list and the kinds in the order of its kinds within each. Each is c with one version and one kind; a websocket attempt is dialed as ws or wss. Any other candidate is its own only attempt.

func (Candidate) HTTPCarrier

func (c Candidate) HTTPCarrier() bool

HTTPCarrier reports whether c is an http or https candidate, which chooses among carrier kinds.

func (Candidate) Key

func (c Candidate) Key() string

Key identifies the candidate, or one of its attempts, within its profile.

func (Candidate) OnlyHTTP3

func (c Candidate) OnlyHTTP3() bool

OnlyHTTP3 reports whether h3 is all the http list of c names (§2.4b): only then is h3 dialed without being known to work.

func (Candidate) Starts

func (c Candidate) Starts() bool

Starts reports whether a session can start on c (it carries both directions).

type Dirs

type Dirs uint8

Dirs is the set of directions a candidate carries (CARRIER_DIRS).

const (
	DirBidi Dirs = 1 // both directions; only these can start a session
	DirUp   Dirs = 2 // npc to server only
	DirDown Dirs = 4 // server to npc only
)
type Link struct {
	VKey   string
	Server string // candidates joined by "|", for Parse
	// Name is the #label, else the name parameter: the profile name.
	Name string
	// Common holds the other [common] keys of the link: pipes, proxy_url,
	// local_ip (written source_addr=), role (canonical), new_protocol_pin and the core settings.
	Common map[string]string
}

Link is a launch link, npc://vkey@host:port[/path]?type=tls&...#label, read as the settings of one connection profile. A link describes the connection only; what is reached over it is written with -L. Its keys are those of npc.conf, and the server is in the candidate form of Parse.

func ParseLink(raw string) (Link, error)

ParseLink reads a launch link. Errors never contain the link: it holds the vkey. A parameter this version does not know is ignored with a warning, so a link written for a newer version still connects.

Jump to

Keyboard shortcuts

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