Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

config.go 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package config
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/9seconds/mtg/v2/mtglib"
  7. )
  8. type Optional struct {
  9. Enabled TypeBool `json:"enabled"`
  10. }
  11. type ListConfig struct {
  12. Optional
  13. DownloadConcurrency TypeConcurrency `json:"downloadConcurrency"`
  14. URLs []TypeBlocklistURI `json:"urls"`
  15. UpdateEach TypeDuration `json:"updateEach"`
  16. }
  17. type Config struct {
  18. Debug TypeBool `json:"debug"`
  19. AllowFallbackOnUnknownDC TypeBool `json:"allowFallbackOnUnknownDc"`
  20. Secret mtglib.Secret `json:"secret"`
  21. BindTo TypeHostPort `json:"bindTo"`
  22. TCPBuffer TypeBytes `json:"tcpBuffer"`
  23. PreferIP TypePreferIP `json:"preferIp"`
  24. DomainFrontingPort TypePort `json:"domainFrontingPort"`
  25. TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
  26. Concurrency TypeConcurrency `json:"concurrency"`
  27. Defense struct {
  28. AntiReplay struct {
  29. Optional
  30. MaxSize TypeBytes `json:"maxSize"`
  31. ErrorRate TypeErrorRate `json:"errorRate"`
  32. } `json:"antiReplay"`
  33. Blocklist ListConfig `json:"blocklist"`
  34. Allowlist ListConfig `json:"allowlist"`
  35. } `json:"defense"`
  36. Network struct {
  37. Timeout struct {
  38. TCP TypeDuration `json:"tcp"`
  39. HTTP TypeDuration `json:"http"`
  40. Idle TypeDuration `json:"idle"`
  41. } `json:"timeout"`
  42. DOHIP TypeIP `json:"dohIp"`
  43. Proxies []TypeProxyURL `json:"proxies"`
  44. } `json:"network"`
  45. Stats struct {
  46. StatsD struct {
  47. Optional
  48. Address TypeHostPort `json:"address"`
  49. MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
  50. TagFormat TypeStatsdTagFormat `json:"tagFormat"`
  51. } `json:"statsd"`
  52. Prometheus struct {
  53. Optional
  54. BindTo TypeHostPort `json:"bindTo"`
  55. HTTPPath TypeHTTPPath `json:"httpPath"`
  56. MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
  57. } `json:"prometheus"`
  58. } `json:"stats"`
  59. }
  60. func (c *Config) Validate() error {
  61. if !c.Secret.Valid() {
  62. return fmt.Errorf("invalid secret %s", c.Secret.String())
  63. }
  64. if c.BindTo.Get("") == "" {
  65. return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
  66. }
  67. return nil
  68. }
  69. func (c *Config) String() string {
  70. buf := &bytes.Buffer{}
  71. encoder := json.NewEncoder(buf)
  72. encoder.SetEscapeHTML(false)
  73. if err := encoder.Encode(c); err != nil {
  74. panic(err)
  75. }
  76. return buf.String()
  77. }