plugin

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0 modules, 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 (
	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.

View Source
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).

View Source
const (
	ShareUnsupported = "share_unsupported" // a service with no name to be told apart by, or one that cannot take part
	ShareNeedsSite   = "share_needs_site"  // none of the services answers a stranger with the node's own site
	SNITaken         = "sni_taken"         // two services ask for the same name
)

The codes of a port that services cannot share (the panel refuses a layout that has one, and words them: admin sentences).

View Source
const MaxWarpReachDomains = 8

MaxWarpReachDomains is the most sites one WARP reach run takes (agent.proto "WARP REACH").

Variables

This section is empty.

Functions

func Hy2SitePort

func Hy2SitePort(s InboundSpec) uint16

Hy2SitePort is the TCP port of a Hysteria2 inbound's HTTPS site, 0 = none: settings.masquerade.tcp_port, 443 when omitted. The node listens there whatever masquerade.type says (type none answers 404, it still answers), and not at all without a TLS mode (no certificate), with a port outside 1-65535 or with settings it cannot read (the inbound does not start).

func NormalizeRealityTarget

func NormalizeRealityTarget(text string) string

NormalizeRealityTarget is a REALITY target typed as text in the form the panel keeps it: trimmed, the host in lower case without a closing dot, the port as a number ("Shop.Example.com.:0443" is "shop.example.com:443"). Text that is not "host:port" comes back trimmed, for the panel to refuse.

func RealityTarget

func RealityTarget(s InboundSpec) (target, name string, ok bool)

RealityTarget is the site a VLESS REALITY inbound shows to strangers when that is another site than the node's own: its target ("host:port") and the first server name the node asks it for (what the engine's own probe sends). ok is false for every other inbound: other protocols, TLS, the node's own site (target "self"), and settings that cannot be read.

func RealityTargetShown

func RealityTargetShown(s InboundSpec) string

RealityTargetShown is what a VLESS REALITY inbound shows strangers, for a person to read: "self" (the node's own site), the target's "host:port", or "" for an inbound that is not VLESS REALITY.

func ServerCDN

func ServerCDN(s InboundSpec) bool

ServerCDN says people reach this server through a CDN host, not the node's address.

func SharesTCPPort

func SharesTCPPort(protocol string) bool

SharesTCPPort says the TCP inbounds of the protocol can stand on one port, told apart by the name in the first ClientHello (TCPSharePlan). A TCP inbound of any other protocol keeps the port to itself.

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). A port that services share by SNI (TCPSharePlan) answers strangers with its default route. 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

func ValidWarpReachDomain(s string) bool

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

type BridgeTarget struct {
	RelayID string
	Network string
	Port    uint16
}

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.

func Skipped added in v0.1.40

func Skipped(note string) (Fragment, bool)

Skipped is the result of a Render that leaves the server out for a reason with a code.

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.

func (LinkStat) Zero

func (s LinkStat) Zero() bool

Zero reports a delta without any counter (an engine leaves it out).

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 agentcap.RelayReverse (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 RunState

type RunState int // values equal agent.v1.InboundRunState
const (
	RunStarting RunState = 1
	RunRunning  RunState = 2
	RunFailed   RunState = 3
	RunStopped  RunState = 4
)

type Session

type Session struct {
	CredID    string
	InboundID string
	Since     time.Time
}

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.
	Routes  []TCPRoute
	Default string
	// Shadowed are the services that asked for a name a service with a lower id holds: they get no route and do not run.
	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.

func TCPRouteOf

func TCPRouteOf(s InboundSpec) (TCPRoute, bool)

TCPRouteOf is the route a TCP inbound offers a shared port: the names it answers to and whether it serves the node's own site. ok is false when it has no name to be told apart by (or is no inbound a port can be shared with).

type TCPShadow

type TCPShadow struct{ Name, By string }

TCPShadow says whose name an inbound asked for and did not get.

type TCPShareProblem

type TCPShareProblem struct {
	Code string
	// ID is the inbound it is about: the one with no name (ShareUnsupported), the one that lost the name (SNITaken); "" for
	// ShareNeedsSite.
	ID string
	// Name and By: the name and the inbound that holds it (SNITaken).
	Name, By string
}

TCPShareProblem is one reason the TCP inbounds of a port cannot share it. It is comparable: the panel judges a change by the problems it adds.

func TCPShareProblems

func TCPShareProblems(specs []InboundSpec, port uint16) []TCPShareProblem

TCPShareProblems says what stops the TCP inbounds of port from sharing it, nothing when they can, or when fewer than two of them are there (one service listens alone, whatever it is). It takes the inbounds as TCPSharePlan does, and a caller that checks a layout before it is enabled passes the disabled ones too. One service that cannot take part (no name, another protocol) is the only problem reported: the others cannot be judged without it.

type TLS

type TLS struct {
	Mode       TLSMode
	ServerName string
}

type TLSMode

type TLSMode int // values equal agent.v1.TlsMode
const (
	TLSAcmeDomain TLSMode = 1
	TLSAcmeIP     TLSMode = 2
	TLSSelfSigned TLSMode = 3
)

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.

func (Tunnel) IsZero

func (t Tunnel) IsZero() bool

IsZero reports whether no tunnel is set.

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.

func (TunnelRefusals) Zero

func (r TunnelRefusals) Zero() bool

Zero reports no refusal at all.

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

type UserTraffic struct {
	CredID    string
	InboundID string
	Up, Down  uint64
}

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 VLESSView

type VLESSView struct {
	Security, Transport string // "reality" | "tls"; "tcp" | "xhttp" | "ws"
	Target              string // REALITY: "self" (the node's own site) or "host:port" of another site
	ServerNames         []string
	CDNHost             string // the name people reach a TLS inbound by through a CDN, "" = none
}

VLESSView is what the settings of a VLESS inbound say, read as the node reads them: Target is trimmed, CDNHost is lower case without a closing dot, ServerNames are as written.

func VLESSOf

func VLESSOf(s InboundSpec) (v VLESSView, ok bool)

VLESSOf reads the settings of a VLESS inbound; ok is false for any other protocol and for settings that cannot be read (the view is then empty). Settings that are absent read as an empty view.

func (VLESSView) OwnSite

func (v VLESSView) OwnSite() bool

OwnSite says a stranger who finds the port gets the node's own HTTPS site: a TLS inbound, or REALITY with target "self" (settings that name no security are read as REALITY).

func (VLESSView) TLS

func (v VLESSView) TLS() bool

TLS says the inbound is a TLS server (its own certificate), not REALITY.

func (VLESSView) TargetHost

func (v VLESSView) TargetHost() string

TargetHost is the host of the REALITY target, "" when it is not "host:port".

func (VLESSView) TargetSelf

func (v VLESSView) TargetSelf() bool

TargetSelf says the REALITY target is the node's own site (wire value "self").

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".

Directories

Path Synopsis
Package plugintest holds the inputs the tests of everything that reads an inbound's settings share, so each is run on the same cases.
Package plugintest holds the inputs the tests of everything that reads an inbound's settings share, so each is run on the same cases.

Jump to

Keyboard shortcuts

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