Documentation
¶
Index ¶
- Constants
- type Config
- func (c *Config) ApplyEnvironment() error
- func (c *Config) GetAPIToken() string
- func (c *Config) GetAdTag() *[mtglib.AdTagLength]byte
- func (c *Config) GetBindAddrs() []string
- func (c *Config) GetConcurrency(defaultValue uint) uint
- func (c *Config) GetDNS() *url.URL
- func (c *Config) GetDomainFrontingHost() string
- func (c *Config) GetDomainFrontingPort(defaultValue uint) uint
- func (c *Config) GetDomainFrontingProxyProtocol(defaultValue bool) bool
- func (c *Config) GetFirstBindPort() uint
- func (c *Config) GetSecretAdTags() map[string][mtglib.AdTagLength]byte
- func (c *Config) GetSecretLimits() map[string]mtglib.SecretLimits
- func (c *Config) GetSecrets() map[string]mtglib.Secret
- func (c *Config) String() string
- func (c *Config) Validate() error
- type ConfigSecretLimit
- type ListConfig
- type Optional
- type TypeAdTag
- type TypeBlocklistURI
- func (t TypeBlocklistURI) Get(defaultValue string) string
- func (t TypeBlocklistURI) IsRemote() bool
- func (t TypeBlocklistURI) MarshalText() ([]byte, error)
- func (t *TypeBlocklistURI) Set(value string) error
- func (t TypeBlocklistURI) String() string
- func (t *TypeBlocklistURI) UnmarshalText(data []byte) error
- type TypeBool
- type TypeBytes
- type TypeConcurrency
- type TypeDC
- type TypeDNSURI
- type TypeDuration
- type TypeErrorRate
- type TypeExpiry
- type TypeHTTPPath
- type TypeHost
- type TypeHostPort
- type TypeHttpsURL
- type TypeIP
- type TypeMetricPrefix
- type TypePort
- type TypePreferIP
- type TypeProxyURL
- type TypeQuotaReset
- type TypeStatsdTagFormat
Constants ¶
const ( // EnvSecret is the proxy secret. Either a full mtg secret (ee-prefixed // hex or base64) or, for parity with the official image, a bare 16-byte // hex key which is combined with EnvSecretHost into a FakeTLS secret. EnvSecret = "SECRET" // EnvSecretHost is the domain-fronting hostname used when EnvSecret // holds a bare 16-byte key. Ignored when EnvSecret is a full secret. EnvSecretHost = "SECRET_HOST" // EnvAdTag is the advertising tag issued by @MTProxybot (the official // image calls it TAG). An empty value clears the tag from the file. EnvAdTag = "TAG" // EnvBindTo is a comma-separated list of host:port pairs to listen on. // It has no unprefixed form: the official image does not document one. EnvBindTo = "MTG_BIND_TO" )
Environment variable names understood by ApplyEnvironment. The unprefixed names mirror the official telegrammessenger/proxy Docker image (https://hub.docker.com/r/telegrammessenger/proxy/), so its documented "docker run -e SECRET=... -e TAG=..." invocations work with mtg-proxy containers as well. MTG_-prefixed variants always win over the unprefixed ones, so generic names like SECRET cannot be captured by accident outside of a container.
const ( // TypePreferIPPreferIPv4 states that you prefer to use IPv4 addresses // but IPv6 is also possible. TypePreferIPPreferIPv4 = "prefer-ipv4" // TypePreferIPPreferIPv6 states that you prefer to use IPv6 addresses // but IPv4 is also possible. TypePreferIPPreferIPv6 = "prefer-ipv6" // TypePreferOnlyIPv4 states that you prefer to use IPv4 addresses // only. TypePreferOnlyIPv4 = "only-ipv4" // TypePreferOnlyIPv6 states that you prefer to use IPv6 addresses // only. TypePreferOnlyIPv6 = "only-ipv6" )
const ( // TypeStatsdTagFormatInfluxdb defines a tag format compatible with // InfluxDB. TypeStatsdTagFormatInfluxdb = "influxdb" // TypeStatsdTagFormatDatadog defines a tag format compatible with // DataDog. TypeStatsdTagFormatDatadog = "datadog" // TypeStatsdTagFormatGraphite defines a tag format compatible with // Graphite. TypeStatsdTagFormatGraphite = "graphite" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Debug TypeBool `json:"debug"`
AllowFallbackOnUnknownDC TypeBool `json:"allowFallbackOnUnknownDc"`
Secret mtglib.Secret `json:"secret"`
Secrets map[string]mtglib.Secret `json:"secrets"`
AdTag TypeAdTag `json:"adTag"`
SecretAdTags map[string]TypeAdTag `json:"secretAdTags"`
SecretLimits map[string]ConfigSecretLimit `json:"secretLimits"`
UsageStateFile string `json:"usageStateFile"`
APIToken string `json:"apiToken"`
BindTo []TypeHostPort `json:"bindTo"`
ProxyProtocolListener TypeBool `json:"proxyProtocolListener"`
PreferIP TypePreferIP `json:"preferIp"`
AutoUpdate TypeBool `json:"autoUpdate"`
DomainFrontingPort TypePort `json:"domainFrontingPort"`
DomainFrontingIP TypeIP `json:"domainFrontingIp"`
DomainFrontingProxyProtocol TypeBool `json:"domainFrontingProxyProtocol"`
TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
Concurrency TypeConcurrency `json:"concurrency"`
PublicIPv4 TypeIP `json:"publicIpv4"`
PublicIPv6 TypeIP `json:"publicIpv6"`
DomainFronting struct {
Host TypeHost `json:"host"`
IP TypeIP `json:"ip"`
Port TypePort `json:"port"`
ProxyProtocol TypeBool `json:"proxyProtocol"`
} `json:"domainFronting"`
Defense struct {
AntiReplay struct {
Optional
MaxSize TypeBytes `json:"maxSize"`
ErrorRate TypeErrorRate `json:"errorRate"`
} `json:"antiReplay"`
Blocklist ListConfig `json:"blocklist"`
Allowlist ListConfig `json:"allowlist"`
Doppelganger struct {
URLs []TypeHttpsURL `json:"urls"`
Repeats TypeConcurrency `json:"repeats_per_raid"`
UpdateEach TypeDuration `json:"raid_each"`
DRS TypeBool `json:"drs"`
} `json:"doppelganger"`
} `json:"defense"`
Network struct {
Timeout struct {
TCP TypeDuration `json:"tcp"`
HTTP TypeDuration `json:"http"`
Idle TypeDuration `json:"idle"`
Handshake TypeDuration `json:"handshake"`
} `json:"timeout"`
KeepAlive struct {
Disabled TypeBool `json:"disabled"`
Idle TypeDuration `json:"idle"`
Interval TypeDuration `json:"interval"`
Count TypeConcurrency `json:"count"`
} `json:"keepAlive"`
DOHIP TypeIP `json:"dohIp"`
DNS TypeDNSURI `json:"dns"`
Proxies []TypeProxyURL `json:"proxies"`
TCPNotSentLowat TypeBytes `json:"tcpNotSentLowat"`
} `json:"network"`
APIBindTo TypeHostPort `json:"apiBindTo"`
Throttle struct {
MaxConnections TypeConcurrency `json:"maxConnections"`
CheckInterval TypeDuration `json:"checkInterval"`
} `json:"throttle"`
Stats struct {
StatsD struct {
Optional
Address TypeHostPort `json:"address"`
MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
TagFormat TypeStatsdTagFormat `json:"tagFormat"`
} `json:"statsd"`
Prometheus struct {
Optional
BindTo TypeHostPort `json:"bindTo"`
HTTPPath TypeHTTPPath `json:"httpPath"`
MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
} `json:"prometheus"`
} `json:"stats"`
}
func (*Config) ApplyEnvironment ¶
ApplyEnvironment overlays environment variables on top of a parsed config file. The environment always wins, mirroring how the official telegrammessenger/proxy image is configured per "docker run". It is applied on every config read, including hot reloads, so an env-pinned secret or tag survives a POST /reload.
func (*Config) GetAPIToken ¶
GetAPIToken returns the bearer token guarding the management API, or an empty string when the API should stay unauthenticated (localhost-bind convention).
func (*Config) GetAdTag ¶
func (c *Config) GetAdTag() *[mtglib.AdTagLength]byte
GetAdTag returns the global advertising tag, or nil when none is configured.
func (*Config) GetBindAddrs ¶
GetBindAddrs returns all bind addresses as strings.
func (*Config) GetConcurrency ¶
func (*Config) GetDomainFrontingHost ¶
func (*Config) GetDomainFrontingPort ¶
func (*Config) GetDomainFrontingProxyProtocol ¶
func (*Config) GetFirstBindPort ¶
GetFirstBindPort returns the port of the first bind address.
func (*Config) GetSecretAdTags ¶
func (c *Config) GetSecretAdTags() map[string][mtglib.AdTagLength]byte
GetSecretAdTags returns the per-secret advertising tag overrides keyed by secret name, or nil when none are configured.
func (*Config) GetSecretLimits ¶
func (c *Config) GetSecretLimits() map[string]mtglib.SecretLimits
GetSecretLimits converts the [secret-limits] tables into the engine-level map keyed by secret name, or nil when none impose any restriction.
func (*Config) GetSecrets ¶
GetSecrets returns all secrets as a map. If the new [secrets] section is used, returns that map. Otherwise, wraps the single Secret as {"default": Secret}.
type ConfigSecretLimit ¶
type ConfigSecretLimit struct {
Quota TypeBytes `json:"quota"`
QuotaReset TypeQuotaReset `json:"quotaReset"`
Expires TypeExpiry `json:"expires"`
Disabled TypeBool `json:"disabled"`
}
ConfigSecretLimit is the typed form of a single [secret-limits.<name>] table: an optional data quota (with reset policy), an expiry deadline and a disabled flag. All fields are optional; the zero value leaves the secret unrestricted.
type ListConfig ¶
type ListConfig struct {
Optional
DownloadConcurrency TypeConcurrency `json:"downloadConcurrency"`
URLs []TypeBlocklistURI `json:"urls"`
UpdateEach TypeDuration `json:"updateEach"`
}
type TypeAdTag ¶
type TypeAdTag struct {
Value []byte
}
TypeAdTag is a Telegram advertising tag (ad_tag / proxy tag). It is a 16-byte value, configured as a 32-character hex string, and used to route a client through Telegram middle proxies so a sponsored channel is shown.
func (*TypeAdTag) Get ¶
func (t *TypeAdTag) Get() *[mtglib.AdTagLength]byte
Get returns the tag as a pointer to a fixed-size array, or nil when unset.
func (TypeAdTag) MarshalText ¶
func (*TypeAdTag) UnmarshalText ¶
type TypeBlocklistURI ¶
type TypeBlocklistURI struct {
Value string
}
func (TypeBlocklistURI) Get ¶
func (t TypeBlocklistURI) Get(defaultValue string) string
func (TypeBlocklistURI) IsRemote ¶
func (t TypeBlocklistURI) IsRemote() bool
func (TypeBlocklistURI) MarshalText ¶
func (t TypeBlocklistURI) MarshalText() ([]byte, error)
func (*TypeBlocklistURI) Set ¶
func (t *TypeBlocklistURI) Set(value string) error
func (TypeBlocklistURI) String ¶
func (t TypeBlocklistURI) String() string
func (*TypeBlocklistURI) UnmarshalText ¶
func (t *TypeBlocklistURI) UnmarshalText(data []byte) error
type TypeBool ¶
type TypeBool struct {
Value bool
}
func (TypeBool) MarshalJSON ¶
func (*TypeBool) UnmarshalJSON ¶
type TypeBytes ¶
type TypeBytes struct {
Value units.Base2Bytes
}
func (TypeBytes) MarshalText ¶
func (*TypeBytes) UnmarshalText ¶
type TypeConcurrency ¶
type TypeConcurrency struct {
Value uint
}
func (TypeConcurrency) Get ¶
func (t TypeConcurrency) Get(defaultValue uint) uint
func (TypeConcurrency) MarshalJSON ¶
func (t TypeConcurrency) MarshalJSON() ([]byte, error)
func (*TypeConcurrency) Set ¶
func (t *TypeConcurrency) Set(value string) error
func (TypeConcurrency) String ¶
func (t TypeConcurrency) String() string
func (*TypeConcurrency) UnmarshalJSON ¶
func (t *TypeConcurrency) UnmarshalJSON(data []byte) error
type TypeDC ¶
type TypeDC struct {
Value int
}
func (TypeDC) MarshalJSON ¶
func (*TypeDC) UnmarshalJSON ¶
type TypeDNSURI ¶
func (TypeDNSURI) MarshalText ¶
func (t TypeDNSURI) MarshalText() ([]byte, error)
func (*TypeDNSURI) Set ¶
func (t *TypeDNSURI) Set(value string) error
func (TypeDNSURI) String ¶
func (t TypeDNSURI) String() string
func (*TypeDNSURI) UnmarshalText ¶
func (t *TypeDNSURI) UnmarshalText(data []byte) error
type TypeDuration ¶
func (TypeDuration) MarshalText ¶
func (t TypeDuration) MarshalText() ([]byte, error)
func (*TypeDuration) Set ¶
func (t *TypeDuration) Set(value string) error
func (TypeDuration) String ¶
func (t TypeDuration) String() string
func (*TypeDuration) UnmarshalText ¶
func (t *TypeDuration) UnmarshalText(data []byte) error
type TypeErrorRate ¶
type TypeErrorRate struct {
Value float64
}
func (TypeErrorRate) Get ¶
func (t TypeErrorRate) Get(defaultValue float64) float64
func (TypeErrorRate) MarshalJSON ¶
func (t TypeErrorRate) MarshalJSON() ([]byte, error)
func (*TypeErrorRate) Set ¶
func (t *TypeErrorRate) Set(value string) error
func (TypeErrorRate) String ¶
func (t TypeErrorRate) String() string
func (*TypeErrorRate) UnmarshalJSON ¶
func (t *TypeErrorRate) UnmarshalJSON(data []byte) error
type TypeExpiry ¶
TypeExpiry is a secret validity deadline parsed from an RFC3339 timestamp or a plain YYYY-MM-DD date. The zero value means the secret never expires.
func (TypeExpiry) MarshalText ¶
func (t TypeExpiry) MarshalText() ([]byte, error)
func (*TypeExpiry) Set ¶
func (t *TypeExpiry) Set(value string) error
func (TypeExpiry) String ¶
func (t TypeExpiry) String() string
func (*TypeExpiry) UnmarshalText ¶
func (t *TypeExpiry) UnmarshalText(data []byte) error
type TypeHTTPPath ¶
type TypeHTTPPath struct {
Value string
}
func (TypeHTTPPath) Get ¶
func (t TypeHTTPPath) Get(defaultValue string) string
func (TypeHTTPPath) MarshalText ¶
func (t TypeHTTPPath) MarshalText() ([]byte, error)
func (*TypeHTTPPath) Set ¶
func (t *TypeHTTPPath) Set(value string) error
func (TypeHTTPPath) String ¶
func (t TypeHTTPPath) String() string
func (*TypeHTTPPath) UnmarshalText ¶
func (t *TypeHTTPPath) UnmarshalText(data []byte) error
type TypeHost ¶
type TypeHost struct {
Value string
}
TypeHost is a non-empty string that is either a literal IP address (IPv4 or IPv6) or a hostname suitable for DNS resolution. It does not include a port — the port belongs in a separate field.
func (TypeHost) MarshalText ¶
func (*TypeHost) UnmarshalText ¶
type TypeHostPort ¶
func (TypeHostPort) Get ¶
func (t TypeHostPort) Get(defaultValue string) string
func (TypeHostPort) MarshalText ¶
func (t TypeHostPort) MarshalText() ([]byte, error)
func (*TypeHostPort) Set ¶
func (t *TypeHostPort) Set(value string) error
func (TypeHostPort) String ¶
func (t TypeHostPort) String() string
func (*TypeHostPort) UnmarshalText ¶
func (t *TypeHostPort) UnmarshalText(data []byte) error
type TypeHttpsURL ¶
func (TypeHttpsURL) MarshalText ¶
func (t TypeHttpsURL) MarshalText() ([]byte, error)
func (*TypeHttpsURL) Set ¶
func (t *TypeHttpsURL) Set(value string) error
func (TypeHttpsURL) String ¶
func (t TypeHttpsURL) String() string
func (*TypeHttpsURL) UnmarshalText ¶
func (t *TypeHttpsURL) UnmarshalText(data []byte) error
type TypeMetricPrefix ¶
type TypeMetricPrefix struct {
Value string
}
func (TypeMetricPrefix) Get ¶
func (t TypeMetricPrefix) Get(defaultValue string) string
func (TypeMetricPrefix) MarshalText ¶
func (t TypeMetricPrefix) MarshalText() ([]byte, error)
func (*TypeMetricPrefix) Set ¶
func (t *TypeMetricPrefix) Set(value string) error
func (TypeMetricPrefix) String ¶
func (t TypeMetricPrefix) String() string
func (*TypeMetricPrefix) UnmarshalText ¶
func (t *TypeMetricPrefix) UnmarshalText(data []byte) error
type TypePort ¶
type TypePort struct {
Value uint
}
func (TypePort) MarshalJSON ¶
func (*TypePort) UnmarshalJSON ¶
type TypePreferIP ¶
type TypePreferIP struct {
Value string
}
func (*TypePreferIP) Get ¶
func (t *TypePreferIP) Get(defaultValue string) string
func (TypePreferIP) MarshalText ¶
func (t TypePreferIP) MarshalText() ([]byte, error)
func (*TypePreferIP) Set ¶
func (t *TypePreferIP) Set(value string) error
func (TypePreferIP) String ¶
func (t TypePreferIP) String() string
func (*TypePreferIP) UnmarshalText ¶
func (t *TypePreferIP) UnmarshalText(data []byte) error
type TypeProxyURL ¶
func (TypeProxyURL) MarshalText ¶
func (t TypeProxyURL) MarshalText() ([]byte, error)
func (*TypeProxyURL) Set ¶
func (t *TypeProxyURL) Set(value string) error
func (TypeProxyURL) String ¶
func (t TypeProxyURL) String() string
func (*TypeProxyURL) UnmarshalText ¶
func (t *TypeProxyURL) UnmarshalText(data []byte) error
type TypeQuotaReset ¶
type TypeQuotaReset struct {
Value string
}
TypeQuotaReset is a per-secret data-quota reset policy: "none" (default) or "monthly".
func (TypeQuotaReset) Get ¶
func (t TypeQuotaReset) Get(defaultValue string) string
func (TypeQuotaReset) MarshalText ¶
func (t TypeQuotaReset) MarshalText() ([]byte, error)
func (*TypeQuotaReset) Set ¶
func (t *TypeQuotaReset) Set(value string) error
func (TypeQuotaReset) String ¶
func (t TypeQuotaReset) String() string
func (*TypeQuotaReset) UnmarshalText ¶
func (t *TypeQuotaReset) UnmarshalText(data []byte) error
type TypeStatsdTagFormat ¶
type TypeStatsdTagFormat struct {
Value string
}
func (TypeStatsdTagFormat) Get ¶
func (t TypeStatsdTagFormat) Get(defaultValue string) string
func (*TypeStatsdTagFormat) MarshalText ¶
func (t *TypeStatsdTagFormat) MarshalText() ([]byte, error)
func (*TypeStatsdTagFormat) Set ¶
func (t *TypeStatsdTagFormat) Set(value string) error
func (*TypeStatsdTagFormat) String ¶
func (t *TypeStatsdTagFormat) String() string
func (*TypeStatsdTagFormat) UnmarshalText ¶
func (t *TypeStatsdTagFormat) UnmarshalText(data []byte) error
Source Files
¶
- config.go
- env.go
- parse.go
- type_adtag.go
- type_blocklist_uri.go
- type_bool.go
- type_bytes.go
- type_concurrency.go
- type_dc.go
- type_dns_uri.go
- type_duration.go
- type_error_rate.go
- type_expiry.go
- type_host.go
- type_hostport.go
- type_http_path.go
- type_https_url.go
- type_ip.go
- type_metric_prefix.go
- type_port.go
- type_prefer_ip.go
- type_proxy_url.go
- type_quota_reset.go
- type_statsd_tag_format.go