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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

config.go 2.4KB

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