mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 00:11:56 +03:00
Propagate DcUpdateEach setting
This commit is contained in:
@@ -263,6 +263,7 @@ func runProxy(conf *config.Config, version string) error { //nolint: funlen
|
|||||||
AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
|
AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),
|
||||||
TolerateTimeSkewness: conf.TolerateTimeSkewness.Value,
|
TolerateTimeSkewness: conf.TolerateTimeSkewness.Value,
|
||||||
DCOverrides: dcOverrides,
|
DCOverrides: dcOverrides,
|
||||||
|
DCUpdateEach: conf.DCUpdateEach.Get(0),
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy, err := mtglib.NewProxy(opts)
|
proxy, err := mtglib.NewProxy(opts)
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ func (s *SimpleRun) Run(cli *CLI, version string) error { //nolint: cyclop,funle
|
|||||||
conf.Debug.Value = s.Debug
|
conf.Debug.Value = s.Debug
|
||||||
conf.AllowFallbackOnUnknownDC.Value = true
|
conf.AllowFallbackOnUnknownDC.Value = true
|
||||||
conf.Defense.AntiReplay.Enabled.Value = true
|
conf.Defense.AntiReplay.Enabled.Value = true
|
||||||
|
conf.DCUpdateEach.Value = 0
|
||||||
|
|
||||||
if err := conf.Validate(); err != nil {
|
if err := conf.Validate(); err != nil {
|
||||||
return fmt.Errorf("invalid result configuration: %w", err)
|
return fmt.Errorf("invalid result configuration: %w", err)
|
||||||
|
|||||||
@@ -65,9 +65,10 @@ type Config struct {
|
|||||||
} `json:"prometheus"`
|
} `json:"prometheus"`
|
||||||
} `json:"stats"`
|
} `json:"stats"`
|
||||||
DCOverrides []struct {
|
DCOverrides []struct {
|
||||||
DC TypeDC
|
DC TypeDC `json:"dc"`
|
||||||
IPs []TypeHostPort `json:"ips"`
|
IPs []TypeHostPort `json:"ips"`
|
||||||
} `json:"dc_overrides"`
|
} `json:"dcOverrides"`
|
||||||
|
DCUpdateEach TypeDuration `json:"dcUpdateEach"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Validate() error {
|
func (c *Config) Validate() error {
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ type tomlConfig struct {
|
|||||||
DCOverrides []struct {
|
DCOverrides []struct {
|
||||||
DC int `toml:"dc" json:"dc"`
|
DC int `toml:"dc" json:"dc"`
|
||||||
IPs []string `toml:"ips" json:"ips"`
|
IPs []string `toml:"ips" json:"ips"`
|
||||||
}
|
} `toml:"dc-overrides" json:"dcOverrides,omitempty"`
|
||||||
|
DCUpdateEach string `toml:"dc-update-each" json:"dcUpdateEach,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parse(rawData []byte) (*Config, error) {
|
func Parse(rawData []byte) (*Config, error) {
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ const (
|
|||||||
// reads from Telegram after which connection will be terminated. This is
|
// reads from Telegram after which connection will be terminated. This is
|
||||||
// required to abort stale connections.
|
// required to abort stale connections.
|
||||||
TCPRelayReadTimeout = 20 * time.Second
|
TCPRelayReadTimeout = 20 * time.Second
|
||||||
|
|
||||||
|
// DefaultDCUpdateEach defines a time period that is used to fetch
|
||||||
|
// a relevant list of DCs to use from Telegram using its own MTPROTO API.
|
||||||
|
DefaultDCUpdateEach = time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
// Network defines a knowledge how to work with a network. It may sound fun but
|
// Network defines a knowledge how to work with a network. It may sound fun but
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package dc
|
package dc
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type preferIP uint8
|
type preferIP uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -12,8 +10,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultDC = 2
|
DefaultDC = 2
|
||||||
DefaultUpdateDCAddressesEach = time.Hour
|
|
||||||
|
|
||||||
defaultAppID = 123456
|
defaultAppID = 123456
|
||||||
defaultAppHash = ""
|
defaultAppHash = ""
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ func (t *Telegram) GetAddresses(dc int) []Addr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Telegram) Run(ctx context.Context, updateEach time.Duration) {
|
func (t *Telegram) Run(ctx context.Context, updateEach time.Duration) {
|
||||||
if updateEach == 0 {
|
|
||||||
updateEach = DefaultUpdateDCAddressesEach
|
|
||||||
}
|
|
||||||
|
|
||||||
t.update(ctx)
|
t.update(ctx)
|
||||||
|
|
||||||
ticker := time.NewTicker(updateEach)
|
ticker := time.NewTicker(updateEach)
|
||||||
|
|||||||
+6
-1
@@ -324,7 +324,12 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
|||||||
telegram: tg,
|
telegram: tg,
|
||||||
}
|
}
|
||||||
|
|
||||||
go tg.Run(ctx, 0) // TODO: propagate value
|
dcUpdateEach := opts.DCUpdateEach
|
||||||
|
if dcUpdateEach == 0 {
|
||||||
|
dcUpdateEach = DefaultDCUpdateEach
|
||||||
|
}
|
||||||
|
|
||||||
|
go tg.Run(ctx, dcUpdateEach)
|
||||||
|
|
||||||
pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
|
pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
|
||||||
func(arg interface{}) {
|
func(arg interface{}) {
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ type ProxyOpts struct {
|
|||||||
//
|
//
|
||||||
// This is an optional setting
|
// This is an optional setting
|
||||||
DCOverrides map[int][]string
|
DCOverrides map[int][]string
|
||||||
|
|
||||||
|
// DCUpdateEach defines a time duration that is used to fetch a list of
|
||||||
|
// DCs to use from the Telegram.
|
||||||
|
DCUpdateEach time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p ProxyOpts) valid() error {
|
func (p ProxyOpts) valid() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user