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.3KB

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