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
- Variables
- func CheckList(server string, types []string) error
- func EnsurePort(addr, carrier string) string
- func FormatLink(vkey, server, carrier, name string, common map[string]string) (string, error)
- func Groups(cands []Candidate) [][]Candidate
- func IsLink(s string) bool
- func ListSep(server string) string
- func MultiGroups(cands []Candidate) [][]Candidate
- func NormalizeRole(s string) (string, error)
- func ParsePipes(s string) (string, error)
- func ParseScheduler(s string) (string, error)
- func PipeCount(groups [][]Candidate) int
- func SplitList(s, sep string) []string
- func UseCoreDefaults(cands []Candidate)
- func UsesType(server string) bool
- type Candidate
- type Dirs
- type Link
Constants ¶
const ( PipesSingle = "single" PipesMulti = "multi" )
Pipe modes of a profile (-pipes, npc.conf pipes=).
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.
const ( KindWebSocket = "websocket" KindStreaming = "streaming" KindSplit = "split" KindExchange = "exchange" KindHTTP3 = "http3" )
HTTP carrier kinds of http and https candidates (zmux CarrierKind names).
const ( HTTP11 = "http/1.1" HTTP2 = "h2" HTTP3 = "h3" )
HTTP versions of http and https carriers.
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.
const ( RoleClient = "client" RoleVisitor = "visitor" )
Roles of a connection, the items of the role parameter.
const AdmitKeySize = 32
AdmitKeySize is the length of an admission key in bytes.
const DefaultQUICALPN = "h3"
DefaultQUICALPN is the ALPN of quic carriers (§13).
const LinkScheme = "npc://"
LinkScheme is the scheme of a launch link.
const MaxLinkSize = 8 << 10
MaxLinkSize is the longest launch link text.
Variables ¶
var Schedulers = []string{SchedulerAffinity, SchedulerSessionAffinity, SchedulerSpreadETA, SchedulerSpreadRoundRobin, SchedulerSpreadRateWeighted}
Schedulers lists the schedulers by wire value.
Functions ¶
func CheckList ¶
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 ¶
EnsurePort adds the default port of carrier to addr when it has none.
func FormatLink ¶
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 Groups ¶ added in v0.35.7
Groups splits cands into their groups (Candidate.Group), in the order each group first appears, the candidates of a group in their order.
func ListSep ¶
ListSep returns the separator of the connections in server, and so of the lists that go with it (vkey, type, local_ip).
func MultiGroups ¶ added in v0.35.7
MultiGroups returns the groups that carry pipes in multi mode (MultiMembers), in the order the pools are built. The candidates of one group share its parameters, so a group is in or out as a whole.
func NormalizeRole ¶ added in v0.35.2
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 ¶
ParsePipes returns the pipe mode s names; "" is PipesSingle.
func ParseScheduler ¶
ParseScheduler returns the scheduler s names; "" is affinity.
func PipeCount ¶ added in v0.35.7
PipeCount is how many pipes groups ask for together: Count per group, whichever of its candidates carries them.
func SplitList ¶
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.
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
// Group is the position of the address as written in the profile, from
// 0: the candidates a type=auto address expanded to share it, any other
// candidate has one of its own. A group is the unit of a pipe pool: its
// pipes run over one of its candidates at a time, Count of them.
Group int
}
Candidate is one way to reach the server of a profile.
func MultiMembers ¶
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 ¶
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 ¶
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 ¶
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 ¶
HTTPCarrier reports whether c is an http or https candidate, which chooses among carrier kinds.
type Dirs ¶
type Dirs uint8
Dirs is the direction a candidate's pipes prefer (CARRIER_DIRS). A pipe carries both directions whatever it prefers: the other one stands by on it, for when no pipe preferring that one is left. A session starts on any candidate.
type Link ¶
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.