Documentation
¶
Overview ¶
Package decoy is the neutral static site shown to everyone who is not a Hysteria2 client (or an admin): HTTP/3 masquerade, HTTPS on TCP 443, later the panel's public listener.
It is a plain http.Handler with no state and no Server header. "/" answers 200 with a tiny page; every other path and every method other than GET/HEAD answers the identical 404, so probing cannot tell "unknown path" from "wrong method" from "auth failed".
One fixed page for every install (recognisable across installs). A per-install site bundle pushed from the panel replaces this handler later (engine.Env.Masquerade already takes any http.Handler).
Index ¶
Constants ¶
const ( ReasonEmpty = "empty" // nothing to serve ReasonBadArchive = "bad_archive" // not a readable ZIP, TAR or TAR.GZ ReasonTooLarge = "too_large" // the archive or its files are over MaxBundleBytes ReasonTooManyFiles = "too_many_files" // more than 4096 entries ReasonBadPath = "bad_path" // "..", an absolute path, a backslash, a colon or a NUL byte in a name ReasonNotStatic = "not_static" // a symlink, device, FIFO or other entry that is not a plain file ReasonNoIndex = "no_index" // no index.html at the top level ReasonDuplicate = "duplicate" // one path twice, or a file where a directory is needed )
Reasons a bundle is refused. They are stable: the admin shows a sentence for each.
const ( ModeBuiltin = "builtin" ModePanel = "panel" ModeOwn = "own" )
const ( // MaxBundleBytes caps the sum of the file contents and, separately, an uploaded archive. The same cap applies to a // bundle an owner uploads for one node and to the snapshot of the panel's own --decoy-dir. MaxBundleBytes = 2 << 20 )
Variables ¶
var ErrInvalidBundle = errors.New("invalid decoy bundle")
ErrInvalidBundle is the base of every bundle refusal; the concrete error is a *BundleError.
Functions ¶
func BundleHandler ¶ added in v0.1.36
BundleHandler serves a validated site using the same index, dot-path, robots and 404 rules as the panel decoy directory.
func ClientMessage ¶ added in v0.1.36
ClientMessage is the coded message for any bundle error.
Types ¶
type Bundle ¶ added in v0.1.36
type Bundle struct {
// contains filtered or unexported fields
}
Bundle is a validated, immutable static site. Hash is independent of archive order and metadata.
func FromDir ¶ added in v0.1.36
FromDir snapshots a local --decoy-dir bundle. Paths the panel hides by its dot-path rule are omitted; symlinks and non-regular files are refused. The directory is held to the same 2 MiB cap as an uploaded bundle.
func FromFiles ¶ added in v0.1.36
FromFiles validates files received over the agent protocol and makes a canonical bundle.
func ParseArchive ¶ added in v0.1.36
ParseArchive accepts a ZIP, TAR or gzip-compressed TAR upload. The upload and the expanded contents are each capped at 2 MiB. Dot-files and macOS "__MACOSX" entries are dropped (the site never serves them), a single wrapping folder is removed when index.html is inside it, and symlinks, devices, ".." and absolute paths are refused.
func ParseStoredArchive ¶ added in v0.1.36
ParseStoredArchive reads the canonical ZIP kept by the panel and node. Its ZIP metadata may exceed the file-content cap.
type BundleError ¶ added in v0.1.36
BundleError says why a bundle was refused; Path names the offending entry when there is one.
func (*BundleError) ClientMessage ¶ added in v0.1.36
func (e *BundleError) ClientMessage() string
ClientMessage is the coded message the admin and the MCP tools show: "decoy_bundle_<reason>" or "decoy_bundle_<reason>: path=<entry>" (the convention of the panel's refusal codes, web/src/lib/errors.ts).
func (*BundleError) Error ¶ added in v0.1.36
func (e *BundleError) Error() string
func (*BundleError) Is ¶ added in v0.1.36
func (e *BundleError) Is(target error) bool
type File ¶ added in v0.1.36
File is one regular file in a decoy bundle. Paths are slash-separated and relative to the site root.
type Site ¶ added in v0.1.36
type Site struct {
// contains filtered or unexported fields
}
Site atomically swaps the handler used by every node masquerade listener and persists its active bundle.
func BuiltinSite ¶ added in v0.1.36
BuiltinSite returns an in-memory builtin site. It is the safe fallback when persisted node state is unreadable.
func OpenSite ¶ added in v0.1.36
OpenSite loads the site's persisted mode and bundle from stateDir. Missing state means the historical built-in page.
func (*Site) Apply ¶ added in v0.1.36
Apply validates a panel update, stores it atomically, and switches all current requests to the new site. An empty files slice reuses the currently installed bundle only when its hash already matches.