mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 11:54:01 +03:00
FILE / ScuroNeko/mtg
internal/config/config.go
Исходный файл и его история в репозитории.
Allow specifying an explicit IP address for the domain fronting host instead of relying on DNS resolution. Useful when DNS resolution of the fronting hostname is blocked. The hostname from the secret is still used for SNI in TLS handshake.
99 lines
2.6 KiB
Go
99 lines
2.6 KiB
Go
package config
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/9seconds/mtg/v2/mtglib"
|
|
)
|
|
|
|
type Optional struct {
|
|
Enabled TypeBool `json:"enabled"`
|
|
}
|
|
|
|
type ListConfig struct {
|
|
Optional
|
|
|
|
DownloadConcurrency TypeConcurrency `json:"downloadConcurrency"`
|
|
URLs []TypeBlocklistURI `json:"urls"`
|
|
UpdateEach TypeDuration `json:"updateEach"`
|
|
}
|
|
|
|
type Config struct {
|
|
Debug TypeBool `json:"debug"`
|
|
AllowFallbackOnUnknownDC TypeBool `json:"allowFallbackOnUnknownDc"`
|
|
Secret mtglib.Secret `json:"secret"`
|
|
BindTo TypeHostPort `json:"bindTo"`
|
|
ProxyProtocolListener TypeBool `json:"proxyProtocolListener"`
|
|
PreferIP TypePreferIP `json:"preferIp"`
|
|
DomainFrontingPort TypePort `json:"domainFrontingPort"`
|
|
DomainFrontingIP TypeIP `json:"domainFrontingIp"`
|
|
TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
|
|
Concurrency TypeConcurrency `json:"concurrency"`
|
|
Defense struct {
|
|
AntiReplay struct {
|
|
Optional
|
|
|
|
MaxSize TypeBytes `json:"maxSize"`
|
|
ErrorRate TypeErrorRate `json:"errorRate"`
|
|
} `json:"antiReplay"`
|
|
Blocklist ListConfig `json:"blocklist"`
|
|
Allowlist ListConfig `json:"allowlist"`
|
|
} `json:"defense"`
|
|
Network struct {
|
|
Timeout struct {
|
|
TCP TypeDuration `json:"tcp"`
|
|
HTTP TypeDuration `json:"http"`
|
|
Idle TypeDuration `json:"idle"`
|
|
} `json:"timeout"`
|
|
DOHIP TypeIP `json:"dohIp"`
|
|
Proxies []TypeProxyURL `json:"proxies"`
|
|
} `json:"network"`
|
|
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"`
|
|
DCOverrides []struct {
|
|
DC TypeDC `json:"dc"`
|
|
IPs []TypeHostPort `json:"ips"`
|
|
} `json:"dcOverrides"`
|
|
}
|
|
|
|
func (c *Config) Validate() error {
|
|
if !c.Secret.Valid() {
|
|
return fmt.Errorf("invalid secret %s", c.Secret.String())
|
|
}
|
|
|
|
if c.BindTo.Get("") == "" {
|
|
return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Config) String() string {
|
|
buf := &bytes.Buffer{}
|
|
encoder := json.NewEncoder(buf)
|
|
|
|
encoder.SetEscapeHTML(false)
|
|
|
|
if err := encoder.Encode(c); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return buf.String()
|
|
}
|