Skip to content

EN Snishaper Core

dongle edited this page Oct 25, 2026 · 6 revisions

中文 | English

Snishaper-Core Library

snishaper-core (Go module: github.com/SnishaperTeam/snishaper-core, AGPL-3.0) is the core proxy library extracted from SniShaper. The SniShaper app depends on it directly via go.mod; the core proxy code is no longer vendored in the app repo.

Packages

Package Description
proxy ProxyServer (HTTP + SOCKS5 hybrid port), RuleManager (rule engine; since v0.7.0 rules live in an effective-state file plus a pristine upstream backup with the user diff derived on demand, exposing GetRulesLayerInfo / RevertSiteGroupToUpstream / RevertUpstreamConfigToUpstream), AutoRouter, MITM, upstream dialing
subscription Clash subscription parsing, node storage and protocol outbound (vmess / vless / trojan / shadowsocks / hysteria / tuic / wireguard, etc., mihomo adapters; since v0.2.0)
dohresolver Multi-node DoH failover resolution
cfpool Cloudflare preferred-IP pool
netiface Physical interface selection and outbound binding
tlsfrag TLS ClientHello fragmentation (TLS-RF)
gfwlist GFWList domain suffix matching (local cache file only, no network updates)
certmanager CA generation, MITM certificate minting, system trust installation
singtun sing-tun based TUN dataplane
config Shared configuration types (CertVerifyConfig etc.)
log Logger interface with Nop / Std / Func adapters

Design Conventions

  • Zero global mutable state: no init(), no package-level mutable state, no environment reads, no os.Exit; safe for multiple instances and concurrent embedding.
  • Injected behavior: logging goes through log.Logger (defaults to Nop; the SniShaper app injects Std); the debug switch (formerly SNISHAPER_ROUTER_DEBUG=1) is injected via proxy.WithRouterDebug.
  • Product identity injected via config.Brand: proxy, dohresolver and subscription all accept brand options; the zero value falls back to config.DefaultProductName (SniShaper). The library hardcodes no product name — including the subscription download User-Agent (clash-verge/v2.0 <product>). Embedders other than SniShaper should pass their own name explicitly.
  • Config semantics compatibility: rule and settings JSON formats and semantics stay consistent with the SniShaper app side.

Developing SniShaper and snishaper-core Together

Release dependencies come from go.mod (currently v0.7.0). To modify both repos at once, add a temporary local replace to SniShaper's go.mod:

replace github.com/SnishaperTeam/snishaper-core => ../snishaper-core

Remove the replace before committing. Full library docs live in its repo README and docs/DESIGN.md; a minimal embedder sample is available at examples/basic.

Clone this wiki locally