Documentation
¶
Overview ¶
Package protocols turns xtune's state into what servers and apps run: the Xray server config, client outbounds and the failover config, share links and subscriptions (with their names and flags), and the configs and profiles of the WireGuard, AmneziaWG, SSH and DNS tunnels, MTProto, OpenVPN and IKEv2. It only builds; deploying and measuring live in the main package.
Index ¶
- Constants
- Variables
- func AWGAddr(e state.Entry, u state.User) netip.Addr
- func AWGClientParams(p state.AWGParams, mode string) (jc, jmin, jmax int, i1 string)
- func AWGConfFile(st *state.State, e state.Entry, u state.User) string
- func AWGUserKey(u state.User) (priv, pub string)
- func B64hex(s string) string
- func ClientPort(e state.Entry) int
- func ConfigName(st *state.State, e state.Entry, u state.User) string
- func DNSTTInfo(st *state.State, e state.Entry, u state.User) string
- func DialAddr(st *state.State, e state.Entry, k state.Knobs) string
- func FlagEmoji(cc string) string
- func HostPort(host string, port int) string
- func KindLabel(kind string) string
- func Link(st *state.State, e state.Entry, u state.User, k state.Knobs) string
- func Links(st *state.State, u state.User) []string
- func MTProtoInfo(st *state.State, e state.Entry, u state.User) string
- func MTProtoKey(u state.User) []byte
- func MTProtoLink(st *state.State, e state.Entry, u state.User) string
- func MTProtoSecret(u state.User) string
- func MobileConfig(st *state.State, u state.User) string
- func OVPNProfile(st *state.State, e state.Entry, u state.User) string
- func OpenVPNConf(st *state.State, e state.Entry, dir string) string
- func ParseCertPEM(s string) (*x509.Certificate, error)
- func PeerServers(st *state.State) []*state.State
- func RelayStates(st *state.State) []*state.State
- func RelayTarget(st *state.State) string
- func Relayable(e state.Entry) bool
- func SSHInfo(st *state.State, e state.Entry, u state.User) string
- func ServerFlag(st *state.State) string
- func SswanProfile(st *state.State, u state.User) string
- func SubName(st *state.State, u state.User) string
- func Subscription(st *state.State, u state.User) string
- func SwanctlConf(st *state.State, users []state.User) string
- func TunnelPassword(u state.User) string
- func UAPIShared(p state.AWGParams, b *strings.Builder)
- func VPNSubnet(e state.Entry) string
- func VPNUsers(users []state.User) map[string]VPNUser
- func ValidCountryCode(cc string) bool
- func WGConf(st *state.State, e state.Entry, u state.User) string
- func WGMTU(k state.Knobs) int
- func WGUserKey(u state.User) (priv, pub string)
- func WarpDomains(w *state.Warp) []string
- type AWGConf
- type AWGPeer
- type J
- func CertFiles(dir string) []J
- func ClientConfig(out J) J
- func FailoverConfig(st *state.State, u state.User) J
- func FragOutbounds() []J
- func Inbound(st *state.State, e state.Entry, users []state.User) J
- func Outbound(st *state.State, e state.Entry, u state.User, k state.Knobs, tag string) J
- func ServerConfig(st *state.State, entries []state.Entry, users []state.User) J
- type NamedLink
- type Profile
- type TunnelConf
- type TunnelUser
- type VPNUser
Constants ¶
const ( MTProtoFrameLen = 64 MTProtoKeyLen = 16 // the proxy secret )
const PeerStale = 24 * time.Hour
PeerStale is how long a follower that stopped reporting stays in subscriptions.
const ProbeURL = "https://www.gstatic.com/generate_204"
ProbeURL answers 204: tuning and the failover config's health checks fetch it.
Variables ¶
var Countries = map[string][2]string{
"ir": {"geosite:category-ir", "geoip:ir"},
"cn": {"geosite:cn", "geoip:cn"},
"ru": {"geosite:category-ru", "geoip:ru"},
}
Countries maps a country code to the client routing lists that send its sites direct.
var DNSResolvers = []string{"udp:8.8.8.8:53", "udp:1.1.1.1:53", "udp:9.9.9.9:53",
"doh:https://cloudflare-dns.com/dns-query", "doh:https://dns.google/dns-query", "dot:dns.quad9.net:853"}
DNSResolvers are the resolvers DNS tunnel variants are tried through: plain UDP to public resolvers (often the only thing a censor lets out), and DNS over HTTPS and TLS, which look like web traffic.
var DefaultWarpDomains = []string{"geosite:category-ai-!cn", "geosite:google-gemini"}
DefaultWarpDomains are AI services that block datacenter IPs or whole countries.
var FragNames = []string{"none", "frag-mild", "frag-aggr"}
var NamePlaceholder = regexp.MustCompile(`\{(\w+)\}`)
Functions ¶
func AWGAddr ¶
AWGAddr is the user's tunnel address in the entry's subnet: the last two bytes of their WireGuard address. The server is .0.1, which WireGuard addresses never use.
func AWGClientParams ¶
AWGClientParams are p as a client in mode sends them.
func AWGConfFile ¶
AWGConfFile is the config file the AmneziaVPN and AmneziaWG apps import.
func AWGUserKey ¶
func ClientPort ¶
ClientPort is the port clients dial: a Worker answers on 443 whatever port it relays to.
func ConfigName ¶
ConfigName is what apps show for one config of u.
func DialAddr ¶
DialAddr is the address the client connects to: a clean IP for CDN and Worker entries when tuning chose one, the entry's usual address otherwise.
func FlagEmoji ¶
FlagEmoji is the flag of an ISO 3166-1 alpha-2 country code ("DE" → 🇩🇪), "" for anything else.
func MTProtoInfo ¶
MTProtoInfo is what to type into Telegram's proxy settings by hand.
func MTProtoKey ¶
func MTProtoLink ¶
MTProtoLink opens the proxy in Telegram and doubles as the page's QR code.
func MTProtoSecret ¶
MTProtoSecret is the secret Telegram apps take: the "dd" prefix (padded-intermediate transport, no fake TLS) plus the user's 16-byte key in hex.
func MobileConfig ¶
MobileConfig is an Apple configuration profile (iOS, macOS) with the CA and the IKEv2 VPN.
func OVPNProfile ¶
OVPNProfile is an OpenVPN client profile; the app asks for the user name and password.
func OpenVPNConf ¶
OpenVPNConf is the server config of one OpenVPN entry; files live in dir.
func ParseCertPEM ¶
func ParseCertPEM(s string) (*x509.Certificate, error)
ParseCertPEM decodes the first certificate in a PEM block.
func PeerServers ¶
PeerServers are this deployment and, on a primary, the followers that reported recently, with their entries named after them.
func RelayStates ¶
RelayStates are this server's configs as clients reach them through each relay. A relay that forwards to an old address (after a move) is left out until it is synced.
func RelayTarget ¶
RelayTarget is the address of this server relays forward to.
func Relayable ¶
Relayable entries can go through a port forwarder: the others are reached by domain (CDN, Worker), through DNS resolvers (dnstt), or are VPNs whose certificate or profile names this server.
func SSHInfo ¶
SSHInfo is what HTTP Injector, NetMod and similar apps need for an SSH entry: where to connect, whether to wrap it in TLS (with which SNI), and the payload to send first.
func ServerFlag ¶
ServerFlag is the country code behind {flag} and {country}, "" when unknown or off.
func SswanProfile ¶
SswanProfile is a strongSwan app profile: the CA is included, the app asks for the password.
func SubName ¶
SubName is the subscription's name in apps (Profile-Title) and of the failover config.
func Subscription ¶
Subscription is the base64 body most clients accept as an imported subscription.
func SwanctlConf ¶
SwanctlConf is strongSwan's config for the ikev2 entry and the active users' EAP secrets. The helper installs the certificate and key into strongSwan's x509 and private directories, the only place it loads unencrypted keys from.
func TunnelPassword ¶
TunnelPassword is the user's password for SSH, OpenVPN and IKEv2.
func ValidCountryCode ¶
func WarpDomains ¶
Types ¶
type AWGConf ¶
type AWGConf struct {
Params state.AWGParams `json:"params"`
Entries []state.Entry `json:"entries"`
Peers []AWGPeer `json:"peers"`
Stats string `json:"stats"` // where the server writes its counters (tunnelStats)
}
AWGConf is what `xtune awg run` serves.
type J ¶
func ClientConfig ¶
ClientConfig is a ready-to-run client config (socks 10808, http 10809).
func FailoverConfig ¶
FailoverConfig is a full client config with every deployed config behind one balancer: Xray health-checks them and uses the fastest working one, so a blocked config fails over by itself (to the CDN entry, for example). Private addresses, and the chosen country's sites, go direct; ads are blocked. Domain strategy AsIs keeps DNS lookups for proxied sites off the local network.
func FragOutbounds ¶
func FragOutbounds() []J
type NamedLink ¶
type NamedLink struct{ Name, URL string }
NamedLink is a link and what to call it: a config's share link, a profile file, an app's import link.
type Profile ¶
type Profile struct {
Name string // shown to the user
File string
Type string // MIME type
Body string
}
Profile is a file a user imports into an app.
type TunnelConf ¶
type TunnelConf struct {
Entries []state.Entry `json:"entries"`
Users []TunnelUser `json:"users"`
HostKey string `json:"hostKey"`
CertPEM string `json:"certPem"`
KeyPEM string `json:"keyPem"`
DNSTTKey string `json:"dnsttKey,omitempty"`
DNSDomain string `json:"dnsDomain,omitempty"`
Stats string `json:"stats"` // where the server writes its counters
}
TunnelConf is what the tunnel server runs.
func TunnelServerConf ¶
func TunnelServerConf(st *state.State, entries []state.Entry, users []state.User, statsPath string) TunnelConf
TunnelServerConf builds the tunnel server's config for these users.