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. PreferIP TypePreferIP `json:"preferIp"`
  23. DomainFrontingPort TypePort `json:"domainFrontingPort"`
  24. TolerateTimeSkewness TypeDuration `json:"tolerateTimeSkewness"`
  25. Concurrency TypeConcurrency `json:"concurrency"`
  26. Defense struct {
  27. AntiReplay struct {
  28. Optional
  29. MaxSize TypeBytes `json:"maxSize"`
  30. ErrorRate TypeErrorRate `json:"errorRate"`
  31. } `json:"antiReplay"`
  32. Blocklist ListConfig `json:"blocklist"`
  33. Allowlist ListConfig `json:"allowlist"`
  34. } `json:"defense"`
  35. Network struct {
  36. Timeout struct {
  37. TCP TypeDuration `json:"tcp"`
  38. HTTP TypeDuration `json:"http"`
  39. Idle TypeDuration `json:"idle"`
  40. } `json:"timeout"`
  41. DOHIP TypeIP `json:"dohIp"`
  42. Proxies []TypeProxyURL `json:"proxies"`
  43. } `json:"network"`
  44. Stats struct {
  45. StatsD struct {
  46. Optional
  47. Address TypeHostPort `json:"address"`
  48. MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
  49. TagFormat TypeStatsdTagFormat `json:"tagFormat"`
  50. } `json:"statsd"`
  51. Prometheus struct {
  52. Optional
  53. BindTo TypeHostPort `json:"bindTo"`
  54. HTTPPath TypeHTTPPath `json:"httpPath"`
  55. MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
  56. } `json:"prometheus"`
  57. } `json:"stats"`
  58. DCOverrides []struct {
  59. DC TypeDC `json:"dc"`
  60. IPs []TypeHostPort `json:"ips"`
  61. } `json:"dcOverrides"`
  62. DCUpdateEach TypeDuration `json:"dcUpdateEach"`
  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. }