Documentation
¶
Index ¶
- Constants
- func TCPPortOwners(specs []InboundSpec) map[uint16]TCPOwner
- func TCPSharePlan(specs []InboundSpec) map[uint16]TCPPortShare
- func TrustTunnelH3(spec InboundSpec) bool
- func ValidWarpReachDomain(s string) bool
- type BridgeDial
- type BridgeServe
- type BridgeTarget
- type ClientFormat
- type ClientID
- type ClientSupport
- type EngineHealth
- type Fragment
- type InboundSpec
- type LinkStat
- type Listen
- type RelayForward
- type RunState
- type Session
- type TCPOwner
- type TCPPortShare
- type TCPRoute
- type TCPShadow
- type TLS
- type TLSMode
- type Tunnel
- type TunnelRefusal
- type TunnelRefusals
- type UserCred
- type UserTraffic
- type WarpSpec
Constants ¶
const ( BridgeHTTP2Streams = 250 BridgePendingPairs = 4 BridgePeoplePerConn = (BridgeHTTP2Streams - 2*BridgePendingPairs) / 2 )
BridgeHTTP2Streams is MAX_CONCURRENT_STREAMS of the bridge's site (the Go server's 250; it is part of the site's look, so it is not raised), BridgePendingPairs the waiting pairs an exit keeps open on each connection (2 streams each), and BridgePeoplePerConn what is left for people, 2 streams a person: the most people one TLS connection of the bridge carries. A burst may take more waiting pairs for a moment; the figure is the steady one.
const ( NoteXHTTP = "xhttp" // not rendered: the format has no XHTTP transport NoteSelfSigned = "self_signed" // not rendered: the format cannot pin a self-signed certificate NoteGecko = "gecko" // not rendered: the format has no Gecko obfuscation NoteAWG = "awg" // not rendered: the format cannot carry AmneziaWG NoteHopSinglePort = "hop_single_port" // rendered: the port-hopping range is written as its one listening port )
Fragment.Note codes. They are part of the admin API (ProfileFormat.note in profile.proto).
const CapRelayForward = "relay-forward/1"
CapRelayForward is the Hello capability of an agent that can forward ports (DesiredState.relays, ApplyResult.relays). The panel sends relays only to a stream that listed it.
const CapRelayReverse = "relay-reverse/1"
CapRelayReverse is the Hello capability of an agent that can run the bridge of a reverse relay (RelayForward.mode, DesiredState.bridge_serve and bridge_dials, ApplyResult.bridges, StatsBatch.bridges; agent.proto "REVERSE RELAY"). The panel sends those fields only to a stream that listed it; a pair of agents needs it at both ends for a reverse relay.
const MaxWarpReachDomains = 8
MaxWarpReachDomains is the most sites one WARP reach run takes (agent.proto "WARP REACH").
Variables ¶
This section is empty.
Functions ¶
func TCPPortOwners ¶
func TCPPortOwners(specs []InboundSpec) map[uint16]TCPOwner
TCPPortOwners is the plan of the TCP ports of a node from its enabled inbounds: who holds each port, as the agent settles it. The lowest id of the TCP inbounds on a port holds it. A Hysteria2 site (settings.masquerade.tcp_port, 443 when omitted) holds a port only when no TCP inbound does: it gives the port up to any of them (the agent's TCPClaims). The panel and the agent must say the same here, so everything that asks "what answers on TCP 443" asks this.
func TCPSharePlan ¶
func TCPSharePlan(specs []InboundSpec) map[uint16]TCPPortShare
TCPSharePlan decides which TCP ports of a node several services share by SNI (the agent's front, internal/node/front). It takes the inbounds that are to run (a caller that checks a layout before it is enabled passes the disabled ones too) and returns the ports where two of them or more listen. A port where one inbound cannot take part (another protocol than VLESS, TrustTunnel and MTProto, or no name to be told apart by) is not in the result: it keeps the old rule. A Hysteria2 site is no route: it gives its port up to any TCP inbound (TCPPortOwners).
func TrustTunnelH3 ¶
func TrustTunnelH3(spec InboundSpec) bool
TrustTunnelH3 reports whether a TrustTunnel inbound's settings ({"h3":bool}) turn HTTP/3 on.
func ValidWarpReachDomain ¶
ValidWarpReachDomain says whether s can be a site of the WARP reach list: a lower-case host name with at least two labels (no address, port or path), at most 253 characters. The panel checks the owner's list with it and the node checks again.
Types ¶
type BridgeDial ¶
type BridgeDial struct {
EntryNodeID string
Host string // an IP literal or a name
Port uint16
SNI string // optional server name sent as SNI; one of SNI or PinSHA256 is required
PinSHA256 string // lowercase hex SHA-256 of the leaf certificate's DER
Path string
Pool uint32 // TLS connections to keep; 0 = the agent's default
Targets []BridgeTarget
PanelVia bool
}
BridgeDial is one entry an exit calls (agent.v1.BridgeDial).
type BridgeServe ¶
type BridgeServe struct {
Port uint16 // the TCP port of the entry's site; 0 = 443 of the node's own site
Path string
ExitNodeIDs []string
PanelVia bool
}
BridgeServe is the entry side of the bridge (agent.v1.BridgeServe): where the exits call and which of them are accepted.
func (BridgeServe) IsZero ¶
func (b BridgeServe) IsZero() bool
IsZero: nothing is served (an empty BridgeServe on the wire stops the bridge; it hashes like an absent one).
type BridgeTarget ¶
BridgeTarget is where the exit passes the connections of one relay: its own server, by network and port (agent.v1.BridgeTarget).
type ClientFormat ¶
type ClientFormat string
ClientFormat is a subscription wire format.
const ( FormatURIList ClientFormat = "uri-list" // base64(lines of scheme:// URIs); hysteria2:// and vless:// so far. FormatXrayJSON ClientFormat = "xray-json" // one Xray outbound as a JSON object, see Fragment FormatSingbox ClientFormat = "singbox" // one sing-box outbound as a JSON object, see Fragment FormatMihomo ClientFormat = "mihomo-yaml" FormatMistgate ClientFormat = "mistgate" // the first-party client API's structured protocol settings FormatAmneziaVPN ClientFormat = "amnezia-vpn" // vpn:// FormatAWGConf ClientFormat = "awg-conf" // FormatTelegramLink is one tg://proxy link. It is no subscription format: no subscription carries it, the person's // own list of Telegram links does (access.SubView.Telegram). FormatTelegramLink ClientFormat = "tg-link" // FormatTTLink is one official-app tt:// key. It is not a subscription format; a person receives it in their key block. FormatTTLink ClientFormat = "tt-link" )
type ClientID ¶
type ClientID string
ClientID names a client application, independent of its config format.
const ( ClientHapp ClientID = "happ" // user toggle "Happ" ClientAmnezia ClientID = "amnezia" // user toggle "Amnezia" ClientTelegram ClientID = "telegram" // user toggle "Telegram": MTProto proxy links ClientTrustTunnel ClientID = "trusttunnel" // user toggle "TrustTunnel": official-app tt:// links ClientMistgate ClientID = "mistgate" // the first-party app, enrolled by its client API key ClientMihomo ClientID = "mihomo" ClientSingbox ClientID = "singbox" // the official sing-box apps (SFA, SFI, SFM); no user toggle of their own )
type ClientSupport ¶
type ClientSupport struct {
Client ClientID
Formats []ClientFormat
MinVersion string // "" = any; shown as a warning when the client is older
}
ClientSupport says which client can consume a protocol, in which formats.
type EngineHealth ¶
type EngineHealth struct {
InboundID string
State RunState
Detail string // machine-readable reason when not running
Restarts uint32
Since time.Time
// The certificate the inbound serves right now (zero for a protocol without TLS, and for an ACME certificate that is
// not issued yet). Unlike the apply-time report it follows issuance and renewal.
CertPinSHA256 string
CertNotAfter time.Time
}
EngineHealth is per inbound.
type Fragment ¶
type Fragment struct {
Format ClientFormat
Name string // display name, e.g. "de1 · hy2 · 443"
Data []byte
Note string
}
Fragment is a piece of a subscription in one format. For FormatURIList, Data is exactly one URI (no newline, no base64; the subscription assembler joins and encodes). For FormatXrayJSON and FormatSingbox, Data is ONE outbound as a JSON object without a "tag", built with encoding/json (never from a string template: node and user names are hostile input, and the plugin puts no name into the object at all); the assembler sets the tag and adds the rest of the config (inbounds, dns, routing). A server the format cannot carry is not rendered (ok == false).
Note says why, in a stable code that the admin UI turns into text. With ok == false the fragment is otherwise empty and Note is the reason the format leaves this server out (NoteXHTTP, NoteSelfSigned, NoteGecko, NoteAWG; empty for a cause that has no code of its own, such as an address the format cannot carry). With ok == true it names a degraded rendering (NoteHopSinglePort); empty means carried in full. The assembler ignores it: it exists so that "which formats carry this profile" is answered by the same Render call as the subscription, not by a second rule.
type InboundSpec ¶
type InboundSpec struct {
ID string
Protocol string
ProfileID string
Version uint64 // agent.v1 spec_version
Enabled bool
Listen Listen
TLS TLS
Egress string // "direct" | "warp"
Settings json.RawMessage
// Tunnel is the L3 interface of a tunnel protocol (awg). The zero value means "none" (hysteria2); the
// state hash includes it only when it is set, so the hashes of protocols without it never change.
Tunnel Tunnel
}
InboundSpec mirrors agent.v1.InboundSpec. Settings is opaque, protocol-specific and already validated by the plugin on the panel; the engine validates again (never trust the wire).
type LinkStat ¶ added in v0.1.53
type LinkStat struct {
CredID, InboundID string
Connects, Rejects, Drops, Stalls, UnknownKeys uint32
Hellos, Handshakes uint32
ClientCloses, Freezes, Quiet uint32
Accepted, HellosForeign uint32
RTTMSSum uint64
RTTSamples uint32
PktsSent, PktsLost uint64
// links/3. Volume: the handshake failures of the inbound row and the AmneziaWG handshake counts of a key. Event: the
// TCP stalls of a VLESS key (or of the inbound, behind the TLS front).
HsUnfinished, TLSAlertsSent, TLSAlertsRecv, TLSCertRefused uint32
RealityFallback, AuthFailed uint32
TCPStalls, TCPStalls16K uint32
Initiations, Responses, ResponsesUnmatched uint32
// vless-hello-kex/1. Event, on a VLESS REALITY key: the ClientHellos of its connections by key exchange.
HelloPQ, HelloClassic, HelloUnknown uint32
// trusttunnel-refusals/1. Event, on the inbound row: the tunnel requests the engine refused after the credential had
// passed, by reason. No credential, person or destination is attached.
Refusals TunnelRefusals
}
LinkStat is a connection-counter delta. Event counters are reported in the next stats batch; hello, handshake, connection-quality, and packet-volume counters are accumulated by the agent until its next UTC ten-minute boundary. agent.proto LinkCounters says which is which and which engine counts what.
type Listen ¶
type Listen struct {
Network string // "udp" | "tcp"
Port uint16
HopFrom, HopTo uint16 // 0/0 = no port hopping
}
Listen is what the HOST layer needs. The engine binds Port only; the agent installs the hop DNAT.
func SideListens ¶
func SideListens(spec InboundSpec) []Listen
SideListens returns listeners a protocol adds beside its primary listener. TrustTunnel's optional HTTP/3 endpoint uses UDP on the same port as its required TCP HTTP/2 endpoint.
type RelayForward ¶ added in v0.1.65
type RelayForward struct {
ID string
Network string // "tcp" | "udp"
Port uint16
ToHost string
ToPort uint16
// Mode is "" (and "dnat": the same plain forward) or "reverse"; ExitNodeID names the exit whose bridge carries a reverse forward.
// Both are empty for an agent without CapRelayReverse (the omitempty keeps the JSON the panel digests of a plain forward as it was).
Mode string `json:"Mode,omitempty"`
ExitNodeID string `json:"ExitNodeID,omitempty"`
}
RelayForward is one forwarded port of the node (agent.v1.RelayForward): connections to Port go, unchanged, to ToHost:ToPort. ToHost is an IPv4 literal or a name the agent resolves.
type Session ¶
Session is one open client connection (QUIC connection for Hysteria2, recent handshake for AWG).
type TCPOwner ¶
type TCPOwner struct {
ID string // the inbound that holds the port
Protocol string
// Site: a stranger gets the node's own HTTPS site (VLESS TLS and REALITY "self", TrustTunnel, the decoy of MTProto, a
// Hysteria2 site). REALITY with another site and the site fallback of MTProto show someone else's.
Site bool
}
TCPOwner is what holds one TCP port of a node and what a visitor of the port meets there.
type TCPPortShare ¶
type TCPPortShare struct {
// Routes are the services that hold their names, by id. Default is the id of the first of them that serves the node's own
// site: it gets what no route claims (no name, an unknown name, not TLS, a broken hello); "" when none does.
Shadowed map[string]TCPShadow
}
TCPPortShare is one TCP port with two services or more, each of which can be told apart by name.
func (TCPPortShare) Front ¶
func (p TCPPortShare) Front() bool
Front says the port is shared: two routes or more and a default one. Otherwise the port keeps its old rule: the lowest id listens, the others fail to bind (Shadowed ones are reported the same way, by name).
type TCPRoute ¶
type TCPRoute struct {
ID string
Protocol string
// Names are the exact SNI names the service gets: lower case, no trailing dot, ASCII, never an IP address, and none that
// a service with a lower id holds.
Names []string
Site bool // a stranger gets the node's own site from it (TCPOwner.Site)
// Reality: Xray runs REALITY on its connections (a TCP keepalive is not set on them, as when Xray listens alone).
Reality bool
}
TCPRoute is one service on a TCP port that services share by the SNI of the first ClientHello.
type TCPShadow ¶
type TCPShadow struct{ Name, By string }
TCPShadow says whose name an inbound asked for and did not get.
type Tunnel ¶
type Tunnel struct {
AddrV4, AddrV6 netip.Prefix // AddrV6 invalid = no IPv6 in the tunnel
MTU uint16
}
Tunnel is what the HOST layer needs for an L3 protocol: the address of the node's interface inside the client subnet (the .1 of it) and the MTU. The host derives the client subnets (masquerade source, "ip rule from") from the prefixes. Mirrors agent.v1.Tunnel.
type TunnelRefusal ¶
type TunnelRefusal uint8
TunnelRefusal is why a TrustTunnel engine refused a tunnel request (CONNECT host:port or _udp2) of a credential that had authenticated. The list is closed: agent.proto LinkCounters (capability "trusttunnel-refusals/1") has one counter for each.
const ( RefusedBlocked TunnelRefusal = iota // the egress forbids the address (X-Warning 310) RefusedNoIPv4 // the destination has no IPv4 address and IPv6 is off for clients (301) RefusedConnRefused // the connection was refused (301) RefusedConnUnreachable // no route to the network or the host (301) RefusedConnDNS // the name did not resolve (301) RefusedConnOther // any other connection error (301) RefusedTimeout // the connect timeout (302) RefusedOtherDeadlines // the site's deadlines could not be lifted (300) RefusedOtherAuthority // the request's authority could not be read (300) RefusedOtherICMP // an ICMP tunnel, which the engine does not carry (300) RefusedOtherDial // the egress failed in a way none of the above names (300) RefusedStreamClosed // the connection was closing (the client left, or the connection expired) RefusedStreamCredGone // the credential was removed, kicked or expired RefusedStreamLimit // the credential already holds the most connections it may TunnelRefusalKinds = iota )
func (TunnelRefusal) Name ¶
func (r TunnelRefusal) Name() string
Name is the reason as the journal and the counters' documentation call it.
type TunnelRefusals ¶
type TunnelRefusals [TunnelRefusalKinds]uint32
TunnelRefusals counts refusals by reason, indexed by TunnelRefusal.
type UserCred ¶
type UserCred struct {
CredID string
UserID string
DeviceID string
Data json.RawMessage // verifier, never the raw end-user secret
RateLimitBps uint64 // the device limit: this credential never goes faster; 0 = unlimited
// UserRateLimitBps is the person limit: one bucket shared by every credential of UserID on the node; 0 = none. An
// agent that does not list "user-rate-limit/1" never gets it (the panel folds it into RateLimitBps).
UserRateLimitBps uint64
ValidUntil time.Time // zero = no expiry; the agent drops the credential itself at this time
}
UserCred is one device x protocol credential as a node sees it (agent.v1.Credential).
type UserTraffic ¶
UserTraffic is a counter delta. Up = client -> internet, Down = internet -> client (the END USER's view; Hysteria core's "tx"/"rx" are server-remote and therefore swapped: core tx = Up, core rx = Down).
type WarpSpec ¶
type WarpSpec struct {
Enabled bool
PrivateKey string // base64; a secret, never logged
PeerPublicKey string
EndpointV4 string // IP literal, no port
EndpointV6 string // "" = never use
Ports []uint16
AddressV4 string // "172.16.0.2/32"
AddressV6 string // "" = none
MTU uint16
Reserved []byte // 0 or 3 bytes
Backend string // "auto" | "kernel" | "userspace"
}
WarpSpec is the node-level WARP configuration (agent.v1.WarpSpec). A nil *WarpSpec means "this node has no WARP"; Enabled=false with a spec present is "paused".