瀏覽代碼

Propagate DcUpdateEach setting

tags/v2.1.9^2
9seconds 2 月之前
父節點
當前提交
308e372a5d

+ 1
- 0
internal/cli/run_proxy.go 查看文件

@@ -263,6 +263,7 @@ func runProxy(conf *config.Config, version string) error { //nolint: funlen
263 263
 		AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
264 264
 		TolerateTimeSkewness:     conf.TolerateTimeSkewness.Value,
265 265
 		DCOverrides:              dcOverrides,
266
+		DCUpdateEach:             conf.DCUpdateEach.Get(0),
266 267
 	}
267 268
 
268 269
 	proxy, err := mtglib.NewProxy(opts)

+ 1
- 0
internal/cli/simple_run.go 查看文件

@@ -80,6 +80,7 @@ func (s *SimpleRun) Run(cli *CLI, version string) error { //nolint: cyclop,funle
80 80
 	conf.Debug.Value = s.Debug
81 81
 	conf.AllowFallbackOnUnknownDC.Value = true
82 82
 	conf.Defense.AntiReplay.Enabled.Value = true
83
+	conf.DCUpdateEach.Value = 0
83 84
 
84 85
 	if err := conf.Validate(); err != nil {
85 86
 		return fmt.Errorf("invalid result configuration: %w", err)

+ 3
- 2
internal/config/config.go 查看文件

@@ -65,9 +65,10 @@ type Config struct {
65 65
 		} `json:"prometheus"`
66 66
 	} `json:"stats"`
67 67
 	DCOverrides []struct {
68
-		DC  TypeDC
68
+		DC  TypeDC         `json:"dc"`
69 69
 		IPs []TypeHostPort `json:"ips"`
70
-	} `json:"dc_overrides"`
70
+	} `json:"dcOverrides"`
71
+	DCUpdateEach TypeDuration `json:"dcUpdateEach"`
71 72
 }
72 73
 
73 74
 func (c *Config) Validate() error {

+ 2
- 1
internal/config/parse.go 查看文件

@@ -62,7 +62,8 @@ type tomlConfig struct {
62 62
 	DCOverrides []struct {
63 63
 		DC  int      `toml:"dc" json:"dc"`
64 64
 		IPs []string `toml:"ips" json:"ips"`
65
-	}
65
+	} `toml:"dc-overrides" json:"dcOverrides,omitempty"`
66
+	DCUpdateEach string `toml:"dc-update-each" json:"dcUpdateEach,omitempty"`
66 67
 }
67 68
 
68 69
 func Parse(rawData []byte) (*Config, error) {

+ 4
- 0
mtglib/init.go 查看文件

@@ -99,6 +99,10 @@ const (
99 99
 	// reads from Telegram after which connection will be terminated. This is
100 100
 	// required to abort stale connections.
101 101
 	TCPRelayReadTimeout = 20 * time.Second
102
+
103
+	// DefaultDCUpdateEach defines a time period that is used to fetch
104
+	// a relevant list of DCs to use from Telegram using its own MTPROTO API.
105
+	DefaultDCUpdateEach = time.Hour
102 106
 )
103 107
 
104 108
 // Network defines a knowledge how to work with a network. It may sound fun but

+ 1
- 4
mtglib/internal/dc/init.go 查看文件

@@ -1,7 +1,5 @@
1 1
 package dc
2 2
 
3
-import "time"
4
-
5 3
 type preferIP uint8
6 4
 
7 5
 const (
@@ -12,8 +10,7 @@ const (
12 10
 )
13 11
 
14 12
 const (
15
-	DefaultDC                    = 2
16
-	DefaultUpdateDCAddressesEach = time.Hour
13
+	DefaultDC = 2
17 14
 
18 15
 	defaultAppID   = 123456
19 16
 	defaultAppHash = ""

+ 0
- 4
mtglib/internal/dc/telegram.go 查看文件

@@ -37,10 +37,6 @@ func (t *Telegram) GetAddresses(dc int) []Addr {
37 37
 }
38 38
 
39 39
 func (t *Telegram) Run(ctx context.Context, updateEach time.Duration) {
40
-	if updateEach == 0 {
41
-		updateEach = DefaultUpdateDCAddressesEach
42
-	}
43
-
44 40
 	t.update(ctx)
45 41
 
46 42
 	ticker := time.NewTicker(updateEach)

+ 6
- 1
mtglib/proxy.go 查看文件

@@ -324,7 +324,12 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
324 324
 		telegram:                 tg,
325 325
 	}
326 326
 
327
-	go tg.Run(ctx, 0) // TODO: propagate value
327
+	dcUpdateEach := opts.DCUpdateEach
328
+	if dcUpdateEach == 0 {
329
+		dcUpdateEach = DefaultDCUpdateEach
330
+	}
331
+
332
+	go tg.Run(ctx, dcUpdateEach)
328 333
 
329 334
 	pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
330 335
 		func(arg interface{}) {

+ 4
- 0
mtglib/proxy_opts.go 查看文件

@@ -119,6 +119,10 @@ type ProxyOpts struct {
119 119
 	//
120 120
 	// This is an optional setting
121 121
 	DCOverrides map[int][]string
122
+
123
+	// DCUpdateEach defines a time duration that is used to fetch a list of
124
+	// DCs to use from the Telegram.
125
+	DCUpdateEach time.Duration
122 126
 }
123 127
 
124 128
 func (p ProxyOpts) valid() error {

Loading…
取消
儲存