decoy

package
v0.1.71 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 24 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

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

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

View Source
const (
	ModeBuiltin = "builtin"
	ModePanel   = "panel"
	ModeOwn     = "own"
)
View Source
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

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

func BundleHandler(b *Bundle) http.Handler

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

func ClientMessage(err error) string

ClientMessage is the coded message for any bundle error.

func Handler

func Handler() http.Handler

Handler serves the built-in page on "/" and the identical 404 everywhere else.

func NotFound

func NotFound() http.Handler

NotFound answers every request with the same 404 page (masquerade "none").

func ReasonOf added in v0.1.36

func ReasonOf(err error) string

ReasonOf returns the reason of a refusal, ReasonBadArchive for an error that is not a *BundleError.

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

func FromDir(dir string) (*Bundle, error)

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

func FromFiles(files []File) (*Bundle, error)

FromFiles validates files received over the agent protocol and makes a canonical bundle.

func ParseArchive added in v0.1.36

func ParseArchive(data []byte) (*Bundle, error)

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

func ParseStoredArchive(data []byte) (*Bundle, error)

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

func (b *Bundle) Archive() []byte

Archive returns a copy of the stable ZIP representation used for content-addressed storage.

func (*Bundle) Files added in v0.1.36

func (b *Bundle) Files() []File

func (*Bundle) Hash added in v0.1.36

func (b *Bundle) Hash() string

type BundleError added in v0.1.36

type BundleError struct {
	Reason string
	Path   string
}

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

type File struct {
	Path    string
	Content []byte
}

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

func BuiltinSite(stateDir string) *Site

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

func OpenSite(stateDir string) (*Site, error)

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

func (s *Site) Apply(mode, hash string, files []File) (bool, error)

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.

func (*Site) Handler added in v0.1.36

func (s *Site) Handler() http.Handler

Handler returns a stable handler whose active site can be changed while listeners are running.

func (*Site) State added in v0.1.36

func (s *Site) State() (mode, hash string)

State reports the selected mode and the hash of its active bundle. Builtin has an empty hash.

Jump to

Keyboard shortcuts

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