Kaynağa Gözat

Address round-two review: rename mtglib privates, reorder, more tests

- mtglib/proxy.go: rename private field domainFrontingIP -> domainFrontingHost
  and update DomainFrontingAddress() doc comment to reflect that hostnames
  are now accepted. The exported mtglib.ProxyOpts.DomainFrontingIP is
  unchanged (public API), so the assignment in NewProxy now reads
  `domainFrontingHost: opts.DomainFrontingIP,` which makes the
  public-vs-internal naming explicitly visible at the boundary.
- internal/config/{parse,config}.go: reorder so Host comes before IP in
  the [domain-fronting] struct. Cosmetic, but signals Host is the
  preferred forward path.
- Add TestDomainFrontingHostAcceptsLiteralIP + domain_fronting_host_ip.toml
  fixture exercising the documented "host accepts hostname or literal IP"
  contract end-to-end.
pull/480/head
Alexey Dolotov 1 hafta önce
ebeveyn
işleme
908b32afff

+ 1
- 1
internal/config/config.go Dosyayı Görüntüle

@@ -37,8 +37,8 @@ type Config struct {
37 37
 	PublicIPv4                  TypeIP          `json:"publicIpv4"`
38 38
 	PublicIPv6                  TypeIP          `json:"publicIpv6"`
39 39
 	DomainFronting              struct {
40
-		IP            TypeIP   `json:"ip"`
41 40
 		Host          TypeHost `json:"host"`
41
+		IP            TypeIP   `json:"ip"`
42 42
 		Port          TypePort `json:"port"`
43 43
 		ProxyProtocol TypeBool `json:"proxyProtocol"`
44 44
 	} `json:"domainFronting"`

+ 7
- 0
internal/config/config_test.go Dosyayı Görüntüle

@@ -90,6 +90,13 @@ func (suite *ConfigTestSuite) TestDomainFrontingHostFromTOML() {
90 90
 	suite.Equal("fronting-backend", conf.GetDomainFrontingHost())
91 91
 }
92 92
 
93
+func (suite *ConfigTestSuite) TestDomainFrontingHostAcceptsLiteralIP() {
94
+	conf, err := config.Parse(suite.ReadConfig("domain_fronting_host_ip.toml"))
95
+	suite.NoError(err)
96
+	suite.NoError(conf.Validate())
97
+	suite.Equal("10.0.0.1", conf.GetDomainFrontingHost())
98
+}
99
+
93 100
 func (suite *ConfigTestSuite) TestDomainFrontingIPFromTOML() {
94 101
 	conf, err := config.Parse(suite.ReadConfig("domain_fronting_ip.toml"))
95 102
 	suite.NoError(err)

+ 1
- 1
internal/config/parse.go Dosyayı Görüntüle

@@ -24,8 +24,8 @@ type tomlConfig struct {
24 24
 	PublicIPv4                  string `toml:"public-ipv4" json:"publicIpv4,omitempty"`
25 25
 	PublicIPv6                  string `toml:"public-ipv6" json:"publicIpv6,omitempty"`
26 26
 	DomainFronting              struct {
27
-		IP            string `toml:"ip" json:"ip,omitempty"`
28 27
 		Host          string `toml:"host" json:"host,omitempty"`
28
+		IP            string `toml:"ip" json:"ip,omitempty"`
29 29
 		Port          uint   `toml:"port" json:"port,omitempty"`
30 30
 		ProxyProtocol bool   `toml:"proxy-protocol" json:"proxyProtocol,omitempty"`
31 31
 	} `toml:"domain-fronting" json:"domainFronting,omitempty"`

+ 5
- 0
internal/config/testdata/domain_fronting_host_ip.toml Dosyayı Görüntüle

@@ -0,0 +1,5 @@
1
+secret = "7oe1GqLy6TBc38CV3jx7q09nb29nbGUuY29t"
2
+bind-to = "0.0.0.0:3128"
3
+
4
+[domain-fronting]
5
+host = "10.0.0.1"

+ 6
- 5
mtglib/proxy.go Dosyayı Görüntüle

@@ -30,7 +30,7 @@ type Proxy struct {
30 30
 	idleTimeout                 time.Duration
31 31
 	handshakeTimeout            time.Duration
32 32
 	domainFrontingPort          int
33
-	domainFrontingIP            string
33
+	domainFrontingHost          string
34 34
 	domainFrontingProxyProtocol bool
35 35
 	workerPool                  *ants.PoolWithFunc
36 36
 	telegram                    *dc.Telegram
@@ -48,11 +48,12 @@ type Proxy struct {
48 48
 }
49 49
 
50 50
 // DomainFrontingAddress returns a host:port pair for a fronting domain.
51
-// If DomainFrontingIP is set, it is used instead of resolving the hostname.
51
+// If a fronting host (literal IP or hostname) is configured, it is used
52
+// instead of resolving the secret's hostname.
52 53
 func (p *Proxy) DomainFrontingAddress() string {
53 54
 	host := p.secret.Host
54
-	if p.domainFrontingIP != "" {
55
-		host = p.domainFrontingIP
55
+	if p.domainFrontingHost != "" {
56
+		host = p.domainFrontingHost
56 57
 	}
57 58
 
58 59
 	return net.JoinHostPort(host, strconv.Itoa(p.domainFrontingPort))
@@ -354,7 +355,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
354 355
 		eventStream:              opts.EventStream,
355 356
 		logger:                   logger,
356 357
 		domainFrontingPort:       opts.getDomainFrontingPort(),
357
-		domainFrontingIP:         opts.DomainFrontingIP,
358
+		domainFrontingHost:       opts.DomainFrontingIP,
358 359
 		tolerateTimeSkewness:     opts.getTolerateTimeSkewness(),
359 360
 		idleTimeout:              opts.getIdleTimeout(),
360 361
 		handshakeTimeout:         opts.getHandshakeTimeout(),

Loading…
İptal
Kaydet