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文字以内のものにしてください。

config.go 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. 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. DCOverrides []struct {
  60. DC TypeDC `json:"dc"`
  61. IPs []TypeHostPort `json:"ips"`
  62. } `json:"dcOverrides"`
  63. }
  64. func (c *Config) Validate() error {
  65. if !c.Secret.Valid() {
  66. return fmt.Errorf("invalid secret %s", c.Secret.String())
  67. }
  68. if c.BindTo.Get("") == "" {
  69. return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
  70. }
  71. return nil
  72. }
  73. func (c *Config) String() string {
  74. buf := &bytes.Buffer{}
  75. encoder := json.NewEncoder(buf)
  76. encoder.SetEscapeHTML(false)
  77. if err := encoder.Encode(c); err != nil {
  78. panic(err)
  79. }
  80. return buf.String()
  81. }