mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:04:02 +03:00
Merge pull request #339 from 9seconds/domain-fronting-config-grouping
Domain fronting config grouping
This commit is contained in:
+33
-10
@@ -36,13 +36,6 @@ bind-to = "0.0.0.0:3128"
|
|||||||
# All other incoming connections are going to be dropped.
|
# All other incoming connections are going to be dropped.
|
||||||
concurrency = 8192
|
concurrency = 8192
|
||||||
|
|
||||||
# A size of user-space buffer for TCP to use. Since we do 2 connections,
|
|
||||||
# then we have tcp-buffer * (4 + 2) per each connection: read/write for
|
|
||||||
# each connection + 2 copy buffers to pump the data between sockets.
|
|
||||||
#
|
|
||||||
# Deprecated: this setting is no longer makes any effect.
|
|
||||||
# tcp-buffer = "4kb"
|
|
||||||
|
|
||||||
# Sometimes you want to enforce mtg to use some types of
|
# Sometimes you want to enforce mtg to use some types of
|
||||||
# IP connectivity to Telegram. We have 4 modes:
|
# IP connectivity to Telegram. We have 4 modes:
|
||||||
# - prefer-ipv6:
|
# - prefer-ipv6:
|
||||||
@@ -57,7 +50,10 @@ prefer-ip = "prefer-ipv6"
|
|||||||
|
|
||||||
# FakeTLS uses domain fronting protection. So it needs to know a port to
|
# FakeTLS uses domain fronting protection. So it needs to know a port to
|
||||||
# access.
|
# access.
|
||||||
domain-fronting-port = 443
|
#
|
||||||
|
# Deprecated: use [domain-fronting] configuration block. If relevant option
|
||||||
|
# is defined there, this one would be ignored.
|
||||||
|
# domain-fronting-port = 443
|
||||||
|
|
||||||
# By default, mtg resolves the fronting hostname (from the secret) via DNS
|
# By default, mtg resolves the fronting hostname (from the secret) via DNS
|
||||||
# to establish a TCP connection. If DNS resolution of that hostname is blocked,
|
# to establish a TCP connection. If DNS resolution of that hostname is blocked,
|
||||||
@@ -65,11 +61,17 @@ domain-fronting-port = 443
|
|||||||
# used for SNI in the TLS handshake.
|
# used for SNI in the TLS handshake.
|
||||||
#
|
#
|
||||||
# default value is not set (DNS resolution is used).
|
# default value is not set (DNS resolution is used).
|
||||||
# domain-fronting-ip = "142.250.185.112"
|
#
|
||||||
|
# Deprecated: use [domain-fronting] configuration block. If relevant option
|
||||||
|
# is defined there, this one would be ignored.
|
||||||
|
# domain-fronting-ip = "10.0.0.10"
|
||||||
|
|
||||||
# This makes a communication between both fronting website and mtg to use
|
# This makes a communication between both fronting website and mtg to use
|
||||||
# proxy protocol.
|
# proxy protocol.
|
||||||
domain-fronting-proxy-protocol = false
|
#
|
||||||
|
# Deprecated: use [domain-fronting] configuration block. If relevant option
|
||||||
|
# is defined there, this one would be ignored.
|
||||||
|
# domain-fronting-proxy-protocol = false
|
||||||
|
|
||||||
# FakeTLS can compare timestamps to prevent probes. Each message has
|
# FakeTLS can compare timestamps to prevent probes. Each message has
|
||||||
# encrypted timestamp. So, mtg can compare this timestamp and decide if
|
# encrypted timestamp. So, mtg can compare this timestamp and decide if
|
||||||
@@ -92,6 +94,27 @@ tolerate-time-skewness = "5s"
|
|||||||
# Otherwise, chose a new DC.
|
# Otherwise, chose a new DC.
|
||||||
allow-fallback-on-unknown-dc = false
|
allow-fallback-on-unknown-dc = false
|
||||||
|
|
||||||
|
# This section is relevant to communication with fronting domain. Usually
|
||||||
|
# you do not need to setup anything here but there are plenty of cases, especially
|
||||||
|
# if you put mtg behind load balancer, when some specific configuration is
|
||||||
|
# required.
|
||||||
|
[domain-fronting]
|
||||||
|
# By default, mtg resolves the fronting hostname (from the secret) via DNS
|
||||||
|
# to establish a TCP connection. If DNS resolution of that hostname is blocked,
|
||||||
|
# you can specify an IP address to connect to directly. The hostname is still
|
||||||
|
# used for SNI in the TLS handshake.
|
||||||
|
#
|
||||||
|
# default value is not set (DNS resolution is used).
|
||||||
|
# ip = "10.10.10.11"
|
||||||
|
|
||||||
|
# FakeTLS uses domain fronting protection. So it needs to know a port to
|
||||||
|
# access. Default value is 443
|
||||||
|
# port = 443
|
||||||
|
|
||||||
|
# This makes a communication between both fronting website and mtg to use
|
||||||
|
# proxy protocol.
|
||||||
|
# proxy-protocol = false
|
||||||
|
|
||||||
# network defines different network-related settings
|
# network defines different network-related settings
|
||||||
[network]
|
[network]
|
||||||
# please be aware that mtg needs to do some external requests. For
|
# please be aware that mtg needs to do some external requests. For
|
||||||
|
|||||||
@@ -251,9 +251,9 @@ func runProxy(conf *config.Config, version string) error { //nolint: funlen
|
|||||||
EventStream: eventStream,
|
EventStream: eventStream,
|
||||||
|
|
||||||
Secret: conf.Secret,
|
Secret: conf.Secret,
|
||||||
DomainFrontingPort: conf.DomainFrontingPort.Get(mtglib.DefaultDomainFrontingPort),
|
DomainFrontingPort: conf.GetDomainFrontingPort(mtglib.DefaultDomainFrontingPort),
|
||||||
DomainFrontingIP: conf.DomainFrontingIP.String(),
|
DomainFrontingIP: conf.GetDomainFrontingIP(nil),
|
||||||
DomainFrontingProxyProtocol: conf.DomainFrontingProxyProtocol.Get(false),
|
DomainFrontingProxyProtocol: conf.GetDomainFrontingProxyProtocol(false),
|
||||||
PreferIP: conf.PreferIP.Get(mtglib.DefaultPreferIP),
|
PreferIP: conf.PreferIP.Get(mtglib.DefaultPreferIP),
|
||||||
|
|
||||||
AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
|
AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/mtglib"
|
"github.com/9seconds/mtg/v2/mtglib"
|
||||||
)
|
)
|
||||||
@@ -32,7 +33,12 @@ type Config struct {
|
|||||||
DomainFrontingProxyProtocol TypeBool `json:"domainFrontingProxyProtocol"`
|
DomainFrontingProxyProtocol TypeBool `json:"domainFrontingProxyProtocol"`
|
||||||
TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
|
TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
|
||||||
Concurrency TypeConcurrency `json:"concurrency"`
|
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 {
|
AntiReplay struct {
|
||||||
Optional
|
Optional
|
||||||
|
|
||||||
@@ -69,6 +75,27 @@ type Config struct {
|
|||||||
} `json:"stats"`
|
} `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 {
|
func (c *Config) Validate() error {
|
||||||
if !c.Secret.Valid() {
|
if !c.Secret.Valid() {
|
||||||
return fmt.Errorf("invalid secret %s", c.Secret.String())
|
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"`
|
DomainFrontingProxyProtocol bool `toml:"domain-fronting-proxy-protocol" json:"domainFrontingProxyProtocol,omitempty"`
|
||||||
TolerateTimeSkewness string `toml:"tolerate-time-skewness" json:"tolerateTimeSkewness,omitempty"`
|
TolerateTimeSkewness string `toml:"tolerate-time-skewness" json:"tolerateTimeSkewness,omitempty"`
|
||||||
Concurrency uint `toml:"concurrency" json:"concurrency,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 {
|
AntiReplay struct {
|
||||||
Enabled bool `toml:"enabled" json:"enabled,omitempty"`
|
Enabled bool `toml:"enabled" json:"enabled,omitempty"`
|
||||||
MaxSize string `toml:"max-size" json:"maxSize,omitempty"`
|
MaxSize string `toml:"max-size" json:"maxSize,omitempty"`
|
||||||
|
|||||||
+15
-15
@@ -31,8 +31,8 @@ type Proxy struct {
|
|||||||
domainFrontingProxyProtocol bool
|
domainFrontingProxyProtocol bool
|
||||||
workerPool *ants.PoolWithFunc
|
workerPool *ants.PoolWithFunc
|
||||||
telegram *dc.Telegram
|
telegram *dc.Telegram
|
||||||
configUpdater *dc.PublicConfigUpdater
|
configUpdater *dc.PublicConfigUpdater
|
||||||
clientObfuscatror obfuscation.Obfuscator
|
clientObfuscatror obfuscation.Obfuscator
|
||||||
|
|
||||||
secret Secret
|
secret Secret
|
||||||
network Network
|
network Network
|
||||||
@@ -321,20 +321,20 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
|||||||
updatersLogger := logger.Named("telegram-updaters")
|
updatersLogger := logger.Named("telegram-updaters")
|
||||||
|
|
||||||
proxy := &Proxy{
|
proxy := &Proxy{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
ctxCancel: cancel,
|
ctxCancel: cancel,
|
||||||
secret: opts.Secret,
|
secret: opts.Secret,
|
||||||
network: opts.Network,
|
network: opts.Network,
|
||||||
antiReplayCache: opts.AntiReplayCache,
|
antiReplayCache: opts.AntiReplayCache,
|
||||||
blocklist: opts.IPBlocklist,
|
blocklist: opts.IPBlocklist,
|
||||||
allowlist: opts.IPAllowlist,
|
allowlist: opts.IPAllowlist,
|
||||||
eventStream: opts.EventStream,
|
eventStream: opts.EventStream,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
domainFrontingPort: opts.getDomainFrontingPort(),
|
domainFrontingPort: opts.getDomainFrontingPort(),
|
||||||
domainFrontingIP: opts.DomainFrontingIP,
|
domainFrontingIP: opts.DomainFrontingIP,
|
||||||
tolerateTimeSkewness: opts.getTolerateTimeSkewness(),
|
tolerateTimeSkewness: opts.getTolerateTimeSkewness(),
|
||||||
allowFallbackOnUnknownDC: opts.AllowFallbackOnUnknownDC,
|
allowFallbackOnUnknownDC: opts.AllowFallbackOnUnknownDC,
|
||||||
telegram: tg,
|
telegram: tg,
|
||||||
configUpdater: dc.NewPublicConfigUpdater(
|
configUpdater: dc.NewPublicConfigUpdater(
|
||||||
tg,
|
tg,
|
||||||
updatersLogger.Named("public-config"),
|
updatersLogger.Named("public-config"),
|
||||||
|
|||||||
Reference in New Issue
Block a user