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
- Variables
- func BuiltinHTML() string
- func BundleHandler(b *Bundle) http.Handler
- func ClientMessage(err error) string
- func Handler() http.Handler
- func NotFound() http.Handler
- func NotFoundHTML() string
- func PreviewDocument(b *Bundle, page string) (string, error)
- func ReasonOf(err error) string
- func TextFile(b *Bundle, name string) (text string, size int, truncated bool, err error)
- type Bundle
- func (b *Bundle) Archive() []byte
- func (b *Bundle) FS() fs.FS
- func (b *Bundle) File(name string) ([]byte, bool)
- func (b *Bundle) Files() []File
- func (b *Bundle) Hash() string
- func (b *Bundle) Infos() []FileInfo
- func (b *Bundle) Pages() []string
- func (b *Bundle) Size() int
- func (b *Bundle) With(name string, content []byte) (*Bundle, error)
- func (b *Bundle) Without(name string) (nb *Bundle, ok bool, err error)
- type BundleError
- type File
- type FileInfo
- type Report
- type Site
- type Warning
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 ( WarnNo404 = "no_404" WarnExternalURLs = "external_urls" WarnTelltale = "telltale_words" WarnScripts = "scripts_or_forms" WarnDuplicateName = "duplicate_title" WarnFewPages = "few_pages" WarnSharedDomains = "shared_domains" )
The warnings of a site (design: the library's "checks"). The required checks (index.html, size, file count, plain files and safe paths) are the bundle rules themselves: a bundle that exists has passed them.
const ( // MaxPreviewBytes caps the document: the bundle is at most 2 MiB and data: URIs are a third bigger, and a file used many // times is inlined every time. MaxPreviewBytes = 6 << 20 // MaxTextBytes is how much of a text file GetFile returns. MaxTextBytes = 256 << 10 )
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 )
const MinAssistantPages = 3
MinAssistantPages is the fewest HTML pages a site made by the assistant should have.
Variables ¶
var ( ErrPageNotFound = errors.New("decoy page not found") ErrNotText = errors.New("decoy file is not text") ErrPreviewTooLarge = errors.New("decoy preview too large") )
var ErrInvalidBundle = errors.New("invalid decoy bundle")
ErrInvalidBundle is the base of every bundle refusal; the concrete error is a *BundleError.
Functions ¶
func BuiltinHTML ¶
func BuiltinHTML() string
BuiltinHTML is the built-in page: the one the node, the panel's public listener and the library's preview all show.
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.
func NotFoundHTML ¶
func NotFoundHTML() string
NotFoundHTML is the built-in 404 page (a site without a 404.html answers with it).
func PreviewDocument ¶
PreviewDocument is the page as one self-contained HTML document (see the top of this file).
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 BuiltinBundle ¶
func BuiltinBundle() *Bundle
BuiltinBundle is the built-in page as a bundle of one file, so the library reads it as it reads a site (preview, files). The text is BuiltinHTML, the one the node and the panel serve.
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.
func (*Bundle) Archive ¶ added in v0.1.36
Archive returns a copy of the stable ZIP representation used for content-addressed storage.
func (*Bundle) FS ¶
FS is the bundle as a read-only file system: the panel serves its own public site from it with the rules of a directory. Directories exist only as the parents of files.
func (*Bundle) File ¶
File returns the content of one file. The slice belongs to the bundle: do not change it.
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.