mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 11:54:01 +03:00
Introduce [domain-fronting] config
This commit is contained in:
@@ -251,9 +251,9 @@ func runProxy(conf *config.Config, version string) error { //nolint: funlen
|
||||
EventStream: eventStream,
|
||||
|
||||
Secret: conf.Secret,
|
||||
DomainFrontingPort: conf.DomainFrontingPort.Get(mtglib.DefaultDomainFrontingPort),
|
||||
DomainFrontingIP: conf.DomainFrontingIP.String(),
|
||||
DomainFrontingProxyProtocol: conf.DomainFrontingProxyProtocol.Get(false),
|
||||
DomainFrontingPort: conf.GetDomainFrontingPort(mtglib.DefaultDomainFrontingPort),
|
||||
DomainFrontingIP: conf.GetDomainFrontingIP(nil),
|
||||
DomainFrontingProxyProtocol: conf.GetDomainFrontingProxyProtocol(false),
|
||||
PreferIP: conf.PreferIP.Get(mtglib.DefaultPreferIP),
|
||||
|
||||
AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/9seconds/mtg/v2/mtglib"
|
||||
)
|
||||
@@ -32,7 +33,12 @@ type Config struct {
|
||||
DomainFrontingProxyProtocol TypeBool `json:"domainFrontingProxyProtocol"`
|
||||
TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
|
||||
Concurrency TypeConcurrency `json:"concurrency"`
|
||||
Defense struct {
|
||||
DomainFronting struct {
|
||||
IP TypeIP `json:"ip"`
|
||||
Port TypePort `json:"port"`
|
||||
ProxyProtocol TypeBool `json:"proxyProtocol"`
|
||||
} `json:"domainFronting"`
|
||||
Defense struct {
|
||||
AntiReplay struct {
|
||||
Optional
|
||||
|
||||
@@ -69,6 +75,27 @@ type Config struct {
|
||||
} `json:"stats"`
|
||||
}
|
||||
|
||||
func (c *Config) GetDomainFrontingPort(defaultValue uint) uint {
|
||||
if port := c.DomainFronting.Port.Get(0); port != 0 {
|
||||
return port
|
||||
}
|
||||
return c.DomainFrontingPort.Get(defaultValue)
|
||||
}
|
||||
|
||||
func (c *Config) GetDomainFrontingIP(defaultValue net.IP) string {
|
||||
if ip := c.DomainFronting.IP.Get(nil); ip != nil {
|
||||
return ip.String()
|
||||
}
|
||||
if ip := c.DomainFrontingIP.Get(defaultValue); ip != nil {
|
||||
return ip.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *Config) GetDomainFrontingProxyProtocol(defaultValue bool) bool {
|
||||
return c.DomainFronting.ProxyProtocol.Get(false) || c.DomainFrontingProxyProtocol.Get(defaultValue)
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if !c.Secret.Valid() {
|
||||
return fmt.Errorf("invalid secret %s", c.Secret.String())
|
||||
|
||||
@@ -20,7 +20,12 @@ type tomlConfig struct {
|
||||
DomainFrontingProxyProtocol bool `toml:"domain-fronting-proxy-protocol" json:"domainFrontingProxyProtocol,omitempty"`
|
||||
TolerateTimeSkewness string `toml:"tolerate-time-skewness" json:"tolerateTimeSkewness,omitempty"`
|
||||
Concurrency uint `toml:"concurrency" json:"concurrency,omitempty"`
|
||||
Defense struct {
|
||||
DomainFronting struct {
|
||||
IP string `toml:"ip" json:"ip,omitempty"`
|
||||
Port uint `toml:"port" json:"port,omitempty"`
|
||||
ProxyProtocol bool `toml:"proxy-protocol" json:"proxyProtocol,omitempty"`
|
||||
} `toml:"domain-fronting" json:"domainFronting,omitempty"`
|
||||
Defense struct {
|
||||
AntiReplay struct {
|
||||
Enabled bool `toml:"enabled" json:"enabled,omitempty"`
|
||||
MaxSize string `toml:"max-size" json:"maxSize,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user