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 символів.

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