Przeglądaj źródła

Propagate DcUpdateEach setting

tags/v2.1.9^2
9seconds 2 miesięcy temu
rodzic
commit
308e372a5d

+ 1
- 0
internal/cli/run_proxy.go Wyświetl plik

263
 		AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
263
 		AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
264
 		TolerateTimeSkewness:     conf.TolerateTimeSkewness.Value,
264
 		TolerateTimeSkewness:     conf.TolerateTimeSkewness.Value,
265
 		DCOverrides:              dcOverrides,
265
 		DCOverrides:              dcOverrides,
266
+		DCUpdateEach:             conf.DCUpdateEach.Get(0),
266
 	}
267
 	}
267
 
268
 
268
 	proxy, err := mtglib.NewProxy(opts)
269
 	proxy, err := mtglib.NewProxy(opts)

+ 1
- 0
internal/cli/simple_run.go Wyświetl plik

80
 	conf.Debug.Value = s.Debug
80
 	conf.Debug.Value = s.Debug
81
 	conf.AllowFallbackOnUnknownDC.Value = true
81
 	conf.AllowFallbackOnUnknownDC.Value = true
82
 	conf.Defense.AntiReplay.Enabled.Value = true
82
 	conf.Defense.AntiReplay.Enabled.Value = true
83
+	conf.DCUpdateEach.Value = 0
83
 
84
 
84
 	if err := conf.Validate(); err != nil {
85
 	if err := conf.Validate(); err != nil {
85
 		return fmt.Errorf("invalid result configuration: %w", err)
86
 		return fmt.Errorf("invalid result configuration: %w", err)

+ 3
- 2
internal/config/config.go Wyświetl plik

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

+ 2
- 1
internal/config/parse.go Wyświetl plik

62
 	DCOverrides []struct {
62
 	DCOverrides []struct {
63
 		DC  int      `toml:"dc" json:"dc"`
63
 		DC  int      `toml:"dc" json:"dc"`
64
 		IPs []string `toml:"ips" json:"ips"`
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
 func Parse(rawData []byte) (*Config, error) {
69
 func Parse(rawData []byte) (*Config, error) {

+ 4
- 0
mtglib/init.go Wyświetl plik

99
 	// reads from Telegram after which connection will be terminated. This is
99
 	// reads from Telegram after which connection will be terminated. This is
100
 	// required to abort stale connections.
100
 	// required to abort stale connections.
101
 	TCPRelayReadTimeout = 20 * time.Second
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
 // Network defines a knowledge how to work with a network. It may sound fun but
108
 // Network defines a knowledge how to work with a network. It may sound fun but

+ 1
- 4
mtglib/internal/dc/init.go Wyświetl plik

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

+ 0
- 4
mtglib/internal/dc/telegram.go Wyświetl plik

37
 }
37
 }
38
 
38
 
39
 func (t *Telegram) Run(ctx context.Context, updateEach time.Duration) {
39
 func (t *Telegram) Run(ctx context.Context, updateEach time.Duration) {
40
-	if updateEach == 0 {
41
-		updateEach = DefaultUpdateDCAddressesEach
42
-	}
43
-
44
 	t.update(ctx)
40
 	t.update(ctx)
45
 
41
 
46
 	ticker := time.NewTicker(updateEach)
42
 	ticker := time.NewTicker(updateEach)

+ 6
- 1
mtglib/proxy.go Wyświetl plik

324
 		telegram:                 tg,
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
 	pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
334
 	pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
330
 		func(arg interface{}) {
335
 		func(arg interface{}) {

+ 4
- 0
mtglib/proxy_opts.go Wyświetl plik

119
 	//
119
 	//
120
 	// This is an optional setting
120
 	// This is an optional setting
121
 	DCOverrides map[int][]string
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
 func (p ProxyOpts) valid() error {
128
 func (p ProxyOpts) valid() error {

Ładowanie…
Anuluj
Zapisz