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
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ProxyProtocolListener TypeBool `json:"proxyProtocolListener"`
  23. PreferIP TypePreferIP `json:"preferIp"`
  24. DomainFrontingPort TypePort `json:"domainFrontingPort"`
  25. DomainFrontingIP TypeIP `json:"domainFrontingIp"`
  26. TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
  27. Concurrency TypeConcurrency `json:"concurrency"`
  28. Defense struct {
  29. AntiReplay struct {
  30. Optional
  31. MaxSize TypeBytes `json:"maxSize"`
  32. ErrorRate TypeErrorRate `json:"errorRate"`
  33. } `json:"antiReplay"`
  34. Blocklist ListConfig `json:"blocklist"`
  35. Allowlist ListConfig `json:"allowlist"`
  36. } `json:"defense"`
  37. Network struct {
  38. Timeout struct {
  39. TCP TypeDuration `json:"tcp"`
  40. HTTP TypeDuration `json:"http"`
  41. Idle TypeDuration `json:"idle"`
  42. } `json:"timeout"`
  43. DOHIP TypeIP `json:"dohIp"`
  44. Proxies []TypeProxyURL `json:"proxies"`
  45. } `json:"network"`
  46. Stats struct {
  47. StatsD struct {
  48. Optional
  49. Address TypeHostPort `json:"address"`
  50. MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
  51. TagFormat TypeStatsdTagFormat `json:"tagFormat"`
  52. } `json:"statsd"`
  53. Prometheus struct {
  54. Optional
  55. BindTo TypeHostPort `json:"bindTo"`
  56. HTTPPath TypeHTTPPath `json:"httpPath"`
  57. MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
  58. } `json:"prometheus"`
  59. } `json:"stats"`
  60. }
  61. func (c *Config) Validate() error {
  62. if !c.Secret.Valid() {
  63. return fmt.Errorf("invalid secret %s", c.Secret.String())
  64. }
  65. if c.BindTo.Get("") == "" {
  66. return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
  67. }
  68. return nil
  69. }
  70. func (c *Config) String() string {
  71. buf := &bytes.Buffer{}
  72. encoder := json.NewEncoder(buf)
  73. encoder.SetEscapeHTML(false)
  74. if err := encoder.Encode(c); err != nil {
  75. panic(err)
  76. }
  77. return buf.String()
  78. }